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

TestVideo.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_VideoSet_TestVideo_h
00002 #define Impala_Core_VideoSet_TestVideo_h
00003 
00004 #include "Basis/ILog.h"
00005 
00006 //#include "Core/Stream/RgbDataSrcFactory.h"
00007 #include "Core/Stream/RgbDataSrc.h"
00008 
00009 namespace Impala 
00010 {
00011 namespace Core 
00012 {
00013 namespace VideoSet 
00014 {
00015 
00016 class TestVideo:public Listener
00017 {
00018     int mLevel;
00019     String mVideoName;
00020     String mSrcType;
00021     Stream::RgbDataSrc* mSrc;
00022     Reporter* mReporter;
00023 
00024 public:
00025 
00026     TestVideo(Reporter* reporter, CmdOptions& options){
00027         mReporter = reporter;
00028         ILOG_INFO("Setting up frame accuracy test!");
00029         mLevel = options.GetInt("tlevel", -1);
00030         mSrcType = options.GetString("src");
00031         mSrc = 0;
00032     };
00033 
00034     ~TestVideo()
00035     {
00036         if (mSrc)
00037             delete mSrc;
00038     }
00039 
00040     void
00041     HandleNewWalk(VideoSet* vs)
00042     {
00043     }
00044 
00045     void
00046     HandleDoneWalk(VideoSet* vs)
00047     {
00048     }
00049 
00050     // Pass in either a ready to use data source, or video set + file id.
00051     void
00052     HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src = 0)
00053     {
00054         if (src)
00055             mSrc = 0;
00056         else
00057         {
00058             src = vs->GetVideo(fileId);
00059             if (src == 0)
00060             {
00061                 FailTest("Could not initialize video");
00062                 return;
00063             }
00064             mSrc = src;
00065         }
00066 
00067         try
00068         {
00069             testFrameAccuracy(src);
00070         }
00071         catch (std::exception& e)
00072         {
00073             ILOG_ERROR("Test failed : " << e.what());
00074         }
00075     }
00076 
00077     void
00078     HandleNewFrame(VideoSet* vs, int fileId, Stream::RgbDataSrc* src = 0)
00079     {
00080     }
00081 
00082     void
00083     HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src = 0)
00084     {
00085         if (mSrc)
00086         {
00087             delete mSrc;
00088             mSrc = 0;
00089         }
00090     }
00091 
00092 private:
00093 
00094     void 
00095     testFrameAccuracy(Stream::RgbDataSrc* src)
00096     {
00097         if (mLevel == -1)
00098         {
00099             testFrameAccuracyLevel0(src);
00100             testFrameAccuracyLevel1(src);
00101             return;
00102         }
00103 
00104         if (mLevel >= 0)
00105             testFrameAccuracyLevel0(src);
00106         if (mLevel >= 1)
00107             testFrameAccuracyLevel1(src);
00108         if (mLevel >= 2)
00109             testFrameAccuracyLevel2(src);
00110         if (mLevel >= 3)
00111             testFrameAccuracyLevel3(src);
00112         if (mLevel >= 4)
00113             testFrameAccuracyLevel4(src);
00114     }
00115     
00116     // Stepping forward through the video, 1 frame at a time (full coverage)
00117     bool 
00118     testFrameAccuracyLevel0(Stream::RgbDataSrc* src)
00119     {
00120         const int level = 0;
00121         ILOG_NDC_PUSH("Level-" << MakeString(level));
00122         ILOG_INFO("Test level " << MakeString(level) << " started");
00123         const int lastFrameNr = src->LastFrame();
00124         for (int f = 0; f <= lastFrameNr; f++)
00125         {
00126             if (f > 0)
00127                 ILOG_DEBUG("Going 1 forward");
00128 
00129             if (!testFrameAccuracyBase(src, f, level))
00130             {
00131                 ILOG_NDC_POP;
00132                 return false;
00133             }
00134         }
00135         ILOG_NDC_POP;
00136         return true;
00137     }
00138     
00139     // Stepping backward through the video, 1 frame at a time (full coverage)
00140     bool 
00141     testFrameAccuracyLevel1(Stream::RgbDataSrc* src)
00142     {
00143         const int level = 1;
00144         ILOG_NDC_PUSH("Level-" << MakeString(level));
00145         ILOG_INFO("Test level " << MakeString(level) << " started");
00146         const int lastFrameNr = src->LastFrame();
00147         for (int f = lastFrameNr; f >= 0; f--)
00148         {   
00149             if (f < lastFrameNr)
00150                 ILOG_DEBUG("Going 1 backward");
00151 
00152             if (!testFrameAccuracyBase(src, f, level))
00153             {
00154                 ILOG_NDC_POP;
00155                 return false;
00156             }
00157         }
00158         ILOG_NDC_POP;
00159         return true;
00160     }
00161     
00162     // Stepping forward through the video (no full coverage)
00163     bool 
00164     testFrameAccuracyLevel2(Stream::RgbDataSrc* src)
00165     {
00166         const int level = 2;
00167         ILOG_NDC_PUSH("Level-" << MakeString(level));
00168         ILOG_INFO("Test level " << MakeString(level) << " started");
00169         const int lastFrameNr = src->LastFrame();
00170         int stepSize = Max(2, Max(lastFrameNr / 100, src->GopSize()));
00171         for (int f = 0; f <= lastFrameNr; f += stepSize)
00172         {
00173             if (f > 0)
00174                 ILOG_DEBUG("Going " << stepSize << " forwards");
00175 
00176             if (!testFrameAccuracyBase(src, f, level))
00177             {
00178                 ILOG_NDC_POP;
00179                 return false;
00180             }
00181         }
00182         ILOG_NDC_POP;
00183         return true;
00184     }
00185 
00186     // Stepping back through the video (no full coverage)
00187     bool 
00188     testFrameAccuracyLevel3(Stream::RgbDataSrc* src)
00189     {
00190         const int level = 3;
00191         ILOG_NDC_PUSH("Level-" << MakeString(level));
00192         ILOG_INFO("Test level " << MakeString(level) << " started");
00193         const int lastFrameNr = src->LastFrame();
00194         int stepSize = Max(2, Max(lastFrameNr / 100, src->GopSize()));
00195         for (int f = lastFrameNr; f >= 0; f -= stepSize)
00196         {
00197             if (f < lastFrameNr)
00198                 ILOG_DEBUG("Going " << stepSize << " backwards");
00199 
00200             if (!testFrameAccuracyBase(src, f, level))
00201             {
00202                 ILOG_NDC_POP;
00203                 return false;
00204             }
00205         }
00206         ILOG_NDC_POP;
00207         return true;
00208     }
00209 
00210     // Jumping randomly through the video (no full coverage)
00211     bool 
00212     testFrameAccuracyLevel4(Stream::RgbDataSrc* src)
00213     {
00214         const int level = 4;
00215         ILOG_NDC_PUSH("Level-" << MakeString(level));
00216         ILOG_INFO("Test level " << MakeString(level) << " started");
00217 
00218         //SK: video v Jun
00219         testFrameAccuracyBase(src, 529, level);
00220         testFrameAccuracyBase(src, 530, level);
00221         testFrameAccuracyBase(src, 531, level);
00222 
00223         // SK: target selection algorithm by Taylan
00224         int targets[100];
00225         srand ( time(NULL) );
00226         targets[0] = 1;
00227         targets[1] = 11;
00228         targets[2] = 32;
00229         const int lastFrameNr = src->LastFrame();
00230         for (int i = 3; i < 98; i++)
00231         {
00232             targets[i] = (lastFrameNr - 5) * ( (1.0 * rand()) / RAND_MAX);
00233         }
00234         targets[98] = lastFrameNr - 5;
00235         targets[99] = 0;
00236 
00237         for (int i = 0; i < 100; i++)
00238         {
00239             ILOG_DEBUG("Going to " << targets[i]);
00240             if (!testFrameAccuracyBase(src, targets[i], level))
00241             {
00242                 ILOG_NDC_POP;
00243                 return false;
00244             }
00245         }
00246         ILOG_NDC_POP;
00247         return true;
00248     }
00249     
00250     bool 
00251     testFrameAccuracyBase(Stream::RgbDataSrc* src, int targetFrame, int testLevel)
00252     {
00253         src->GotoFrame(targetFrame);
00254             ILOG_DEBUG("Current frame is " << src->FrameNr());
00255 
00256         if (!src->IsFrameAccurate())
00257         {
00258             String errFrame = MakeString(src->FrameNr());
00259             String level = MakeString(testLevel);
00260             FailTest("Frame accuracy level " + level + " at frame: " + errFrame);
00261             return false;
00262         }
00263 
00264         return true;
00265     }
00266 
00267     void 
00268     FailTest(String msg)
00269     {
00270         ILOG_ERROR("Test failed: " << msg);
00271     }
00272 
00273     ILOG_VAR_DECL;
00274 };
00275 
00276 ILOG_VAR_INIT(TestVideo, Impala.Core.VideoSet);
00277 // Registers the fixture into the CppUnit tests repository
00278 
00279 }}}//namespace Impala.Core.VideoSet
00280 
00281 
00282 #endif
00283 

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