00001 #ifndef Impala_Core_VideoSet_Color64Extractor_h
00002 #define Impala_Core_VideoSet_Color64Extractor_h
00003
00004
00005
00006
00007 #include "Core/VideoSet/Reporter.h"
00008 #include "Core/Vector/VectorTem.h"
00009 #include "Core/Feature/FeatureTable.h"
00010 #include "Core/Feature/Color64.h"
00011
00012
00013
00014
00015
00016 namespace Impala
00017 {
00018 namespace Core
00019 {
00020 namespace VideoSet
00021 {
00022
00023 class Color64Extractor : public Listener
00024 {
00025
00026 protected:
00027
00028 typedef Vector::VectorTem<Real64> VectorReal64;
00029
00030 public:
00031
00032 Color64Extractor(Reporter* reporter,
00033 CmdOptions& options, CString featureName, int binCount)
00034 {
00035 mReporter = reporter;
00036 mFeatureName = featureName;
00037 mBinCount = binCount;
00038 Feature::FeatureDefinition def(GetFeatureName());
00039 mHistogramTable = new Feature::FeatureTable(def, 1000, GetBinCount());
00040
00041 m_verbose = FALSE;
00042 m_verbose2 = FALSE;
00043 }
00044
00045 Color64Extractor(Reporter* reporter, CmdOptions& options)
00046 {
00047 mReporter = reporter;
00048 mFeatureName = "color64";
00049 mBinCount = 64;
00050 Feature::FeatureDefinition def(GetFeatureName());
00051 mHistogramTable = new Feature::FeatureTable(def, 1000, GetBinCount());
00052
00053 m_verbose = FALSE;
00054 m_verbose2 = FALSE;
00055
00056
00057
00058 }
00059
00060 virtual
00061 ~Color64Extractor()
00062 {
00063 delete mHistogramTable;
00064 }
00065
00066 String
00067 GetFeatureName() const
00068 {
00069 return mFeatureName;
00070 }
00071
00072 virtual void
00073 HandleNewFrame(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00074 {
00075 if (!src)
00076 {
00077 ILOG_ERROR("Not a valid source for fileId " << fileId);
00078 return;
00079 }
00080
00081 Array::Array2dVec3UInt8* im = Array::ArrayCreate<Array::Array2dVec3UInt8>
00082 (src->FrameWidth(), src->FrameHeight(), 0, 0, src->DataPtr(), true);
00083 if (!im)
00084 {
00085 ILOG_ERROR("Couldn't load image for fileId " << fileId);
00086 return;
00087 }
00088
00089 if (m_verbose)
00090 {
00091 std::cout << "Current Frame No. = " << src->FrameNr() << std::endl;
00092 }
00093
00094
00095
00096
00097
00098
00099 VectorReal64 histogram(mBinCount);
00100
00101 Core::Feature::Color64* pExtractor = new Core::Feature::Color64(mFeatureName);
00102 pExtractor->Extract(im, histogram);
00103
00104 Quid quid = vs->GetQuidFrame(fileId, src->FrameNr());
00105 mHistogramTable->Add(quid, histogram);
00106
00107 delete im;
00108 delete pExtractor;
00109
00110 ILOG_DEBUG("... done keyframe " << src->FrameNr());
00111
00112 }
00113
00114 virtual void
00115 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00116 {
00117 bool binary = true;
00118 Feature::FeatureDefinition def = mHistogramTable->GetFeatureDefinition();
00119 std::string fName = vs->GetFilePathFeatureData("Keyframes", def, fileId, false, -1, true, false);
00120
00121 if (!fName.empty())
00122 Table::Write(mHistogramTable, fName, vs->GetDatabase(), binary);
00123 mHistogramTable->SetSize(0);
00124 }
00125
00126 protected:
00127
00128 int
00129 GetBinCount() const
00130 {
00131 return mBinCount;
00132 }
00133
00134 private:
00135
00136
00137
00138 Reporter* mReporter;
00139 String mFeatureName;
00140 int mBinCount;
00141 Feature::FeatureTable* mHistogramTable;
00142
00143 BOOL m_verbose;
00144 BOOL m_verbose2;
00145
00146 ILOG_VAR_DECL;
00147 };
00148
00149 ILOG_VAR_INIT(Color64Extractor, Impala.Core.VideoSet);
00150
00151 }
00152 }
00153 }
00154
00155 #endif