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

VisualQueryEngine.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Trec_VisualQueryEngine_h
00002 #define Impala_Core_Trec_VisualQueryEngine_h
00003 
00004 #include "Core/Geometry/Rectangle.h"
00005 
00006 #include "Core/Trec/KeyframeResult.h"
00007 #include "Core/Trec/ShotResult.h"
00008 //#include "Sandbox/ork/XRegionQuery.h"
00009 #include "Basis/ILog.h"
00010 
00011 namespace Impala {
00012 namespace Core {
00013 namespace Trec {
00014 
00015 class VisualQueryEngine {
00016 public:
00017     typedef std::list<KeyframeResult>           KeyframeResultList;
00018 
00019     VisualQueryEngine(ThreadSet *threadset, int maxResults)
00020     {
00021         mThreadSet = threadset;
00022         mMaxResults = maxResults;
00023     }
00024 
00025     KeyframeResultList
00026     QueryByRegion(int keyframeID, Core::Geometry::Rectangle rect, int h, int w)
00027     {
00028         double top, left, bottom, right;
00029         top    = rect.mTop / (double)h;
00030         left   = rect.mLeft / (double)w;
00031         bottom = rect.mBottom / (double)h;
00032         right  = rect.mRight / (double)w;
00033         return QueryByRegion(keyframeID, left, top, right, bottom);
00034     }
00035 
00036     KeyframeResultList
00037     QueryByRegion(int keyframeID, float left, float top, float right, float bot)
00038     {
00039         ILOG_DEBUG("QueryByRegion: keyframe="<<keyframeID<< " (left=" << left <<
00040                    ", top=" << top<< ") x ( right=" << right<< ", bottom=" <<
00041                    bot<< ")");
00042         return QueryVisual(keyframeID, false);
00043 /*        ILOG_STARTACTION("query by region", ILOG_LEVEL_SYSTEM);
00044         Sandbox::XRegionQuery *q = new Sandbox::XRegionQuery();
00045         KeyframeResultList results = q->query(keyframeID, left, top , right,
00046                                               bot, mThreadSet->GetKeyframes());
00047         ILOG_ENDACTION("query by region");
00048         return results; */
00049     }
00050 
00051     KeyframeResultList
00052     QueryVisual(int keyframeID, bool forcerecalculate = false)
00053     {
00054         return QueryVisual("fusionvissemgabor", keyframeID, forcerecalculate);
00055     }
00056 
00057 
00058     KeyframeResultList
00059     QueryVisual(std::string thread, int keyframeID, bool forcerecalculate=false)
00060     {
00061         Thread* visual = mThreadSet->GetThreadByName("visual_" + thread);
00062         // RvB: SaveGuard
00063         if (!visual)
00064         {
00065             KeyframeResultList results;
00066             return results;
00067         }
00068         return QueryVisual(visual, keyframeID, forcerecalculate);
00069     }
00070 
00071     KeyframeResultList
00072     QueryVisual(Thread *thread, int keyframeID, bool forcerecalculate = false,
00073                 int maxToReturn = -1)
00074     {
00075         ThreadVisualSimilarity* threadVisual = (ThreadVisualSimilarity*) thread;
00076         VideoSet::Keyframes* keyFrames = mThreadSet->GetKeyframes();
00077 
00078         int oldMax = threadVisual->GetMaxReturned();
00079         threadVisual->SetMaxReturned(mMaxResults);
00080 
00081         int shotID = keyFrames->GetShotId(keyframeID);
00082         //int nrOfKeyFrames = keyFrames->Size();
00083 
00084         //if (forcerecalculate)
00085             thread->SetOrigin(shotID);
00086         int resultLen = thread->GetLength();
00087         if (maxToReturn >= 0 && maxToReturn < resultLen)
00088             resultLen = maxToReturn;
00089 
00090         KeyframeResultList results;
00091         std::map<int,bool> seen;
00092         for (int i = 0; i < resultLen; i++) {
00093             Trec::KeyframeResult r;
00094             int shot = threadVisual->GetShot(i); // according to current ranking
00095             if (shot < keyFrames->GetNrShots() && shot > -1) {
00096                 r.keyframeid = keyFrames->GetShotRKF(shot);
00097                 if (r.keyframeid != -1 && seen.find(r.keyframeid)==seen.end())
00098                 {
00099                     seen[r.keyframeid] = true;
00100                     r.rank = i+1;
00101                     r.score = threadVisual->GetSimilarity(shot);
00102                     results.push_back(r);
00103                 }
00104             }
00105             else
00106             {
00107                 ILOG_WARN("Received incorrect shot from visual keyframe=" <<
00108                           keyframeID << " at position " << i);
00109                 break; // SK: fix for datasets with less than 400 keyframes
00110             }
00111         }
00112         threadVisual->SetMaxReturned(oldMax);
00113         return results;
00114     }
00115 
00116 
00117 private:
00118     ThreadSet*          mThreadSet;
00119     int                 mMaxResults;
00120 
00121    ILOG_VAR_DEC;
00122 }; // class VisualQueryEngine
00123 
00124 ILOG_VAR_INIT(VisualQueryEngine, Visualization.RotorBrowser);
00125 
00126 }
00127 }
00128 }
00129 #endif

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