00001 #ifndef Impala_Core_VideoSet_ShotSegmenterGUI_h
00002 #define Impala_Core_VideoSet_ShotSegmenterGUI_h
00003
00004 #include "Basis/CmdOptions.h"
00005 #include "OglGui/Strut.h"
00006 #include "Core/Geometry/Rectangle.h"
00007 #include "Core/Geometry/RectanglePyramid.h"
00008 #include "Core/Stream/RgbDataSrc.h"
00009 #include "Core/Stream/RgbDataSrcFactory.h"
00010 #include "Visualization/VideoNav.h"
00011 #include "Visualization/AppControlSrc.h"
00012
00013 #include "Visualization/Plot/Plot.h"
00014 #include "Visualization/Plot/Line.h"
00015 #include "Core/Vector/VectorTem.h"
00016 #include "Core/Array/MulVal.h"
00017 #include "Core/Array/PrintData.h"
00018 #include "Core/Array/MakeFrom3Images.h"
00019 #include "Core/Array/GaussDerivative2d.h"
00020 #include "Core/VideoSet/ShotSegmenter.h"
00021 #undef Next
00022
00023
00024
00025 namespace Impala
00026 {
00027 namespace Core
00028 {
00029 namespace VideoSet
00030 {
00031
00032 using namespace Util;
00033 using namespace Visualization;
00034 using namespace Core::Array;
00035 using namespace Core::Vector;
00036 using namespace Core::Stream;
00037 using namespace Core::Histogram;
00038 using namespace Core::Geometry;
00039
00040 class ShotSegmenterGUI : public Window, public AppControlSrc,
00041 public VideoNavListener, public OglGui::ViewListener
00042 {
00043 public:
00044
00045 ShotSegmenterGUI(int x, int y, bool doZoom, bool mainIs2d, bool vpIs2d,
00046 RgbDataSrc* src) :
00047 Window(x, y, SuggestWndWidth(1, 2*src->FrameWidth()+src->FrameHeight()) + 30,
00048 SuggestWndHeight(1, 2*src->FrameHeight())+30, mainIs2d),
00049 AppControlSrc(1)
00050 {
00051
00052 CmdOptions& options = CmdOptions::GetInstance();
00053 mBlurSigma = options.GetDouble("SSBlurSigma");
00054 mBlurDer = options.GetInt("SSBlurDer");
00055 mShotSeg = new ShotSegmenter(0,options);
00056 mShotSeg->HandleNewFile(0,0,src);
00057
00058
00059 SetSource(src);
00060
00061
00062 mVideoDecision = new VideoNav(this,mPredictSrc);
00063 mVideoDecision->SetVideoNavListener(this);
00064
00065 new OglGui::Strut(this,src->FrameHeight()+5,1);
00066
00067 mVideoProcess = new VideoNav(this, src);
00068 mVideoProcess->SetVideoNavListener(this);
00069
00070
00071 int WindowWidth=W()-10;
00072 int HalfWindowWidth=WindowWidth/2;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 mScoresPlot = new Plot::Plot(this, 5, 30,
00088 W()-10,src->FrameHeight()-30);
00089 mScoresPlot->SetDisableGlobalKeyListener(false);
00090 mScoresPlot->SetDisableOGLViewKeys(false);
00091
00092 mScoresPlottable = new Plot::Line(0, true);
00093 mProbsPlottable = new Plot::Line(0, true);
00094 mCUTPlottable = new Plot::Line(0, true);
00095 mDISPlottable = new Plot::Line(0, true);
00096 mOTHPlottable = new Plot::Line(0, true);
00097 mFOIPlottable = new Plot::Line(0, true);
00098 mProcessRange = new Plot::Line(0, true);
00099 mDecisionRange = new Plot::Line(0, true);
00100
00101 mPlotScale1 = new Plot::Line(0, true);
00102 mPlotScale2 = new Plot::Line(0, true);
00103 mPlotScale3 = new Plot::Line(0, true);
00104 mPlotScale4 = new Plot::Line(0, true);
00105 mPlotScale5 = new Plot::Line(0, true);
00106
00107 mDecisionBoundaryPlottable = new Plot::Line(0, true);
00108
00109 mScoresPlot->Add(mPlotScale1);
00110 mScoresPlot->Add(mPlotScale2);
00111 mScoresPlot->Add(mPlotScale3);
00112 mScoresPlot->Add(mPlotScale4);
00113 mScoresPlot->Add(mPlotScale5);
00114 mScoresPlot->Add(mProcessRange);
00115 mScoresPlot->Add(mDecisionRange);
00116 mScoresPlot->Add(mScoresPlottable);
00117 mScoresPlot->Add(mProbsPlottable);
00118 mScoresPlot->Add(mCUTPlottable);
00119 mScoresPlot->Add(mDISPlottable);
00120 mScoresPlot->Add(mOTHPlottable);
00121 mScoresPlot->Add(mFOIPlottable);
00122
00123 mScoresPlot->Add(mDecisionBoundaryPlottable);
00124 mScoresPlot->SetBackground(0xff000000);
00125
00126 mScoresPlottable->SetDomain(0,src->LastFrame());
00127 mProbsPlottable->SetDomain(0,src->LastFrame());
00128 mCUTPlottable->SetDomain(0,src->LastFrame());
00129 mDISPlottable->SetDomain(0,src->LastFrame());
00130 mOTHPlottable->SetDomain(0,src->LastFrame());
00131 mFOIPlottable->SetDomain(0,src->LastFrame());
00132 mProcessRange->SetDomain(0,src->LastFrame());
00133 mDecisionRange->SetDomain(0,src->LastFrame());
00134 mPlotScale1->SetDomain(0,src->LastFrame());
00135 mPlotScale2->SetDomain(0,src->LastFrame());
00136 mPlotScale3->SetDomain(0,src->LastFrame());
00137 mPlotScale4->SetDomain(0,src->LastFrame());
00138 mPlotScale5->SetDomain(0,src->LastFrame());
00139 mDecisionBoundaryPlottable->SetDomain(0,src->LastFrame());
00140
00141 mScoresPlottable->SetColor(1,0,0);
00142 mProbsPlottable->SetColor(1,1,0);
00143 mCUTPlottable->SetColor(1,0.5,0);
00144 mDISPlottable->SetColor(0,1,0.5);
00145 mOTHPlottable->SetColor(0,0.5,1);
00146 mFOIPlottable->SetColor(0.5,0,1);
00147
00148 mPlotScale1->SetColor(0.4,0.4,0.4);
00149 mPlotScale2->SetColor(0.4,0.4,0.4);
00150 mPlotScale3->SetColor(0.4,0.4,0.4);
00151 mPlotScale4->SetColor(0.4,0.4,0.4);
00152 mPlotScale5->SetColor(0.4,0.4,0.4);
00153
00154 mProcessRange->SetColor(1,1,1);
00155 mDecisionRange->SetColor(1,1,0);
00156
00157 mDecisionBoundaryPlottable->SetColor(0,1,0);
00158
00159 mDecisionBoundary = ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00160 SetVal(mDecisionBoundary,mShotSeg->GetProbThresh());
00161
00162 mWeightsView=new View(mOglWnd,
00163 src->FrameWidth()+10,
00164 this->H()-src->FrameHeight()-3,
00165 src->FrameHeight(),
00166 src->FrameHeight(),1,true,true,true);
00167
00168 mWeights = mShotSeg->GetWeights();
00169
00170 mScoresPlottable->SetData(mShotSeg->GetScores());
00171
00172 mProbsPlottable->SetData(mShotSeg->GetPredictions());
00173 mCUTPlottable->SetData(mShotSeg->GetCUTs());
00174 mDISPlottable->SetData(mShotSeg->GetDISs());
00175 mOTHPlottable->SetData(mShotSeg->GetOTHs());
00176 mFOIPlottable->SetData(mShotSeg->GetFOIs());
00177
00178 mDecisionBoundaryPlottable->SetData(mDecisionBoundary);
00179 Array2dScalarReal64* s1=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00180 Array2dScalarReal64* s2=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00181 Array2dScalarReal64* s3=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00182 Array2dScalarReal64* s4=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00183 Array2dScalarReal64* s5=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00184 mPr=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00185 mDr=ArrayCreate<Array2dScalarReal64>(GetSrc()->LastFrame(),1,0,0);
00186
00187 SetVal(s1,0.25);
00188 SetVal(s2,0.5);
00189 SetVal(s3,1.);
00190 SetVal(s4,2.);
00191 SetVal(s5,4.);
00192 SetVal(mPr,0);
00193 SetVal(mDr,0);
00194
00195 mPlotScale1->SetData(s1);
00196 mPlotScale2->SetData(s2);
00197 mPlotScale3->SetData(s3);
00198 mPlotScale4->SetData(s4);
00199 mPlotScale5->SetData(s5);
00200 mProcessRange->SetData(mPr);
00201 mDecisionRange->SetData(mDr);
00202
00203
00204
00205 #ifdef OGL_USING_GLUT
00206 SetAlwaysDraw();
00207 #endif
00208 AppController::Instance().MainLoop();
00209
00210 }
00211
00212 void SetCUTs(Array2dScalarReal64* CUTS)
00213 {
00214 mCUTPlottable->SetData(CUTS);
00215 }
00216 void SetFOIs(Array2dScalarReal64* FOIS)
00217 {
00218 mFOIPlottable->SetData(FOIS);
00219 }
00220 void SetDISs(Array2dScalarReal64* DISS)
00221 {
00222 mDISPlottable->SetData(DISS);
00223 }
00224 void SetOTHs(Array2dScalarReal64* OTHS)
00225 {
00226 mOTHPlottable->SetData(OTHS);
00227 }
00228 void SetScores(Array2dScalarReal64* Scores)
00229 {
00230 mScoresPlottable->SetData(Scores);
00231 }
00232 void SetPredictions(Array2dScalarReal64* Predictions)
00233 {
00234 mProbsPlottable->SetData(Predictions);
00235 }
00236 void SetWeights(Array2dScalarReal64* Weights)
00237 {
00238 mWeights=Weights;
00239 }
00240 void SetSource(RgbDataSrc* src){
00241 SetSrc(src);
00242 AppController::Instance().AddControl((AppControlSrc*) this, true);
00243
00244 RgbDataSrcFactory& factory = RgbDataSrcFactory::Instance();
00245 mPredictSrc = factory.Construct( src->GetName(),CmdOptions::GetInstance().GetString("src"));
00246 }
00247
00248 void
00249 MainLoop(){
00250 AppController::Instance().MainLoop();
00251 }
00252
00253 void
00254 HandleCycleSrc()
00255 {
00256 UpdateScene();
00257 SetStatusStr((char*) GetFpsString().c_str());
00258 }
00259
00260 void
00261 HandleDestroyEvent()
00262 {
00263
00264 }
00265
00266 void
00267 BlurImage(Array2dVec3UInt8*& rgb,double sigma)
00268 {
00269
00270 Array2dScalarUInt8* R=0;
00271 Array2dScalarUInt8* G=0;
00272 Array2dScalarUInt8* B=0;
00273
00274 ProjectRange(R,rgb,1);
00275 ProjectRange(G,rgb,2);
00276 ProjectRange(B,rgb,3);
00277
00278 Array2dScalarReal64* RReal=0;
00279 Array2dScalarReal64* GReal=0;
00280 Array2dScalarReal64* BReal=0;
00281
00282 Array2dScalarReal64* RRealp=0;
00283 Array2dScalarReal64* GRealp=0;
00284 Array2dScalarReal64* BRealp=0;
00285
00286 Set(RReal,R);
00287 Set(GReal,G);
00288 Set(BReal,B);
00289
00290 RecGauss(RRealp,RReal,sigma,sigma,mBlurDer,mBlurDer,1);
00291 RecGauss(GRealp,GReal,sigma,sigma,mBlurDer,mBlurDer,1);
00292 RecGauss(BRealp,BReal,sigma,sigma,mBlurDer,mBlurDer,1);
00293 if(mBlurDer>0){
00294 Mul(RReal,RReal,RRealp);
00295 Mul(GReal,GReal,GRealp);
00296 Mul(BReal,BReal,BRealp);
00297 DivVal(RReal,RReal,PixMax(RRealp));
00298 DivVal(GReal,GReal,PixMax(GRealp));
00299 DivVal(BReal,BReal,PixMax(BRealp));
00300 RecGauss(RRealp,RReal,sigma,sigma,0,0,1);
00301 RecGauss(GRealp,GReal,sigma,sigma,0,0,1);
00302 RecGauss(BRealp,BReal,sigma,sigma,0,0,1);
00303 }
00304
00305 delete rgb;
00306 delete R;
00307 delete G;
00308 delete B;
00309
00310 R=G=B=0;
00311 rgb=0;
00312
00313 Set(R,RRealp);
00314 Set(G,GRealp);
00315 Set(B,BRealp);
00316
00317 MakeFrom3Images(rgb,R,G,B);
00318
00319 delete R;delete G;delete B;
00320 delete RReal;delete GReal;delete BReal;
00321 delete RRealp;delete GRealp;delete BRealp;
00322
00323 }
00324
00325 void
00326 HandleNewFrame()
00327 {
00328 int ProcessFrame = GetSrc()->FrameNr();
00329 int PredictionFrame = mShotSeg->GetPredictionFrame();
00330 mPredictSrc->GotoFrame(PredictionFrame+1);
00331 mPr->SetValue(0,ProcessFrame-1,0);
00332 mPr->SetValue(0.5,ProcessFrame,0);
00333 mDr->SetValue(0,PredictionFrame-1,0);
00334 mDr->SetValue(0.5,PredictionFrame,0);
00335
00336 mShotSeg->HandleNewFrame();
00337
00338 ArraySystem::Instance().MarkMemoryUsage();
00339 Array2dVec3UInt8* rgb1 = Array::ArrayCreate<Array2dVec3UInt8>
00340 (GetSrc()->FrameWidth(), GetSrc()->FrameHeight(),
00341 0, 0,mPredictSrc->DataPtr(),true);
00342 if(mShotSeg->Blur())
00343 BlurImage(rgb1,mBlurSigma);
00344 Array2dVec3UInt8* rgb2 = Array::ArrayCreate<Array2dVec3UInt8>
00345 (GetSrc()->FrameWidth(), GetSrc()->FrameHeight(),
00346 0, 0,GetSrc()->DataPtr(),true);
00347 if(mShotSeg->Blur())
00348 BlurImage(rgb2,mBlurSigma);
00349
00350 mVideoDecision->UpdateView(0,rgb1,"");
00351 mVideoProcess->UpdateView(0,rgb2,"");
00352 delete rgb1;
00353 delete rgb2;
00354
00355
00356 MulVal(mWeights,mWeights,255/PixMax(mWeights));
00357
00358 mScoresPlot->SetCenter(ProcessFrame-50,2,0);
00359 mScoresPlot->SetRange(100,5,1);
00360
00361 mWeightsView->UpdateImage(mWeights,std::string(""));
00362 mWeightsView->SetZoom(mWeightsView->W()/mWeights->CW(),
00363 mWeightsView->H()/mWeights->CH());
00364
00365 }
00366
00367
00368
00369 void
00370 NavFrameEvent(VideoNav* src, int requestedFrame, void* listenerData)
00371 {
00372 Jump(requestedFrame);
00373 }
00374
00375 virtual void
00376 OnViewMouse(OglGui::View* view, int msg, int btn, int state,
00377 float x, float y)
00378 {
00379 }
00380
00381 VideoNav* mVideoDecision;
00382 VideoNav* mVideoProcess;
00383 View* mWeightsView;
00384
00385 Plot::Plot* mHistogramPlot;
00386 Plot::Plot* mHistogramPlotW;
00387 Plot::Line* mHistogramPlottable;
00388 Plot::Line* mHistogramPlottableW;
00389
00390 Plot::Plot* mScoresPlot;
00391 Plot::Line* mScoresPlottable;
00392 Plot::Line* mProbsPlottable;
00393 Plot::Line* mCUTPlottable;
00394 Plot::Line* mDISPlottable;
00395 Plot::Line* mOTHPlottable;
00396 Plot::Line* mFOIPlottable;
00397 Plot::Line* mDecisionBoundaryPlottable;
00398 Plot::Line* mPlotScale1;
00399 Plot::Line* mPlotScale2;
00400 Plot::Line* mPlotScale3;
00401 Plot::Line* mPlotScale4;
00402 Plot::Line* mPlotScale5;
00403 Plot::Line* mProcessRange;
00404 Plot::Line* mDecisionRange;
00405
00406
00407 RgbDataSrc* mPredictSrc;
00408
00409 Array2dScalarReal64* mWeights;
00410 Array2dScalarReal64* mPr;
00411 Array2dScalarReal64* mDr;
00412 Array2dScalarReal64* mDecisionBoundary;
00413
00414 ShotSegmenter* mShotSeg;
00415 double mBlurSigma;
00416 int mBlurDer;
00417
00418 };
00419 }
00420 }
00421 }
00422 #endif