00001 #ifndef Impala_Core_VideoSet_ProtoSimilarityEval_h
00002 #define Impala_Core_VideoSet_ProtoSimilarityEval_h
00003
00004 #include "Persistency/FeatureTableRepository.h"
00005 #include "Core/Feature/Computor.h"
00006 #include "Core/VideoSet/Reporter.h"
00007 #include "Core/Stream/SeqConvKernel.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace VideoSet
00014 {
00015
00016
00017 class ProtoSimilarityEval : public Listener
00018 {
00019 public:
00020 typedef Persistency::FeatureLocator FeatureLocator;
00021
00022 ProtoSimilarityEval(Feature::Computor* computor, Reporter* reporter,
00023 CmdOptions& options)
00024 {
00025 mReporter = reporter;
00026 mComputor = computor;
00027 mWalkType = "unknown";
00028 mIsPartial = false;
00029 if (options.GetNrArg() < 5)
00030 ILOG_ERROR("Need more arguments");
00031 String protoSet = options.GetArg(2);
00032 if (protoSet == "nil")
00033 protoSet = "";
00034 String maskSet = options.GetArg(3);
00035 if (maskSet == "nil")
00036 maskSet = "";
00037 int maxNr = atol(options.GetArg(4));
00038 mComputor->ReadPrototypes(protoSet, maskSet, maxNr);
00039 mSkipThisVideo = false;
00040 }
00041
00042 virtual void
00043 HandleNewWalk(VideoSet* vs, String walkType)
00044 {
00045 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00046 mWalkType = walkType;
00047 #endif // REPOSITORY_USED
00048 mLoc = FeatureLocator(vs->GetLocator(), false, false, walkType,
00049 "unknown", "unknown");
00050 }
00051
00052 virtual void
00053 HandleNewWalkPartial(VideoSet* vs, int startFrame, int stepSize,
00054 int numberFrames)
00055 {
00056 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00057 mIsPartial = true;
00058 mStartFrame = startFrame;
00059 #endif // REPOSITORY_USED
00060 mLoc.SetNumberFrames(numberFrames);
00061 mLoc.SetStartFrame(startFrame);
00062 }
00063
00064 virtual void
00065 HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00066 {
00067
00068 mSkipThisVideo = false;
00069 if (CmdOptions::GetInstance().GetBool("override"))
00070 return;
00071
00072 Feature::FeatureTableSet* tableSet = mComputor->GetFeatureTableSet();
00073 for (int i=0 ; i<tableSet->Size() ; i++)
00074 {
00075 if (mLoc.GetIsPartial() && (tableSet->GetTable(i)->Size() < 2))
00076 continue;
00077 Feature::FeatureDefinition def = tableSet->GetFeatureDefinition(i);
00078 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00079 String fName = vs->GetFilePathFeatureData(mWalkType, def, fileId,
00080 mIsPartial, mStartFrame,
00081 true, false);
00082 if (fName.empty())
00083 #else
00084 mLoc.SetFeatureDef(def);
00085 mLoc.SetContainer(vs->GetContainerFile(fileId));
00086 if (Persistency::FeatureTableRepository().Exists(mLoc))
00087 #endif // REPOSITORY_USED
00088 {
00089 ILOG_INFO("Skipping video " << fileId <<
00090 "; FeatureData file already exists");
00091 mSkipThisVideo = true;
00092 }
00093 }
00094 }
00095
00096
00097 virtual void
00098 HandleNewFrame(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00099 {
00100 if (mSkipThisVideo)
00101 return;
00102 Array::Array2dVec3UInt8* im = Array::ArrayCreate<Array::Array2dVec3UInt8>
00103 (src->FrameWidth(), src->FrameHeight(), 0, 0, src->DataPtr(), true);
00104 Quid quid = vs->GetQuidFrame(fileId, src->FrameNr(), true);
00105 mComputor->ComputeFeatures(im, quid);
00106 delete im;
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 }
00125
00126 virtual void
00127 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00128 {
00129 if (mSkipThisVideo)
00130 return;
00131 bool binary = true;
00132 Feature::FeatureTableSet* tableSet = mComputor->GetFeatureTableSet();
00133 for (int i=0 ; i<tableSet->Size() ; i++)
00134 {
00135 if (mIsPartial && (tableSet->GetTable(i)->Size() < 2))
00136 continue;
00137 Feature::FeatureDefinition def = tableSet->GetFeatureDefinition(i);
00138 def = mComputor->ExtendFeatureDefinition(def);
00139 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00140 String fName = vs->GetFilePathFeatureData(mWalkType, def, fileId,
00141 mIsPartial, mStartFrame,
00142 true, false);
00143 if (!fName.empty())
00144 Table::Write(tableSet->GetTable(i), fName, vs->GetDatabase(),
00145 binary);
00146 #else // REPOSITORY_USED
00147 mLoc.SetFeatureDef(def);
00148 Persistency::FeatureTableRepository().Add(mLoc,
00149 tableSet->GetTable(i));
00150 #endif // REPOSITORY_USED
00151 tableSet->GetTable(i)->SetSize(0);
00152 }
00153 String mask = mComputor->GetMaskSetBase();
00154 if (!mask.empty())
00155 {
00156 #ifndef REPOSITORY_USED
00157 String fName = vs->GetFilePathFeatureData
00158 (mWalkType, mask + ".txt", fileId, mIsPartial, mStartFrame,
00159 true, false);
00160 if (!fName.empty())
00161 mComputor->WriteFeatureDefinitions(fName, vs->GetDatabase());
00162 #else // REPOSITORY_USED
00163 mLoc.SetFeatureString(mask + ".txt");
00164 mComputor->WriteFeatureDefinitions(mLoc);
00165 #endif // REPOSITORY_USED
00166 }
00167 }
00168
00169 private:
00170
00171 Reporter* mReporter;
00172 Feature::Computor* mComputor;
00173 String mWalkType;
00174 bool mIsPartial;
00175 int mStartFrame;
00176 FeatureLocator mLoc;
00177
00178
00179 bool mSkipThisVideo;
00180
00181 ILOG_VAR_DEC;
00182
00183 };
00184
00185 ILOG_VAR_INIT(ProtoSimilarityEval, Impala.Core.VideoSet);
00186
00187 }
00188 }
00189 }
00190
00191 #endif