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

ThreadShots.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Trec_ThreadShots_h
00002 #define Impala_Core_Trec_ThreadShots_h
00003 
00004 #include "Core/Trec/Thread.h"
00005 #include "Core/Column/Find.h"
00006 
00007 #include "Core/VideoSet/Segmentation.h"
00008 #include "Core/Trec/ShotResult.h"
00009 #include "Core/Trec/KeyframeResult.h"
00010 
00011 #include "Core/Table/AnnotationTable.h"
00012 
00013 namespace Impala
00014 {
00015 namespace Core
00016 {
00017 namespace Trec
00018 {
00019 
00020 class ThreadShots : public Thread
00021 {
00022 public:
00023 
00024     ThreadShots(std::string identifier, std::list<ShotResult> shotlist,
00025                 Core::VideoSet::Segmentation* shots,
00026                 Core::VideoSet::Keyframes* keyframes) :
00027         Thread(std::string("shots_") + identifier)
00028     {
00029         mShots = new Core::Table::AnnotationTable();
00030         mSegmentation = shots;
00031         ConvertToTable(shotlist, shots);
00032     }
00033 
00034     ThreadShots(std::string identifier, std::list<KeyframeResult> keyframelist,
00035                 Core::VideoSet::Segmentation* shots,
00036                 Core::VideoSet::Keyframes* keyframes) :
00037         Thread(std::string("shots_") + identifier)
00038     {
00039         mShots = new Core::Table::AnnotationTable();
00040         mSegmentation = shots;
00041         ConvertToTable(keyframelist, shots, keyframes);
00042     }
00043 
00044     virtual int
00045     GetShot(int position)
00046     {
00047         if ((position < 0) || (position >= mShots->Size()))
00048             return -1;
00049 
00050         Quid s = mShots->Get1(position);
00051         return mSegmentation->GetShotId(s);
00052     }
00053 
00054     Real64
00055     GetShotScore(int position)
00056     {
00057         if ((position < 0) || (position >= mShots->Size()))
00058             return -1;
00059         return mShots->Get2(position);
00060     }
00061 
00062     virtual int
00063     GetLength()
00064     {
00065         return mShots->Size();
00066     }
00067 
00068     virtual int
00069     GetShotAt(int shot, int offset)
00070     {
00071         Quid shotquid = mSegmentation->GetQuidShot(shot);
00072         int r = Column::Find(mShots->GetColumn1(), shotquid, 0, mShots->Size());
00073         int dst = r + offset;
00074         if ((dst < 0) || (dst >= mShots->Size())) {
00075             return -1;
00076         }
00077         return mSegmentation->GetShotId(mShots->Get1(dst));
00078     }
00079 
00080     virtual int
00081     GetShotPosition(int shot)
00082     {
00083         if (shot<0) return -1;
00084         Quid shotquid = mSegmentation->GetQuidShot(shot);
00085         int r = Column::Find(mShots->GetColumn1(), shotquid, 0, mShots->Size());
00086         if (r == mShots->Size())
00087             return -1;
00088         return r;
00089     }
00090 
00091     virtual int
00092     GetType()
00093     {
00094         return SHOTS;
00095     }
00096 
00097 private:
00098 
00099     void
00100     ConvertToTable(std::list<ShotResult> shotlist,
00101                    Core::VideoSet::Segmentation* shots)
00102     {
00103         std::list<ShotResult>::iterator i;
00104         std::map<int,bool> noduplicates;
00105         for (i = shotlist.begin(); i != shotlist.end(); i++)
00106         {
00107             if (i->shotid >= 0 &&
00108                 noduplicates.find(i->shotid) == noduplicates.end())
00109             {
00110                 Quid quid = shots->GetQuidShot(i->shotid);
00111                 mShots->Add(quid, (Real64)i->score);
00112                 noduplicates[i->shotid] = true;
00113             }
00114         }
00115     }
00116 
00117     void
00118     ConvertToTable(std::list<KeyframeResult> keyframelist,
00119                    Core::VideoSet::Segmentation* shots,
00120                    Core::VideoSet::Keyframes* keyframes)
00121     {
00122         std::list<KeyframeResult>::iterator i;
00123         std::map<int,bool> noduplicates;
00124         for (i = keyframelist.begin(); i != keyframelist.end(); i++)
00125         {
00126             if (i->keyframeid < 0)
00127                 continue;
00128 
00129             int shot = keyframes->GetShotId(i->keyframeid);
00130 
00131             if (shot >= 0 &&
00132                 noduplicates.find(shot) == noduplicates.end())
00133             {
00134                 Quid quid = shots->GetQuidShot(shot);
00135                 mShots->Add(quid, (Real64)i->score);
00136                 noduplicates[shot] = true;
00137             }
00138         }
00139     }
00140 
00141     Core::Table::AnnotationTable* mShots;
00142     Core::VideoSet::Segmentation* mSegmentation;
00143 
00144     ILOG_VAR_DEC;
00145 
00146 };
00147 
00148 ILOG_VAR_INIT(ThreadShots, Core.Trec);
00149 
00150 
00151 } // namespace Trec
00152 } // namespace Core
00153 } // namespace Impala
00154 
00155 #endif

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