00001 #ifndef Impala_Core_VideoSet_ImportAudioConcepts_h
00002 #define Impala_Core_VideoSet_ImportAudioConcepts_h
00003
00004 #include "Util/DatabaseReadString.h"
00005 #include "Core/Table/SimilarityTableSet.h"
00006 #include "Core/Table/QuidTable.h"
00007 #include "Core/VideoSet/Reporter.h"
00008 #include "Core/VideoSet/Segmentation.h"
00009 #include "Core/VideoSet/Keyframes.h"
00010 #include "Core/VideoSet/Mpeg7DocAudio.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace VideoSet
00017 {
00018
00019
00020 class ImportAudioConcepts : public Listener
00021 {
00022 public:
00023 typedef Table::SimilarityTableSet SimilarityTableSet;
00024 typedef Table::SimilarityTableSet::SimTableType SimTableType;
00025
00026 ImportAudioConcepts(Reporter* reporter, CmdOptions& options)
00027 {
00028 mReporter = reporter;
00029 if (options.GetNrArg() < 5)
00030 {
00031 ILOG_ERROR("Missing argument");
00032 return;
00033 }
00034 mConceptSet = options.GetArg(2);
00035 mModel = options.GetArg(3);
00036 mFeature = options.GetArg(4);
00037 mSegmentation = 0;
00038 mKeyframes = 0;
00039 mSimSet = 0;
00040 }
00041
00042 virtual void
00043 HandleNewWalk(VideoSet* vs, Keyframes* keyframes, bool* keyframeMask)
00044 {
00045 mKeyframes = keyframes;
00046 }
00047
00048 virtual void
00049 HandleNewWalk(VideoSet* vs, Segmentation* segmentation)
00050 {
00051 mSegmentation = segmentation;
00052 }
00053
00054 virtual void
00055 HandleNewWalk(VideoSet* vs)
00056 {
00057 String fName = vs->GetFilePathAnnotation(mConceptSet, false, false);
00058 if (fName.empty())
00059 {
00060 ILOG_ERROR("Unable to read conceptSet");
00061 return;
00062 }
00063 std::vector<String> names;
00064 Util::DatabaseReadString(std::back_inserter(names), fName,
00065 vs->GetDatabase(), true);
00066 mSimSet = new SimilarityTableSet(names, 100);
00067 }
00068
00069 virtual void
00070 HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00071 {
00072 String vidName = vs->GetFile(fileId);
00073 for (int c=0 ; c<mSimSet->NrTables() ; c++)
00074 {
00075 int startKey = mKeyframes->GetFirstKeyframeVideo(fileId);
00076 int nrKeys = mKeyframes->GetNrKeyframesVideo(fileId);
00077 if (c == 0)
00078 {
00079 Table::QuidTable* qTable = mSimSet->GetQuidTable();
00080 for (int k=0 ; k<nrKeys ; k++)
00081 {
00082 int frameNr = mKeyframes->GetFrameNr(startKey + k);
00083 Quid quid = vs->GetQuidFrame(fileId, frameNr);
00084 qTable->Add(quid);
00085 }
00086 }
00087 String concept = mSimSet->GetName(c);
00088 SimTableType* table = mSimSet->GetSimTable(c);
00089 String fName = vs->GetFilePathMpeg7Concept(fileId, mConceptSet,
00090 concept + ".xml",
00091 false, true);
00092 for (int k=0 ; k<nrKeys ; k++)
00093 table->Add(0.0);
00094 if (! fName.empty())
00095 {
00096 ILOG_INFO("Reading " << fName);
00097 Mpeg7DocAudio mp7(fName, vs->GetDatabase());
00098 for (int s=0 ; s<mp7.NrSegments() ; s++)
00099 {
00100 double sim = mp7.Confidence(s);
00101 int startFrame = mp7.StartFrameReFraction(s, 25);
00102 int endFrame = mp7.EndFrameReFraction(s, 25);
00103 std::vector<int> shotList;
00104 shotList = mSegmentation->GetShotIds(fileId, startFrame,
00105 endFrame, 12);
00106 for (int i=0 ; i<shotList.size() ; i++)
00107 {
00108 int shot = shotList[i];
00109 int sKey = mKeyframes->GetFirstKeyframeShot(shot);
00110 int nKey = mKeyframes->GetNrKeyframesShot(shot);
00111 for (int k=sKey ; k<sKey+nKey ; k++)
00112 table->Set1(k, sim);
00113 }
00114 }
00115 }
00116 }
00117 }
00118
00119 virtual void
00120 HandleDoneWalk(VideoSet* vs)
00121 {
00122 mSimSet->ComputeRanks(true);
00123 mSimSet->Save(vs, mConceptSet, mModel, mFeature, true);
00124 delete mSimSet;
00125 }
00126
00127 private:
00128
00129 Reporter* mReporter;
00130 String mConceptSet;
00131 String mModel;
00132 String mFeature;
00133 Segmentation* mSegmentation;
00134 Keyframes* mKeyframes;
00135 SimilarityTableSet* mSimSet;
00136
00137 ILOG_VAR_DEC;
00138
00139 };
00140
00141 ILOG_VAR_INIT(ImportAudioConcepts, Impala.Core.VideoSet);
00142
00143 }
00144 }
00145 }
00146
00147 #endif