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 Persistency::FeatureLocator loc(vs->GetLocator(), false, false,
00060 mWalkType, mFeatureDef.AsString(),
00061 vs->GetContainerFile(fileId));
00062 typedef Feature::FeatureTable FeatureTable;
00063 FeatureTable* table = Persistency::FeatureTableRepository().Get(loc);
00064 if (table == 0)
00065 {
00066 ILOG_ERROR("Unable to find " << mFeatureDef.AsString());
00067 return;
00068 }
00069 String fileName = vs->GetFile(fileId);
00070 String id = fileName;
00071 int nrFrames = mSegmentation->GetNrFramesVideo(fileId);
00072 int frameRateNum = (src) ? src->FrameRateNum() : 0;
00073 int frameRateDen = (src) ? src->FrameRateDen() : 0;
00074 Mpeg7Doc mp7(id, fileName, nrFrames, mFractions, false, "", "",
00075 frameRateNum, frameRateDen);
00076 for (int i=0 ; i<table->Size() ; i++)
00077 {
00078 Quid quid = table->Get1(i);
00079 if (QuidClass(quid) != QUID_CLASS_FRAME)
00080 ILOG_ERROR("Quid is not a frame");
00081 int frameNr = QuidId(quid);
00082 String name = "frame_" + MakeString(frameNr);
00083 Feature::FeatureTable::VectorReal64 v = table->Get2(i);
00084 std::vector<double> vec;
00085 for (int j=0 ; j<v.Size() ; j++)
00086 vec.push_back(v[j]);
00087 mp7.AddFeature(mFeatureDef.GetName(), name, frameNr, frameNr, vec);
00088 }
00089 delete table;
00090 Core::VideoSet::Mpeg7DocWrite(&mp7, vs, fileId);
00091 }
00092
00093 private:
00094
00095 Reporter* mReporter;
00096 int mFractions;
00097 FeatureDefinition mFeatureDef;
00098 Segmentation* mSegmentation;
00099 String mWalkType;
00100
00101 ILOG_VAR_DEC;
00102
00103 };
00104
00105 ILOG_VAR_INIT(ExportFeatures, Impala.Core.VideoSet);
00106
00107 }
00108 }
00109 }
00110
00111 #endif