Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ProtoSimilarityEval.h

Go to the documentation of this file.
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         // check if override is not set, and the features already exist
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 // REPOSITORY_USED
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         // For temporal filtering use something like this instead:
00109         // (requires --srcWindow "size;5;rgb2ooo")
00110         /*
00111         typedef Stream::RgbDataSrcWindow<Stream::WindowPrepRgb2Ooo> WindowType;
00112         WindowType* window = dynamic_cast<WindowType*>(src);
00113         if (window)
00114         {
00115             std::cout << "window size = " << window->WindowSize() << std::endl;
00116             Array::Array2dScalarReal64* tGauss = 0;
00117             double temporalSigma = 0.75;
00118             tGauss = Array::MakeGaussian1d(temporalSigma, 0, 3.0, 100);
00119             Array::Array2dVec3Real64* res = 0;
00120             SeqConvKernel(res, window, tGauss);
00121             // res is now like im above and should be given to InvWiccest
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 // Here comes the deprecated stuff
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     // if override is not set, and the features already exist
00179     bool mSkipThisVideo;
00180 
00181     ILOG_VAR_DEC;
00182 
00183 };
00184 
00185 ILOG_VAR_INIT(ProtoSimilarityEval, Impala.Core.VideoSet);
00186 
00187 } // namespace VideoSet
00188 } // namespace Core
00189 } // namespace Impala
00190 
00191 #endif

Generated on Fri Mar 19 09:31:14 2010 for ImpalaSrc by  doxygen 1.5.1