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

mainTrecResult.cpp

Go to the documentation of this file.
00001 #include "Core/Trec/SearchResult.h"
00002 #include "Core/Trec/SearchJudge.h"
00003 #include "Basis/CmdOptions.h"
00004 #include "Basis/Timer.h"
00005 #include "Visualization/ImageStrip.h"
00006 #include "OglGui/StringSelector.h"
00007 #include "OglGui/TextArea.h"
00008 #include "OglGui/Button.h"
00009 #include "Core/ImageSet/MakeImageSet.h"
00010 #include "Core/VideoSet/MakeVideoSet.h"
00011 #include "Core/VideoSet/Segmentation.h"
00012 #include "Core/VideoSet/Keyframes.h"
00013 #include "Core/VideoSet/PlayShot.h"
00014 
00015 
00016 // since we are not using libraries:
00017 #include "OglGui/OglLib.cpp"
00018 #include "Link/ImpalaLib.cpp"
00019 
00020 namespace Impala
00021 {
00022 namespace Application
00023 {
00024 
00025 
00026 using namespace Visualization;
00027 
00028 class WindowTrecResult : public Window, public OglGui::StringListener,
00029                          public OglGui::ButtonListener
00030 {
00031 public:
00032 
00033     WindowTrecResult(int width, int height) :
00034         Window(0, 0, width, height, true)
00035     {
00036         CmdOptions& options = CmdOptions::GetInstance();
00037         mViewScale = 1.0;
00038 
00039         ReadData();
00040         mSearchResult.Load(options.GetArg(0));
00041         mSearchResult.Judge(mJudge);
00042         BuildGUI(width, height);
00043         SetActiveShot(0);
00044 
00045         AppController::Instance().MainLoop();
00046     }
00047 
00048     void
00049     SetActiveShot(int idx)
00050     {
00051         mResultWnd->SetCurrentString(idx);
00052         std::string shotName = mSearchResult.GetShot(idx);
00053         mCurShotId = mShots->GetShotId(shotName);
00054         mCurVidId = mShots->GetVideoId(mCurShotId);
00055         mImageStrip->RemoveImages();
00056         int nrKey = mKeyframes->GetNrKeyframesShot(mCurShotId);
00057         int firstKey = mKeyframes->GetFirstKeyframeShot(mCurShotId);
00058         for (int i=0 ; i<nrKey ; i++)
00059         {
00060             std::string imName = mKeyframes->GetName(firstKey + i);
00061             Core::Array::Array2dVec3UInt8* im = mImSetThumb->GetImage(firstKey + i);
00062             mImageStrip->AddImage(im, std::string("Direct"), imName, false);
00063         }
00064     }
00065 
00066     // specialization of base classes
00067 
00068     virtual void
00069     StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00070                          void* listenerData)
00071     {
00072         SetActiveShot(strIndex);
00073     }
00074 
00075     virtual void
00076     ButtonSelectionEvent(OglGui::Button* src, void* listenerData)
00077     {
00078         if (mCurShotId != -1)
00079             Core::VideoSet::PlayShot(mShots, mCurShotId);
00080     }
00081 
00082 private:
00083 
00084     void
00085     ReadData()
00086     {
00087         CmdOptions& options = CmdOptions::GetInstance();
00088         std::string videoSetName = options.GetString("videoSet");
00089         Timer timer(1);
00090 
00091         std::cout << "Reading thumbnails" << std::endl;
00092         mImSetThumb =
00093             Core::ImageSet::MakeImageSet(options.GetString("imageSetThumbnails"));
00094         if (mImSetThumb)
00095         {
00096             mImSetThumb->SetImageSrc(! options.GetBool("noArchive"),
00097                                      options.GetBool("imFileArchive"),
00098                                      options.GetBool("imSplitArchive"));
00099             Core::Array::Array2dVec3UInt8* im = mImSetThumb->GetImage(0);
00100             mThumbWidth = im->CW();
00101             mThumbHeight = im->CH();
00102             delete im;
00103         }
00104         std::cout << "time: " << timer.SplitTime() << std::endl;
00105 
00106         std::cout << "Reading video set" << std::endl;
00107         timer.Start();
00108         mVidSet = Core::VideoSet::MakeVideoSet(videoSetName);
00109         std::cout << "time: " << timer.SplitTime() << std::endl;
00110 
00111         std::cout << "Reading shots" << std::endl;
00112         timer.Start();
00113         mShots = new Core::VideoSet::Segmentation(mVidSet, "segmentation");;
00114         std::cout << "time: " << timer.SplitTime() << std::endl;
00115 
00116         std::cout << "Reading keyframe set" << std::endl;
00117         timer.Start();
00118         mKeyframes = new Core::VideoSet::Keyframes(mVidSet, "keyframes");
00119         std::cout << "time: " << timer.SplitTime() << std::endl;
00120 
00121         std::string judgeFile = options.GetString("judgeFile");
00122         mJudge = new Core::Trec::SearchJudge(judgeFile);
00123         mJudge->Stats();
00124     }
00125 
00126     void
00127     BuildGUI(int wndWidth, int wndHeight)
00128     {
00129         SetBackground(0xffd2c799);
00130         mImageStrip = new ImageStrip(this, mThumbWidth, mThumbHeight,
00131                                      mViewScale, 5);
00132         mResultWnd = new OglGui::StringSelector(this, 400, 20*20);
00133         mResultWnd->SetStringListener(this);
00134         double ap = mSearchResult.GetAveragePrecision();
00135         std::string apString = std::string("ap = ") + MakeString(ap);
00136         mApText = new OglGui::TextArea(this, 100, 1*20, apString);
00137         mPlayBut = new OglGui::Button(this, 100, 20, "play");
00138         mPlayBut->SetButtonListener(this);
00139 
00140         for (int i=0 ; i<mSearchResult.NrElements() ; i++)
00141             mResultWnd->AddString(mSearchResult.Describe(i));
00142     }
00143 
00144     double                   mViewScale;
00145     Core::Trec::SearchResult mSearchResult;
00146     int                      mCurShotId;
00147     int                      mCurVidId;
00148 
00149     Core::ImageSet::ImageSet*     mImSetThumb;
00150     Core::VideoSet::VideoSet*     mVidSet;
00151     Core::VideoSet::Segmentation* mShots;
00152     Core::VideoSet::Keyframes*    mKeyframes;
00153     Core::Trec::SearchJudge*      mJudge;
00154 
00155     int mThumbWidth;
00156     int mThumbHeight;
00157 
00158     ImageStrip*             mImageStrip;
00159     OglGui::StringSelector* mResultWnd;
00160     OglGui::TextArea*       mApText;
00161     OglGui::Button*         mPlayBut;
00162 
00163 };
00164 
00165 int
00166 mainTrecResult(int argc, char* argv[])
00167 {
00168     CmdOptions& options = CmdOptions::GetInstance();
00169     options.Initialise(true, false, true);
00170     options.SetDefault("wndWidth", "950");
00171     options.SetDefault("wndHeight", "580");
00172     if (! options.ParseArgs(argc, argv, "topic_result.xml", 1))
00173         return 1;
00174 
00175     int reqWndWidth = options.GetInt("wndWidth");
00176     int reqWndHeight = options.GetInt("wndHeight");
00177     WindowTrecResult* oglWnd = new WindowTrecResult(reqWndWidth, reqWndHeight);
00178     if (! oglWnd->Valid())
00179     {
00180         std::cout << "WindowTrecResult failed" << std::endl;
00181         return 0;
00182     }
00183     return 1;
00184 }
00185 
00186 } // namespace Application
00187 } // namespace Impala
00188 
00189 int
00190 main(int argc, char* argv[])
00191 {
00192     return Impala::Application::mainTrecResult(argc, argv);
00193 }

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