00001 #ifndef Impala_Core_VideoSet_ImportAudioConcepts_h
00002 #define Impala_Core_VideoSet_ImportAudioConcepts_h
00003
00004 #include "Persistency/SimilarityTableSetRepository.h"
00005 #include "Core/Table/QuidTable.h"
00006 #include "Core/VideoSet/Reporter.h"
00007 #include "Core/VideoSet/Segmentation.h"
00008 #include "Core/VideoSet/Keyframes.h"
00009 #include "Core/VideoSet/Mpeg7DocAudio.h"
00010
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace VideoSet
00016 {
00017
00018
00019 class ImportAudioConcepts : public Listener
00020 {
00021 public:
00022 typedef Table::SimilarityTableSet SimilarityTableSet;
00023 typedef Table::SimilarityTableSet::SimTableType SimTableType;
00024 typedef Persistency::SimilarityTableSetLocator SimilarityTableSetLocator;
00025 typedef Persistency::SimilarityTableSetRepository SimilarityTableSetRepository;
00026
00027 ImportAudioConcepts(Reporter* reporter, CmdOptions& options)
00028 {
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 Persistency::KeywordListLocator loc(vs->GetLocator(), mConceptSet);
00058 Table::KeywordList names =
00059 *(Persistency::KeywordListRepository().Get(loc));
00060 mSimSet = new SimilarityTableSet(names, 100);
00061 }
00062
00063 virtual void
00064 HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00065 {
00066 String vidName = vs->GetFile(fileId);
00067 for (int c=0 ; c<mSimSet->NrTables() ; c++)
00068 {
00069 int startKey = mKeyframes->GetFirstKeyframeVideo(fileId);
00070 int nrKeys = mKeyframes->GetNrKeyframesVideo(fileId);
00071 if (c == 0)
00072 {
00073 Table::QuidTable* qTable = mSimSet->GetQuidTable();
00074 for (int k=0 ; k<nrKeys ; k++)
00075 {
00076 int frameNr = mKeyframes->GetFrameNr(startKey + k);
00077 Quid quid = vs->GetQuidFrame(fileId, frameNr);
00078 qTable->Add(quid);
00079 }
00080 }
00081 String concept = mSimSet->GetName(c);
00082 SimTableType* table = mSimSet->GetSimTable(c);
00083 for (int k=0 ; k<nrKeys ; k++)
00084 table->Add(0.0);
00085 String fName = "MetaData/similarities/" + mConceptSet + "/"
00086 + vs->GetContainerFile(fileId) + "/" + concept + ".xml";
00087 ILOG_INFO("Reading " << fName);
00088 Persistency::File file =
00089 Persistency::RepositoryInFileSystem::GetInstance().GetFile
00090 (vs->GetLocator(), fName, false, false);
00091 Mpeg7DocAudio mp7(fName, file.GetReadBuffer());
00092 for (int s=0 ; s<mp7.NrSegments() ; s++)
00093 {
00094 double sim = mp7.Confidence(s);
00095 int startFrame = mp7.StartFrameReFraction(s, 25);
00096 int endFrame = mp7.EndFrameReFraction(s, 25);
00097 std::vector<int> shotList;
00098 shotList = mSegmentation->GetShotIds(fileId, startFrame,
00099 endFrame, 12);
00100 for (int i=0 ; i<shotList.size() ; i++)
00101 {
00102 int shot = shotList[i];
00103 int sKey = mKeyframes->GetFirstKeyframeShot(shot);
00104 int nKey = mKeyframes->GetNrKeyframesShot(shot);
00105 for (int k=sKey ; k<sKey+nKey ; k++)
00106 table->Set1(k, sim);
00107 }
00108 }
00109 }
00110 }
00111
00112 virtual void
00113 HandleDoneWalk(VideoSet* vs)
00114 {
00115 mSimSet->ComputeRanks(true);
00116 SimilarityTableSetLocator loc(vs->GetLocator(), true, "", mConceptSet,
00117 mModel, mFeature, "");
00118 SimilarityTableSetRepository().Add(loc, mSimSet);
00119 delete mSimSet;
00120 }
00121
00122 private:
00123
00124 String mConceptSet;
00125 String mModel;
00126 String mFeature;
00127 Segmentation* mSegmentation;
00128 Keyframes* mKeyframes;
00129 SimilarityTableSet* mSimSet;
00130
00131 ILOG_VAR_DEC;
00132
00133 };
00134
00135 ILOG_VAR_INIT(ImportAudioConcepts, Impala.Core.VideoSet);
00136
00137 }
00138 }
00139 }
00140
00141 #endif