00001 #ifndef Impala_Core_VideoSet_ExportConcepts_h
00002 #define Impala_Core_VideoSet_ExportConcepts_h
00003
00004 #include "Persistency/SimilarityTableSetRepository.h"
00005 #include "Core/VideoSet/Reporter.h"
00006 #include "Core/VideoSet/Segmentation.h"
00007 #include "Core/VideoSet/Mpeg7DocWrite.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace VideoSet
00014 {
00015
00016
00017 class ExportConcepts : public Listener
00018 {
00019 public:
00020 typedef Feature::FeatureDefinition FeatureDefinition;
00021 typedef Table::SimilarityTableSet SimilarityTableSet;
00022 typedef Persistency::SimilarityTableSetLocator SimilarityTableSetLocator;
00023 typedef Persistency::SimilarityTableSetRepository SimilarityTableSetRepository;
00024
00025 ExportConcepts(Reporter* reporter, CmdOptions& options)
00026 {
00027 mReporter = reporter;
00028 if (options.GetNrArg() < 5)
00029 {
00030 ILOG_ERROR("Missing argument");
00031 return;
00032 }
00033 mFractions = atol(options.GetArg(2));
00034 if ((mFractions != 25) && (mFractions != 30000))
00035 ILOG_WARN("Never tried fractions = " << mFractions);
00036 mConceptFileName = options.GetArg(3);
00037 mModel = options.GetArg(4);
00038 if (options.GetNrArg() > 5)
00039 mFeatureDef = FeatureDefinition(options.GetArg(5));
00040 mSegmentation = 0;
00041 }
00042
00043 virtual void
00044 HandleNewWalk(VideoSet* vs, String walkType)
00045 {
00046 mWalkType = walkType;
00047 }
00048
00049 virtual void
00050 HandleNewWalk(VideoSet* vs, Segmentation* segmentation)
00051 {
00052 mSegmentation = segmentation;
00053 }
00054
00055 virtual void
00056 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00057 {
00058 if ((mSegmentation == 0))
00059 {
00060 ILOG_ERROR("Need segmentation");
00061 return;
00062 }
00063 int frameRateNum = (src) ? src->FrameRateNum() : 0;
00064 int frameRateDen = (src) ? src->FrameRateDen() : 0;
00065 String subDir = (mFeatureDef.Empty()) ? "" : mFeatureDef.AsString();
00066 SimilarityTableSetLocator loc(vs->GetLocator(), false, mWalkType,
00067 mConceptFileName, mModel, subDir,
00068 vs->GetContainer(fileId));
00069 SimilarityTableSet* simSet = SimilarityTableSetRepository().Get(loc);
00070
00071 for (int c=0 ; c<simSet->NrTables() ; c++)
00072 {
00073 String concept = simSet->GetName(c);
00074 ILOG_INFO("doing concept " << concept);
00075 ILOG_NDC_PUSH(concept);
00076 SimilarityTableSet::SimTableType* table = simSet->GetSimTable(c);
00077 String fileName = vs->GetFile(fileId);
00078 ILOG_DEBUG("doing file " << fileName);
00079 String id = fileName;
00080 int nrFrames = mSegmentation->GetNrFramesVideo(fileId);
00081 Mpeg7Doc mp7(id, fileName, nrFrames, mFractions, false,
00082 mConceptFileName, concept, frameRateNum, frameRateDen);
00083 mp7.SetAnnoIsConcept();
00084 for (int i=0 ; i<table->Size() ; i++)
00085 {
00086 Quid quid = simSet->GetQuidTable()->Get1(i);
00087 if (QuidClass(quid) != QUID_CLASS_FRAME)
00088 ILOG_ERROR("Quid is not a frame");
00089 int frameNr = QuidId(quid);
00090 String name = "frame_" + MakeString(frameNr);
00091 double sim = table->Get1(i);
00092 mp7.AddAnnotation(concept, name, frameNr, frameNr, 1, sim);
00093 }
00094 Core::VideoSet::Mpeg7DocWrite(&mp7, vs, fileId);
00095 ILOG_NDC_POP;
00096 }
00097 delete simSet;
00098 }
00099
00100 private:
00101
00102 Reporter* mReporter;
00103 int mFractions;
00104 String mConceptFileName;
00105 String mModel;
00106 FeatureDefinition mFeatureDef;
00107 Segmentation* mSegmentation;
00108 String mWalkType;
00109
00110 ILOG_VAR_DEC;
00111
00112 };
00113
00114 ILOG_VAR_INIT(ExportConcepts, Impala.Core.VideoSet);
00115
00116 }
00117 }
00118 }
00119
00120 #endif