00001 #ifndef Impala_Core_VideoSet_CheckNrFrames_h
00002 #define Impala_Core_VideoSet_CheckNrFrames_h
00003
00004 #include "Core/VideoSet/Reporter.h"
00005 #include "Core/VideoSet/Segmentation.h"
00006
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace VideoSet
00012 {
00013
00014
00015 class CheckNrFrames : public Listener
00016 {
00017 public:
00018
00019 CheckNrFrames(Reporter* reporter, CmdOptions& options)
00020 {
00021 mReporter = reporter;
00022 mSegmentation = 0;
00023 mMargin = 0;
00024 if (options.GetNrArg() < 3)
00025 {
00026 ILOG_ERROR("Need at least 3 arguments");
00027 }
00028 else
00029 {
00030 mMargin = atol(options.GetArg(2));
00031 }
00032 mSbDir = "";
00033 if (options.GetNrArg() > 3)
00034 mSbDir = options.GetArg(3);
00035 }
00036
00037 virtual void
00038 HandleNewWalk(VideoSet* vs, Segmentation* segmentation)
00039 {
00040 mSegmentation = segmentation;
00041 }
00042
00043 virtual void
00044 HandleNewFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00045 {
00046 if (!mSegmentation)
00047 {
00048 ILOG_ERROR("No segmentation given");
00049 return;
00050 }
00051 int srcNr = src->LastFrame() + 1;
00052 int segNr = mSegmentation->GetNrFramesVideo(fileId);
00053 int d = abs(srcNr - segNr);
00054 if (d > mMargin)
00055 {
00056 ILOG_ERROR("Frame difference is " << d << " for file " <<
00057 vs->GetFile(fileId) << " (src says " << srcNr <<
00058 ", segmentation says " << segNr << ")");
00059 }
00060 if ((d > 0) && (mMargin != 0))
00061 ILOG_INFO("Frame difference is " << d << " for file " <<
00062 vs->GetFile(fileId) << " (src says " << srcNr <<
00063 ", segmentation says " << segNr << ")");
00064
00065 if (mSbDir.empty())
00066 return;
00067
00068 String fName = FileNameBase(vs->GetFile(fileId)) + ".sb";
00069 fName = FileNameConcat(mSbDir, fName);
00070 Persistency::FileLocator fLoc(vs->GetLocator(), fName);
00071 typedef Persistency::RepositoryInFileSystem FS;
00072 Persistency::File file = FS::GetInstance().GetFile(fLoc, false, false);
00073 std::vector<String> sb;
00074 file.ReadStrings(sb);
00075 int nrShots = mSegmentation->GetNrShotsVideo(fileId);
00076
00077 if (nrShots != sb.size() - 2)
00078 {
00079 ILOG_ERROR("Different nrShots: segmentation=" << nrShots <<
00080 ", sb=" << sb.size()-2);
00081 return;
00082 }
00083 int firstShot = mSegmentation->GetFirstShotVideo(fileId);
00084 for (int i=0 ; i<nrShots ; i++)
00085 {
00086 Util::StringParser p(sb[i+2]);
00087 int sbStart = p.GetInt(' ');
00088 int sbEnd = p.GetInt(' ');
00089
00090 int start = mSegmentation->GetStart(firstShot + i);
00091 int d = abs(start - sbStart);
00092 if (d > mMargin)
00093 ILOG_ERROR("Start differs: segmentation=" << start <<
00094 ", sb=" << sbStart);
00095 if ((d > 0) && (mMargin != 0))
00096 ILOG_INFO("Start differs: segmentation=" << start <<
00097 ", sb=" << sbStart);
00098
00099 int end = mSegmentation->GetEnd(firstShot + i);
00100 d = abs(end - sbEnd);
00101 if (d > mMargin)
00102 ILOG_ERROR("End differs: segmentation=" << end <<
00103 ", sb=" << sbEnd);
00104 if ((d > 0) && (mMargin != 0))
00105 ILOG_INFO("End differs: segmentation=" << end <<
00106 ", sb=" << sbEnd);
00107 }
00108 }
00109
00110 private:
00111
00112 Reporter* mReporter;
00113 Segmentation* mSegmentation;
00114 int mMargin;
00115 String mSbDir;
00116
00117 ILOG_VAR_DEC;
00118
00119 };
00120
00121 ILOG_VAR_INIT(CheckNrFrames, Impala.Core.VideoSet);
00122
00123 }
00124 }
00125 }
00126
00127 #endif