00001 #include "Basis/CmdOptions.h"
00002 #include "Core/Stream/RgbDataSrcFactory.h"
00003 #include "Core/Array/MakeFromData.h"
00004 #include "Core/Array/RGB2Intensity.h"
00005 #include "Core/Array/GetRgbPixels.h"
00006 #include "Core/Array/Trait/BpoEqual.h"
00007 #include "Visualization/VideoNav.h"
00008 #include "Visualization/ImageStrip.h"
00009 #include "Core/Array/Pattern/PatBinaryPixOp.h"
00010 #include "Core/Array/Trait/BpoTestEqual.h"
00011 #include "Visualization/AppControlSrc.h"
00012
00013
00014 #include "OglGui/OglLib.cpp"
00015 #include "Link/ImpalaLib.cpp"
00016
00017 namespace Impala
00018 {
00019 namespace Application
00020 {
00021
00022
00023 using namespace Visualization;
00024 using namespace Core::Array;
00025 using namespace Core::Stream;
00026
00027 class WindowVdiff : public Window, public AppControlSrc,
00028 public VideoNavListener, public ImagesListener
00029 {
00030 public:
00031
00032 WindowVdiff(RgbDataSrc* src1, RgbDataSrc* src2) :
00033 Window(100, 0, SuggestWndWidth(2, src1->FrameWidth() + 2),
00034 SuggestWndHeight(1.5, src1->FrameHeight()) + 75, true),
00035 AppControlSrc(10)
00036 {
00037 CmdOptions& options = CmdOptions::GetInstance();
00038 SetSrc(src1, -1, src2);
00039 AppController::Instance().AddControl((AppControlSrc*) this, true);
00040
00041 mViewScale = options.GetDouble("viewScale");
00042 mDiffBuf = "";
00043 mVideoNav1 = new VideoNav(this, GetSrc(), mViewScale, false);
00044 mVideoNav1->SetVideoNavListener(this);
00045 mVideoNav2 = new VideoNav(this, GetSrc2(), mViewScale);
00046 mVideoNav2->SetVideoNavListener(this);
00047 mDiffWnd = new ImageStrip(this, src1->FrameWidth(), src1->FrameHeight(),
00048 0.5 * mViewScale, 3);
00049 mDiffWnd->SetImagesListener(this);
00050 AppController::Instance().MainLoop();
00051 }
00052
00053 void
00054 DoProcessing()
00055 {
00056 if ((!GetSrc()->DataPtr() || !GetSrc2()->DataPtr()) ||
00057 (GetSrc()->FrameWidth() != GetSrc2()->FrameWidth()) ||
00058 (GetSrc()->FrameHeight() != GetSrc2()->FrameHeight()))
00059 {
00060 return;
00061 }
00062
00063 bool verbose = false;
00064 ArraySystem& aSys = ArraySystem::Instance();
00065 aSys.MarkMemoryUsage(verbose);
00066
00067 Array2dVec3UInt8* wrap1 = ArrayCreate<Array2dVec3UInt8>
00068 (GetSrc()->FrameWidth(), GetSrc()->FrameHeight(), 0, 0,
00069 GetSrc()->DataPtr(), true);
00070 Array2dVec3UInt8* wrap2 = ArrayCreate<Array2dVec3UInt8>
00071 (GetSrc2()->FrameWidth(), GetSrc2()->FrameHeight(), 0, 0,
00072 GetSrc2()->DataPtr(), true);
00073
00074 double eps = 0.00001;
00075 Trait::BpoTestEqual
00076 <Array2dScalarReal64, Array2dVec3UInt8, Array2dVec3UInt8> bpo(eps);
00077 Array2dScalarReal64* res = 0;
00078 Pattern::PatBinaryPixOp(res, wrap1, wrap2, bpo);
00079
00080 mDiffBuf = "";
00081 std::ostringstream diffStream;
00082 if (bpo.mNrDiff > 0)
00083 {
00084 diffStream << ", found " << bpo.mNrDiff << " differences, in "
00085 << bpo.mNr << " pixels, sum diffs : " << bpo.mSumDiff
00086 << " avg diff : " << bpo.mSumDiff / bpo.mNrDiff
00087 << " avg src1 : " << bpo.mSumSrc1 / bpo.mNr
00088 << " avg src2 : " << bpo.mSumSrc2 / bpo.mNr << std::ends;
00089 }
00090 else
00091 {
00092 diffStream << ", frames are equal" << std::ends;
00093 }
00094 mDiffBuf = diffStream.str();
00095
00096 mDiffWnd->RemoveImages();
00097 mDiffWnd->AddImage(res, "Stretch", "", false);
00098
00099 delete wrap1;
00100 delete wrap2;
00101 delete res;
00102 aSys.CheckMemoryUsageSinceMark(verbose);
00103 if (verbose)
00104 std::cout << std::endl;
00105 }
00106
00107
00108
00109 void
00110 HandleCycleSrc()
00111 {
00112 mOglWnd->updateScene = 1;
00113 SetStatusStr((char*) GetFpsString().c_str());
00114 }
00115
00116 void
00117 HandleNewFrame()
00118 {
00119 mVideoNav1->UpdateView(0, GetSrc()->DataPtr(), GetSrc()->FrameWidth(),
00120 GetSrc()->FrameHeight(), mViewScale);
00121 mVideoNav2->UpdateView(0, GetSrc2()->DataPtr(), GetSrc2()->FrameWidth(),
00122 GetSrc2()->FrameHeight(), mViewScale);
00123 DoProcessing();
00124 }
00125
00126 void
00127 NavFrameEvent(VideoNav* src, int requestedFrame, void* listenerData)
00128 {
00129 Jump(requestedFrame);
00130 }
00131
00132 private:
00133
00134 double mViewScale;
00135 String mDiffBuf;
00136 VideoNav* mVideoNav1;
00137 VideoNav* mVideoNav2;
00138 ImageStrip* mDiffWnd;
00139
00140 };
00141
00142 int
00143 mainVdiff(int argc, char* argv[])
00144 {
00145 CmdOptions& options = CmdOptions::GetInstance();
00146 options.Initialise(true, true, true);
00147 options.AddOption(0, "src2", "type", "", "dx|avi|mpeg2|mpeg2es");
00148 if (! options.ParseArgs(argc, argv, "filename1 filename2", 2))
00149 return 1;
00150
00151 ILOG_VAR(Application.mainVdiff);
00152
00153 String srcName1 = options.GetArg(0);
00154 String srcName2 = options.GetArg(1);
00155
00156 RgbDataSrcFactory& factory = RgbDataSrcFactory::Instance();
00157 RgbDataSrc* src1 = factory.Construct(srcName1, options.GetString("src"));
00158 if (! src1->Valid())
00159 {
00160 ILOG_ERROR("RgbDataSrc failed");
00161 return 0;
00162 }
00163 ILOG_INFO("src1: " << src1->LastFrame()+1 << " frames of "
00164 << src1->FrameWidth() << " x " << src1->FrameHeight());
00165
00166 RgbDataSrc* src2 = factory.Construct(srcName2, options.GetString("src2"));
00167 if (! src2->Valid())
00168 {
00169 ILOG_ERROR("RgbDataSrc failed");
00170 return 0;
00171 }
00172 ILOG_INFO("src2: " << src2->LastFrame()+1 << " frames of "
00173 << src2->FrameWidth() << " x " << src2->FrameHeight());
00174
00175 WindowVdiff* oglWnd = new WindowVdiff(src1, src2);
00176 if (! oglWnd->Valid())
00177 {
00178 ILOG_ERROR("WindowVdiff failed");
00179 return 0;
00180 }
00181 return 1;
00182 }
00183
00184 }
00185 }
00186
00187 int
00188 main(int argc, char* argv[])
00189 {
00190 return Impala::Application::mainVdiff(argc, argv);
00191 }