00001 #ifndef Impala_Core_VideoSet_ExportFeatures_h
00002 #define Impala_Core_VideoSet_ExportFeatures_h
00003
00004 #include "Persistency/FeatureTableRepository.h"
00005 #include "Core/Feature/FeatureTable.h"
00006 #include "Core/VideoSet/Reporter.h"
00007 #include "Core/VideoSet/Segmentation.h"
00008 #include "Core/VideoSet/Mpeg7DocWrite.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace VideoSet
00015 {
00016
00017
00018 class ExportFeatures : public Listener
00019 {
00020 public:
00021 typedef Feature::FeatureDefinition FeatureDefinition;
00022
00023 ExportFeatures(Reporter* reporter, CmdOptions& options)
00024 {
00025 mReporter = reporter;
00026 if (options.GetNrArg() < 3)
00027 {
00028 ILOG_ERROR("Missing argument");
00029 return;
00030 }
00031 mFractions = atol(options.GetArg(2));
00032 if ((mFractions != 25) && (mFractions != 30000))
00033 ILOG_WARN("Never tried fractions = " << mFractions);
00034 mFeatureDef = FeatureDefinition(options.GetArg(3));
00035 mSegmentation = 0;
00036 mWalkType = "unknown";
00037 }
00038
00039 virtual void
00040 HandleNewWalk(VideoSet* vs, String walkType)
00041 {
00042 mWalkType = walkType;
00043 }
00044
00045 virtual void
00046 HandleNewWalk(VideoSet* vs, Segmentation* segmentation)
00047 {
00048 mSegmentation = segmentation;
00049 }
00050
00051 virtual void
00052 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00053 {
00054 if ((mSegmentation == 0))
00055 {
00056 ILOG_ERROR("Need segmentation");
00057 return;
00058 }
00059 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00060 String fName = vs->GetFilePathFeatureData(mWalkType, mFeatureDef,
00061 fileId, false, -1, false,
00062 false);
00063 if (fName.empty())
00064 {
00065 ILOG_ERROR("Unable to find " << mFeatureDef.AsString());
00066 return;
00067 }
00068 Feature::FeatureTable table(mFeatureDef);
00069 Table::Read(&table, fName, vs->GetDatabase());
00070
00071 String fileName = vs->GetFile(fileId);
00072 String id = fileName;
00073 int nrFrames = mSegmentation->GetNrFramesVideo(fileId);
00074 Mpeg7Doc mp7(id, fileName, nrFrames, mFractions, false, "", "");
00075 for (int i=0 ; i<table.Size() ; i++)
00076 {
00077 Quid quid = table.Get1(i);
00078 if (QuidClass(quid) != QUID_CLASS_FRAME)
00079 ILOG_ERROR("Quid is not a frame");
00080 int frameNr = QuidId(quid);
00081 String name = "frame_" + MakeString(frameNr);
00082 Feature::FeatureTable::VectorReal64 v = table.Get2(i);
00083 std::vector<double> vec;
00084 for (int j=0 ; j<v.Size() ; j++)
00085 vec.push_back(v[j]);
00086 mp7.AddFeature(mFeatureDef.GetName(), name, frameNr, frameNr, vec);
00087 }
00088 #else // REPOSITORY_USED
00089 Persistency::FeatureLocator loc(vs->GetLocator(), false, false,
00090 mWalkType, mFeatureDef.AsString(),
00091 vs->GetContainerFile(fileId));
00092 typedef Feature::FeatureTable FeatureTable;
00093 FeatureTable* table = Persistency::FeatureTableRepository().Get(loc);
00094 if (table == 0)
00095 {
00096 ILOG_ERROR("Unable to find " << mFeatureDef.AsString());
00097 return;
00098 }
00099 String fileName = vs->GetFile(fileId);
00100 String id = fileName;
00101 int nrFrames = mSegmentation->GetNrFramesVideo(fileId);
00102 Mpeg7Doc mp7(id, fileName, nrFrames, mFractions, false, "", "");
00103 for (int i=0 ; i<table->Size() ; i++)
00104 {
00105 Quid quid = table->Get1(i);
00106 if (QuidClass(quid) != QUID_CLASS_FRAME)
00107 ILOG_ERROR("Quid is not a frame");
00108 int frameNr = QuidId(quid);
00109 String name = "frame_" + MakeString(frameNr);
00110 Feature::FeatureTable::VectorReal64 v = table->Get2(i);
00111 std::vector<double> vec;
00112 for (int j=0 ; j<v.Size() ; j++)
00113 vec.push_back(v[j]);
00114 mp7.AddFeature(mFeatureDef.GetName(), name, frameNr, frameNr, vec);
00115 }
00116 delete table;
00117 #endif // REPOSITORY_USED
00118 Core::VideoSet::Mpeg7DocWrite(&mp7, vs, fileId);
00119 }
00120
00121 private:
00122
00123 Reporter* mReporter;
00124 int mFractions;
00125 FeatureDefinition mFeatureDef;
00126 Segmentation* mSegmentation;
00127 String mWalkType;
00128
00129 ILOG_VAR_DEC;
00130
00131 };
00132
00133 ILOG_VAR_INIT(ExportFeatures, Impala.Core.VideoSet);
00134
00135 }
00136 }
00137 }
00138
00139 #endif