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

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