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

Color64Extractor.h

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

Generated on Thu Jan 13 09:04:30 2011 for ImpalaSrc by  doxygen 1.5.1