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

TrecEngine.h

Go to the documentation of this file.
00001 /***********************************************************************************
00002  *
00003  * Application: Investigator's Dashboard (MultimediaN project 6)
00004  * 
00005  * Semantic Video Search Engine
00006  *
00007  * Primary author(s): Ork
00008  *                  : 
00009  *                  : 
00010  ***********************************************************************************/
00011 
00012 #ifndef Impala_Application_IDash_TrecEngine_h
00013 #define Impala_Application_IDash_TrecEngine_h
00014 
00015 #include "Basis/Logger.h"
00016 #include "Basis/CmdOptions.h"
00017 
00018 #include "Core/Trec/ThreadSet.h"
00019 #include "Core/VideoSet/VideoSet.h"
00020 #include "Core/VideoSet/Segmentation.h"
00021 #include "Core/VideoSet/Stills.h"
00022 #include "Core/VideoSet/SegmentationDocument.h"
00023 #include "Core/VideoSet/Keyframes.h"
00024 #include "Core/ImageSet/ImageSet.h"
00025 #include "Core/ImageSet/MakeImageSet.h"
00026 #include "Core/VideoSet/MakeVideoSet.h"
00027 
00028 #include "Application/idash/IDashQueryEngine.h"
00029 
00030 namespace Impala {
00031 namespace Application {
00032 namespace IDash {
00033 
00034 class TrecEngine
00035 {
00036 public:
00037     typedef Impala::Core::Table::TableTem
00038             <Impala::Core::Column::ColumnTem<Real64> >      SimTableType;
00039     typedef Core::Trec::IDashQueryEngine                    IDashQueryEngine;
00040     typedef Core::Trec::KeyframeResult                      KeyframeResult;
00041 
00042     TrecEngine()
00043     {
00044         ILOG_SYSTEM("Loading Semantic Video Search Engine...");
00045 
00046         ILOG_STARTACTION("loading configuration", ILOG_LEVEL_INFO);
00047         LoadConfig();
00048         ILOG_ENDACTION("loading configuration");
00049 
00050         ILOG_STARTACTION("loading data", ILOG_LEVEL_INFO);
00051         LoadData();
00052         ILOG_ENDACTION("loading data");
00053 
00054         mQueryEngine = new IDashQueryEngine(ThreadSet());
00055 
00056     }
00057 
00058 
00059     // Engine Retrieval Functions:
00060     //
00061     // these functions map the engine to the GUI
00062     //
00063     Core::Trec::ThreadSet*
00064     ThreadSet()
00065     {
00066         return mThreadSet;
00067     }
00068 
00069     Core::VideoSet::SegmentationDocument*
00070     SegmentationDocument()
00071     {
00072         return mSegDoc;
00073     }
00074 
00075     Core::Table::SimilarityTableSet*
00076     GetConcepts()
00077     {
00078         return mConcepts;
00079     }
00080 
00081 
00082     Core::VideoSet::Keyframes*
00083     GetKeyframes()
00084     {
00085         return mKeyframes;
00086     }
00087 
00088     Core::ImageSet::ImageSet*
00089     GetKeyframeImageSet()
00090     {
00091         return mKeyframeImages;
00092     }
00093 
00094     double
00095     GetTableSimilarityScore(int table, int row)
00096     {
00097         SimTableType *t = mConcepts->GetSimTable(table);
00098         return (double)t->Get1(row);
00099     }
00100 
00101     std::string
00102     GetTableName(int table)
00103     {
00104         return mConcepts->GetName(table);
00105     }
00106 
00107     int
00108     GetNrTables()
00109     {
00110         return mConcepts->NrTables();
00111     }
00112 
00113     int ImWidth()        { return mThumbWidth; }
00114     int ImHeight()       { return mThumbHeight; }
00115     int ImScale()        { return mThumbScale; }
00116 
00117 
00118     int
00119     GetNumberOfStills(int row)
00120     {
00121         if (!OpenStill(row)) return 0;
00122         return mStillEnd;
00123     }
00124 
00125     Core::Array::Array2dVec3UInt8*
00126     GetStill(int row, int frame)
00127     {
00128         ILOG_DEBUG("GetStill " << row << " " << frame);
00129         if (!OpenStill(row)) return 0;
00130 
00131         return mStillImages->GetImage(mStillStart + frame);
00132 
00133     }
00134 
00135     Core::Array::Array2dVec3UInt8*
00136     GetNextStill(int row)
00137     {
00138         if (!OpenStill(row)) return 0;
00139 
00140         mStillFrame++;
00141         if (mStillFrame >= mStillEnd)
00142             mStillFrame = 0;
00143 
00144         return GetStill(row, mStillFrame);
00145     }
00146 
00147     bool
00148     OpenStill(int row)
00149     {
00150         if (!mStills || !mStillImages)
00151             return false;
00152 
00153         if (row != mStillsRow)
00154         {
00155             mStillsRow = row;
00156             mStillFrame = 0;
00157             mStillStart = mStills->GetFirstStillShot(row);
00158             mStillEnd   = mStills->GetNrStillsShot(row);
00159             ILOG_DEBUG("Opening stills for ID=" << row << " " << mStillEnd << " frames.");
00160         }
00161         return true;
00162     }
00163 
00164     // Engine Actions:
00165     //
00166     void
00167     PerformQuery(std::list<std::string> querycomponents)
00168     {
00169 
00170         ILOG_DEBUG("Preparing query...");
00171         mQueryEngine->Clear();
00172         mQueryEngine->ProcessIDashQueryList(querycomponents);
00173 
00174         if (mQueryEngine->HasComponents()) {
00175             mThreadSet->RemoveThread("shots_initialquery");
00176     
00177             ILOG_DEBUG("Performing query...");
00178             mQueryEngine->GenerateThreadFromQuery("initialquery");
00179         }
00180     }
00181 
00182     void
00183     PerformVisualQuery(std::string threadname, int keyframe)
00184     {
00185         ILOG_DEBUG("Preparing visual query for " << threadname << " keyframe " << keyframe << "...");
00186         mQueryEngine->Clear();
00187         std::list<KeyframeResult> visuals = mVisualQueryEngine->QueryVisual(threadname.substr(7), keyframe, true);
00188         mThreadSet->RemoveThread("shots_initialquery");
00189         mThreadSet->AddThreadShots("initialquery", visuals);
00190     }
00191 
00192 private:
00193 
00194     void
00195     LoadConfig()
00196     {
00197         CmdOptions& options = CmdOptions::GetInstance();
00198         std::string yearStr = options.GetString("year");
00199         mYear = atol(yearStr);
00200 
00201         mVideoSetName = options.GetString("videoSet");
00202         mImageStills = options.GetBool("imageStills");
00203         mKeyServer = options.GetString("keyServer");
00204         mConceptSetName = options.GetString("conceptSet");
00205         mConceptModel = options.GetString("conceptModel");
00206         mConceptFeature = options.GetString("conceptFeature");
00207 
00208         mStillsRow = -1;
00209         mStillFrame = 0;
00210 
00211         mStills = 0; 
00212         mStillImages = 0;
00213 
00214     }
00215 
00216     void
00217     LoadData()
00218     {
00219         typedef Core::ImageSet::ImageSet ImageSet;
00220 
00221         CmdOptions& options = CmdOptions::GetInstance();
00222 
00223         // read the keyframes
00224         ILOG_STARTACTION("reading keyframes", ILOG_LEVEL_INFO);;
00225         ImageSet* imSetKeyfr =
00226             Core::ImageSet::MakeImageSet(options.GetString("imageSetKeyframes"));
00227 
00228         if (imSetKeyfr)
00229             imSetKeyfr->SetImageSrc(false, false, true);
00230         else
00231             ILOG_WARN( "No keyframes available" );
00232         ILOG_ENDACTION("reading keyframes");
00233 
00234         mKeyframeImages = imSetKeyfr;
00235 
00236         // read the thumbnails
00237         ILOG_STARTACTION("reading thumbnails", ILOG_LEVEL_INFO);;
00238         ImageSet* imSetThumb = 
00239             Core::ImageSet::MakeImageSet(options.GetString("imageSetThumbnails"));
00240         if (imSetThumb)
00241         {
00242             imSetThumb->SetImageSrc(! options.GetBool("noArchive"),
00243                                     options.GetBool("imFileArchive"),
00244                                     options.GetBool("imSplitArchive"));
00245 
00246             //Core::Array::Array2dVec3UInt8* im = imSetThumb->GetImage(0);
00247             //mThumbWidth = im->CW();
00248             //mThumbHeight = im->CH();
00249             //delete im;
00250 
00251             // we set this manually to allow for different sizes:
00252             mThumbWidth = 360 / 1.5; //im->CW();
00253             mThumbHeight = 240 / 1.5; //im->CH();
00254 
00255             mKeyframeImages = imSetThumb;
00256 
00257             mThumbScale = 1.0;
00258         }
00259         else
00260             ILOG_WARN( "No thumbnails available" );
00261         ILOG_ENDACTION("reading thumbnails");
00262     
00263 
00264         // read the stills
00265         ILOG_STARTACTION("reading stills", ILOG_LEVEL_INFO);;
00266         ImageSet* imSetStill =
00267             Core::ImageSet::MakeImageSet(options.GetString("imageSetStills"));
00268         if (imSetStill)
00269             imSetStill->SetImageSrc(false, false, true);
00270         else
00271             ILOG_WARN( "No stills available" );
00272         ILOG_ENDACTION("reading stills");
00273 
00274         mStillImages = imSetStill;
00275 
00276         // read the videoset
00277         ILOG_STARTACTION("reading videoset", ILOG_LEVEL_INFO);
00278         mVidSet = Core::VideoSet::MakeVideoSet(mVideoSetName);
00279         ILOG_ENDACTION("reading videoset");
00280 
00281         // read the shots
00282         ILOG_STARTACTION("reading shots", ILOG_LEVEL_INFO);
00283         mShots = new Core::VideoSet::Segmentation(mVidSet, "segmentation");
00284         ILOG_ENDACTION("reading shots");
00285 
00286         // read the keyframe set
00287         ILOG_STARTACTION("reading keyframe set", ILOG_LEVEL_INFO);
00288         mKeyframes = new Core::VideoSet::Keyframes(mVidSet, "keyframes");
00289         ILOG_ENDACTION("reading keyframe set");
00290 
00291         ILOG_STARTACTION("reading stills set", ILOG_LEVEL_INFO);
00292         mStills = new Core::VideoSet::Stills(mVidSet, "stills");
00293         ILOG_ENDACTION("reading stills set");
00294 
00295         //mSegDoc = new Core::VideoSet::SegmentationDocument
00296         //    (mVidSet, mShots, mKeyframes, imSetKeyfr, imSetThumb, imSetStill);
00297 
00298   /*      mThreadSet = new Core::Trec::ThreadSet(mShots, mKeyframes, imSetThumb, imSetKeyfr);
00299         mThreadSet->AddThreadTime();
00300         mThreadSet->AddThreadBookmarked(mSegDoc->GetBookmarked());
00301         mThreadSet->AddThreadHistory();
00302 */
00303         // read the concepts
00304         if (mConceptSetName != "") {
00305             ILOG_STARTACTION("reading concept ranking", ILOG_LEVEL_INFO);
00306             try {
00307                 mConcepts =
00308                     Core::Table::SimilarityTableSet::MakeFromFile(mVidSet,
00309                                                                   mConceptSetName, 
00310                                                                   mConceptModel, 
00311                                                                   mConceptFeature);
00312             } catch (std::length_error) {
00313                 ILOG_ERROR("MakeFromFile threw std::length_error");
00314                 ILOG_ERROR("Probable cause: there are no concepts in set '" << mConceptSetName << "'.");
00315                 mConceptSetName = "";
00316                 mConcepts = 0;
00317             }
00318 
00319             if (mConcepts) {
00320                 ILOG_INFO("Found " << mConcepts->NrTables() << " concepts for this set.");
00321                 for (int i=0; i< mConcepts->NrTables(); i++) {
00322                     //mThreadSet->AddThreadRank(mConceptRanking, i);
00323                 }
00324             }
00325 
00326 
00327             ILOG_ENDACTION("reading concept ranking");
00328 
00329         } else {
00330             ILOG_WARN("concept reading disabled. No concepts available.");
00331             mConcepts = 0;
00332         }
00333 /*
00334         // read the visual similarities:
00335         ILOG_STARTACTION("adding visual similarity", ILOG_LEVEL_INFO);
00336         
00337 //         ILOG_STARTACTION("adding visual similarity - Lab histograms", ILOG_LEVEL_INFO);
00338 //         mThreadSet->AddThreadVisualSimilarity("labhistogram");
00339 //         ILOG_ENDACTION("adding visual similarity - Lab histograms");
00340 
00341         ILOG_STARTACTION("adding visual similarity - Weibull", ILOG_LEVEL_INFO);
00342         mThreadSet->AddThreadVisualSimilarity("vissem");
00343         ILOG_ENDACTION("adding visual similarity - Weibull");
00344 
00345         ILOG_STARTACTION("adding visual similarity - Gabor", ILOG_LEVEL_INFO);
00346         mThreadSet->AddThreadVisualSimilarity("vissemgabor");
00347         ILOG_ENDACTION("adding visual similarity - Gabor");
00348 
00349 //         ILOG_STARTACTION("adding visual similarity - Fusion", ILOG_LEVEL_INFO);
00350 //         mThreadSet->AddThreadVisualSimilarity("fusionvissemgabor");
00351 //         ILOG_ENDACTION("adding visual similarity - Fusion");
00352 
00353         ILOG_ENDACTION("adding visual similarity");
00354 
00355 */
00356         //mVisualQueryEngine = new Core::Trec::VisualQueryEngine(mThreadSet, 400);
00357 
00358 
00359     }
00360 
00361     // Data
00362     Core::VideoSet::VideoSet*        mVidSet;
00363     Core::VideoSet::Segmentation*    mShots;
00364     Core::VideoSet::Keyframes*       mKeyframes;
00365     Core::Trec::ThreadSet*           mThreadSet;
00366     Core::Table::SimilarityTableSet* mConcepts;
00367     Core::VideoSet::SegmentationDocument* mSegDoc; // controls current shot
00368 
00369     Core::ImageSet::ImageSet*        mKeyframeImages;
00370     Core::ImageSet::ImageSet*        mStillImages;
00371     Core::VideoSet::Stills*          mStills;
00372 
00373     int mStillsRow, mStillStart, mStillEnd, mStillFrame;
00374 
00375 
00376     int                             mThumbWidth;
00377     int                             mThumbHeight;
00378     double                          mThumbScale;
00379     std::string                     mConceptSetName;
00380     std::string                     mConceptModel;
00381     std::string                     mConceptFeature;
00382 
00383     // Computation
00384     IDashQueryEngine*               mQueryEngine;
00385     Core::Trec::VisualQueryEngine*  mVisualQueryEngine;
00386 
00387     // Configuration
00388     std::string                     mVideoSetName;
00389     bool                            mImageStills;
00390     std::string                     mKeyServer;
00391     int                             mYear;
00392 
00393 
00394     ILOG_VAR_DEC;
00395 };
00396 
00397 ILOG_VAR_INIT(TrecEngine, Application.IDash);
00398 
00399 
00400 
00401 }
00402 }
00403 }
00404 
00405 #endif

Generated on Fri Mar 19 09:30:27 2010 for ImpalaSrc by  doxygen 1.5.1