00001
00002
00003
00004
00005
00006
00007
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/SegmentationDocument.h"
00022 #include "Core/VideoSet/Keyframes.h"
00023 #include "Core/ImageSet/ImageSet.h"
00024 #include "Core/ImageSet/MakeImageSet.h"
00025 #include "Core/VideoSet/MakeVideoSet.h"
00026
00027 #include "IDashQueryEngine.h"
00028
00029 namespace Impala {
00030 namespace Application {
00031 namespace IDash {
00032
00033 class TrecEngine
00034 {
00035 public:
00036 typedef Core::Trec::IDashQueryEngine IDashQueryEngine;
00037 typedef Core::Trec::KeyframeResult KeyframeResult;
00038
00039 TrecEngine()
00040 {
00041 ILOG_SYSTEM("Loading Semantic Video Search Engine...");
00042
00043 ILOG_STARTACTION("loading configuration", ILOG_LEVEL_INFO);
00044 LoadConfig();
00045 ILOG_ENDACTION("loading configuration");
00046
00047 ILOG_STARTACTION("loading data", ILOG_LEVEL_INFO);
00048 LoadData();
00049 ILOG_ENDACTION("loading data");
00050
00051 mQueryEngine = new IDashQueryEngine(ThreadSet());
00052
00053 }
00054
00055
00056
00057
00058
00059
00060 Core::Trec::ThreadSet*
00061 ThreadSet()
00062 {
00063 return mThreadSet;
00064 }
00065
00066 Core::VideoSet::SegmentationDocument*
00067 SegmentationDocument()
00068 {
00069 return mSegDoc;
00070 }
00071
00072 Core::Table::SimilarityTableSet*
00073 GetConceptRanking()
00074 {
00075 return mConceptRanking;
00076 }
00077
00078
00079 int ImWidth() { return mThumbWidth; }
00080 int ImHeight() { return mThumbHeight; }
00081 int ImScale() { return mThumbScale; }
00082
00083
00084
00085
00086 void
00087 PerformQuery(std::list<std::string> querycomponents)
00088 {
00089
00090 ILOG_DEBUG("Preparing query...");
00091 mQueryEngine->Clear();
00092 mQueryEngine->ProcessIDashQueryList(querycomponents);
00093
00094 if (mQueryEngine->HasComponents()) {
00095 mThreadSet->RemoveThread("shots_initialquery");
00096
00097 ILOG_DEBUG("Performing query...");
00098 mQueryEngine->GenerateThreadFromQuery("initialquery");
00099 }
00100 }
00101
00102 void
00103 PerformVisualQuery(std::string threadname, int keyframe)
00104 {
00105 ILOG_DEBUG("Preparing visual query for " << threadname <<
00106 " keyframe " << keyframe << "...");
00107 mQueryEngine->Clear();
00108 std::list<KeyframeResult> visuals =
00109 mVisualQueryEngine->QueryVisual(threadname.substr(7),keyframe,true);
00110 mThreadSet->RemoveThread("shots_initialquery");
00111 mThreadSet->AddThreadShots("initialquery", visuals);
00112 }
00113
00114
00115 private:
00116
00117 void
00118 LoadConfig()
00119 {
00120 CmdOptions& options = CmdOptions::GetInstance();
00121 std::string yearStr = options.GetString("year");
00122 mYear = atol(yearStr);
00123
00124 mVideoSetName = options.GetString("videoSet");
00125 mImageStills = options.GetBool("imageStills");
00126 mKeyServer = options.GetString("keyServer");
00127 mConceptSetName = options.GetString("conceptSet");
00128 mConceptModel = options.GetString("conceptModel");
00129 mConceptFeature = options.GetString("conceptFeature");
00130 }
00131
00132 void
00133 LoadData()
00134 {
00135 typedef Core::ImageSet::ImageSet ImageSet;
00136
00137 CmdOptions& options = CmdOptions::GetInstance();
00138
00139
00140 ILOG_STARTACTION("reading keyframes", ILOG_LEVEL_INFO);;
00141 ImageSet* imSetKeyfr =
00142 Core::ImageSet::MakeImageSet(options.GetString("imageSetKeyframes"));
00143 if (imSetKeyfr)
00144 imSetKeyfr->SetImageSrc(false, false, true);
00145 else
00146 ILOG_WARN( "No keyframes available" );
00147 ILOG_ENDACTION("reading keyframes");
00148
00149
00150 ILOG_STARTACTION("reading thumbnails", ILOG_LEVEL_INFO);
00151 String imSetThumbStr = options.GetString("imageSetThumbnails");
00152 ImageSet* imSetThumb = Core::ImageSet::MakeImageSet(imSetThumbStr);
00153 if (imSetThumb)
00154 {
00155 imSetThumb->SetImageSrc(! options.GetBool("noArchive"),
00156 options.GetBool("imFileArchive"),
00157 options.GetBool("imSplitArchive"));
00158
00159
00160
00161
00162
00163
00164
00165 mThumbWidth = 360 / 1.5;
00166 mThumbHeight = 240 / 1.5;
00167
00168 mThumbScale = 1.0;
00169 }
00170 else
00171 ILOG_WARN( "No thumbnails available" );
00172 ILOG_ENDACTION("reading thumbnails");
00173
00174
00175 ILOG_STARTACTION("reading stills", ILOG_LEVEL_INFO);;
00176 ImageSet* imSetStill =
00177 Core::ImageSet::MakeImageSet(options.GetString("imageSetStills"));
00178 if (imSetStill)
00179 imSetStill->SetImageSrc(false, false, true);
00180 else
00181 ILOG_WARN( "No stills available" );
00182 ILOG_ENDACTION("reading stills");
00183
00184
00185 ILOG_STARTACTION("reading videoset", ILOG_LEVEL_INFO);
00186 mVidSet = Core::VideoSet::MakeVideoSet(mVideoSetName);
00187 ILOG_ENDACTION("reading videoset");
00188
00189
00190 ILOG_STARTACTION("reading shots", ILOG_LEVEL_INFO);
00191 mShots = new Core::VideoSet::Segmentation(mVidSet, "segmentation");
00192 ILOG_ENDACTION("reading shots");
00193
00194
00195 ILOG_STARTACTION("reading keyframe set", ILOG_LEVEL_INFO);
00196 mKeyframes = new Core::VideoSet::Keyframes(mVidSet, "keyframes");
00197 ILOG_ENDACTION("reading keyframe set");
00198
00199 mSegDoc = new Core::VideoSet::SegmentationDocument
00200 (mVidSet, mShots, mKeyframes, imSetKeyfr, imSetThumb, imSetStill);
00201
00202 mThreadSet = new Core::Trec::ThreadSet(mShots, mKeyframes, imSetThumb, imSetKeyfr);
00203 mThreadSet->AddThreadTime();
00204 mThreadSet->AddThreadBookmarked(mSegDoc->GetBookmarked());
00205 mThreadSet->AddThreadHistory();
00206
00207
00208 if (mConceptSetName != "") {
00209 ILOG_STARTACTION("reading concept ranking", ILOG_LEVEL_INFO);
00210 try {
00211 mConceptRanking =
00212 Core::Table::SimilarityTableSet::MakeFromFile(mVidSet,
00213 mConceptSetName,
00214 mConceptModel,
00215 mConceptFeature);
00216 } catch (std::length_error) {
00217 ILOG_ERROR("MakeFromFile threw std::length_error");
00218 ILOG_ERROR("Probable cause: there are no concepts in set '" << mConceptSetName << "'.");
00219 mConceptSetName = "";
00220 mConceptRanking = 0;
00221 }
00222
00223 if (mConceptRanking) {
00224 ILOG_INFO("Found " << mConceptRanking->NrTables() << " concepts for this set.");
00225 for (int i=0; i< mConceptRanking->NrTables(); i++) {
00226 mThreadSet->AddThreadRank(mConceptRanking, i);
00227 }
00228 }
00229
00230
00231 ILOG_ENDACTION("reading concept ranking");
00232
00233 } else {
00234 ILOG_WARN("concept reading disabled. No concepts available.");
00235 mConceptRanking = 0;
00236 }
00237
00238
00239 ILOG_STARTACTION("adding visual similarity", ILOG_LEVEL_INFO);
00240
00241 ILOG_STARTACTION("adding visual similarity - Lab histograms", ILOG_LEVEL_INFO);
00242 mThreadSet->AddThreadVisualSimilarity("labhistogram");
00243 ILOG_ENDACTION("adding visual similarity - Lab histograms");
00244
00245 ILOG_STARTACTION("adding visual similarity - Weibull", ILOG_LEVEL_INFO);
00246 mThreadSet->AddThreadVisualSimilarity("vissem");
00247 ILOG_ENDACTION("adding visual similarity - Weibull");
00248
00249 ILOG_STARTACTION("adding visual similarity - Gabor", ILOG_LEVEL_INFO);
00250 mThreadSet->AddThreadVisualSimilarity("vissemgabor");
00251 ILOG_ENDACTION("adding visual similarity - Gabor");
00252
00253 ILOG_STARTACTION("adding visual similarity - Fusion", ILOG_LEVEL_INFO);
00254 mThreadSet->AddThreadVisualSimilarity("fusionvissemgabor");
00255 ILOG_ENDACTION("adding visual similarity - Fusion");
00256
00257 ILOG_ENDACTION("adding visual similarity");
00258
00259
00260 mVisualQueryEngine = new Core::Trec::VisualQueryEngine(mThreadSet, 400);
00261
00262
00263 }
00264
00265
00266 Core::VideoSet::VideoSet* mVidSet;
00267 Core::VideoSet::Segmentation* mShots;
00268 Core::VideoSet::Keyframes* mKeyframes;
00269 Core::Trec::ThreadSet* mThreadSet;
00270 Core::Table::SimilarityTableSet* mConceptRanking;
00271
00272 Core::VideoSet::SegmentationDocument* mSegDoc;
00273
00274 int mThumbWidth;
00275 int mThumbHeight;
00276 double mThumbScale;
00277 std::string mConceptSetName;
00278 std::string mConceptModel;
00279 std::string mConceptFeature;
00280
00281
00282 IDashQueryEngine* mQueryEngine;
00283 Core::Trec::VisualQueryEngine* mVisualQueryEngine;
00284
00285
00286 std::string mVideoSetName;
00287 bool mImageStills;
00288 std::string mKeyServer;
00289 int mYear;
00290
00291
00292 ILOG_VAR_DEC;
00293 };
00294
00295 ILOG_VAR_INIT(TrecEngine, Application.IDash);
00296
00297
00298
00299 }
00300 }
00301 }
00302
00303 #endif