00001 #ifndef Impala_Core_VideoSet_ImportConcepts_h
00002 #define Impala_Core_VideoSet_ImportConcepts_h
00003
00004 #include "Util/DatabaseReadString.h"
00005 #include "Util/DatabaseWriteString.h"
00006 #include "Core/Table/SimilarityTableSet.h"
00007 #include "Core/VideoSet/Reporter.h"
00008 #include "Core/VideoSet/Segmentation.h"
00009 #include "Core/VideoSet/Keyframes.h"
00010 #include "Core/VideoSet/Mpeg7Doc.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace VideoSet
00017 {
00018
00019
00020 class ImportConcepts : public Listener
00021 {
00022 public:
00023 typedef Table::SimilarityTableSet SimilarityTableSet;
00024 typedef Table::SimilarityTableSet::SimTableType SimTableType;
00025
00026 ImportConcepts(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 mSimSet = 0;
00038 }
00039
00040 virtual void
00041 HandleNewWalk(VideoSet* vs)
00042 {
00043 String fName = vs->GetFilePathAnnotation(mConceptSet, false, false);
00044 if (fName.empty())
00045 {
00046 ILOG_ERROR("Unable to read conceptSet");
00047 return;
00048 }
00049 std::vector<String> names;
00050 Util::DatabaseReadString(std::back_inserter(names), fName,
00051 vs->GetDatabase(), true);
00052 mSimSet = new SimilarityTableSet(names, 100);
00053 }
00054
00055 virtual void
00056 HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00057 {
00058 String vidName = vs->GetFile(fileId);
00059 for (int c=0 ; c<mSimSet->NrTables() ; c++)
00060 {
00061 String concept = mSimSet->GetName(c);
00062 SimTableType* table = mSimSet->GetSimTable(c);
00063 String fName;
00064 fName = vs->GetFilePathMpeg7Concept(fileId, mConceptSet,
00065 concept + ".xml", false, true);
00066 if (fName.empty())
00067 {
00068 continue;
00069 }
00070 Mpeg7Doc mp7(fName, vs->GetDatabase());
00071 for (int s=0 ; s<mp7.NrShots() ; s++)
00072 {
00073 double sim = mp7.Confidence(s);
00074 table->Add(sim);
00075 }
00076 if (c == 0)
00077 {
00078 Table::QuidTable* qTable = mSimSet->GetQuidTable();
00079 for (int s=0 ; s<mp7.NrShots() ; s++)
00080 {
00081 Quid quid = vs->GetQuidFrame(fileId, mp7.StartFrame(s));
00082 qTable->Add(quid);
00083 }
00084 }
00085 }
00086 }
00087
00088 virtual void
00089 HandleDoneWalk(VideoSet* vs)
00090 {
00091 mSimSet->ComputeRanks(true);
00092 mSimSet->Save(vs, mConceptSet, mModel, mFeature, true);
00093 delete mSimSet;
00094 }
00095
00096 private:
00097
00098 Reporter* mReporter;
00099 String mConceptSet;
00100 String mModel;
00101 String mFeature;
00102 SimilarityTableSet* mSimSet;
00103
00104 ILOG_VAR_DEC;
00105
00106 };
00107
00108 ILOG_VAR_INIT(ImportConcepts, Impala.Core.VideoSet);
00109
00110 }
00111 }
00112 }
00113
00114 #endif