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

mainVideo.cpp

Go to the documentation of this file.
00001 #include "Visualization/Window.h"
00002 #include "Basis/Timer.h"
00003 #include "Core/Stream/RgbDataSrcFactory.h"
00004 #include "Core/Stream/RgbDataDstFactory.h"
00005 #include "Core/Array/Rotate.h"
00006 #include "Core/Array/WriteRaw.h"
00007 
00008 // since we are not using libraries:
00009 #include "OglGui/OglLib.cpp"
00010 #include "Link/ImpalaLib.cpp"
00011 
00012 namespace Impala
00013 {
00014 namespace Application
00015 {
00016 namespace Video
00017 {
00018 
00019 
00020 using namespace Impala::Util;
00021 using namespace Impala::Core::Array;
00022 using namespace Impala::Core::Stream;
00023 
00024 // command line parameters
00025 int  gVerbose;
00026 int  gStepSize;
00027 bool gRotateLeft;
00028 bool gRotateRight;
00029 int  gGopSize;
00030 bool gDoRandom;
00031 bool gDoLoop;
00032 int  gNrFrames;
00033 
00034 char gStatusBuf[256];
00035 int  gFramesDone = 0;
00036 
00037 RgbDataSrc* gSrc = 0;
00038 RgbDataDst* gDst = 0;
00039 int         gDstWidth;
00040 int         gDstHeight;
00041 Timer       gTimer(1);
00042 
00043 
00044 void
00045 FpsReset()
00046 {
00047     gTimer.Start();
00048     gFramesDone = 0;
00049 }
00050 
00051 void
00052 UpdateStatusBuf()
00053 {
00054     double timeVal = gTimer.SplitTime();
00055     double fps = (double) gFramesDone / timeVal;
00056     std::ostrstream statusStream;
00057     statusStream << "FrameNr = " << gSrc->FrameNr() << ", did "
00058                  << gFramesDone << " frames in " << timeVal << " sec = "
00059                  << fps << " fps" << std::ends;
00060     strcpy(gStatusBuf, statusStream.str());
00061     statusStream.freeze(false);
00062 }
00063 
00064 int
00065 DemoVideo()
00066 {
00067     int done = 0;
00068     Array2dVec3UInt8* rotIm = 0;
00069     gTimer.Start();
00070     while (!done)
00071     {
00072         if (gDoRandom)
00073         {
00074             int maxFrame = (gSrc->LastFrame()/gGopSize)*gGopSize;
00075             int rFrame = rand()*maxFrame/RAND_MAX;
00076             gSrc->GotoFrame(rFrame);
00077         }
00078         else
00079         {
00080             gSrc->NextFrame(gStepSize);
00081         }
00082 
00083         if (! gSrc->DataPtr())
00084         {
00085             std::cout << "skipping empty frame" << std::endl;
00086             continue;
00087         }
00088         if (gRotateLeft || gRotateRight)
00089         {
00090             int degrees = (gRotateLeft) ? 90 : -90;
00091             Array2dVec3UInt8* wrap = new Array2dVec3UInt8(gSrc->FrameWidth(),
00092                                                           gSrc->FrameHeight(),
00093                                                           0, 0, gSrc->DataPtr(),
00094                                                           true);
00095             Rotate(rotIm, wrap, degrees, Core::Geometry::NEAREST, true, 0);
00096             gDst->NextFrame(rotIm->CPB());
00097             delete wrap;
00098         }
00099         else
00100         {
00101             gDst->NextFrame(gSrc->DataPtr());
00102         }
00103         gFramesDone++;
00104         if ((gVerbose > 0) && (gFramesDone % gVerbose == 0))
00105         {
00106             UpdateStatusBuf();
00107             std::cout << gStatusBuf << std::endl;
00108         }
00109 
00110         UpdateStatusBuf();
00111         done = gDst->WindowManage(done, gStatusBuf);
00112         if (gSrc->TheEnd())
00113         {
00114             if (gDoLoop)
00115             {
00116                 gSrc->Reset();
00117                 FpsReset();
00118             }
00119             else
00120             {
00121                 done = 1;
00122                 gDst->Close();
00123             }
00124         }
00125         if ((gNrFrames != -1) && (gFramesDone > gNrFrames))
00126         {
00127             done = 1;
00128             gDst->Close();
00129         }
00130     }
00131     if (rotIm)
00132         delete rotIm;
00133     return 0;
00134 }
00135 
00136 int
00137 mainVideo(int argc, char* argv[])
00138 {
00139     CmdOptions& options = CmdOptions::GetInstance();
00140     options.Initialise(true);
00141     options.AddOption(0, "rotateLeft", "", "0");
00142     options.AddOption(0, "rotateRight", "", "0");
00143     options.AddOption(0, "gop", "nr", "15");
00144     options.AddOption(0, "random", "", "0");
00145     options.AddOption(0, "dstDX", "", "0");
00146     if (! options.ParseArgs(argc, argv, "camera|filename ogl|win|filename", 2))
00147         return 1;
00148 
00149     gVerbose = options.GetInt("verb");
00150     gStepSize = options.GetInt("stepSize");
00151     gRotateLeft = options.GetBool("rotateLeft");
00152     gRotateRight = options.GetBool("rotateRight");
00153     gGopSize = options.GetInt("gop");
00154     gDoRandom = options.GetBool("random");
00155     gDoLoop = options.GetBool("loop");
00156     gNrFrames = options.GetInt("numberFrames");
00157 
00158     std::string srcName = options.GetArg(0);
00159     RgbDataSrcFactory& factory = RgbDataSrcFactory::Instance();
00160     gSrc = factory.Construct(srcName, options.GetString("src"));
00161     if (! gSrc->Valid())
00162     {
00163         std::cout << "RgbDataSrc failed" << std::endl;
00164         return 0;
00165     }
00166     if (gVerbose)
00167         std::cout << gSrc->LastFrame()+1 << " frames of " << gSrc->FrameWidth() 
00168                   << " x " << gSrc->FrameHeight() << std::endl;
00169 
00170     std::string dstName = options.GetArg(1);
00171     int theDataDst = RgbDataDstFactory::DST_OGL;
00172     if (dstName == "ogl")
00173         theDataDst = RgbDataDstFactory::DST_OGL;
00174     else if (dstName == "win")
00175         theDataDst = RgbDataDstFactory::DST_WIN;
00176     else theDataDst = RgbDataDstFactory::DST_AVI;
00177     if (options.GetBool("dstDX"))
00178         theDataDst = RgbDataDstFactory::DST_DX;
00179 
00180     gDstWidth = gSrc->FrameWidth();
00181     gDstHeight = gSrc->FrameHeight();
00182     if (gRotateLeft || gRotateRight)
00183     {
00184         gDstWidth = gSrc->FrameHeight();
00185         gDstHeight = gSrc->FrameWidth();
00186     }
00187     RgbDataDstFactory& fac = RgbDataDstFactory::Instance();
00188     gDst = fac.Construct(theDataDst, dstName, gDstWidth, gDstHeight);
00189 
00190     if (! gDst->Valid())
00191     {
00192         std::cout << "RgbDataDst failed" << std::endl;
00193         return 0;
00194     }
00195     gDst->WindowManage(0, 0);
00196 
00197     return DemoVideo();
00198 }
00199 
00200 } // namespace Video
00201 } // namespace Application
00202 } // namespace Impala
00203 
00204 int
00205 main(int argc, char* argv[])
00206 {
00207     return Impala::Application::Video::mainVideo(argc, argv);
00208 }

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