00001 #ifndef Impala_Core_VideoSet_ClusterFeatures_h
00002 #define Impala_Core_VideoSet_ClusterFeatures_h
00003
00004 #include "Core/Feature/ClusterorFactory.h"
00005 #include "Core/Feature/Computor.h"
00006 #include "Core/VideoSet/Reporter.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace VideoSet
00013 {
00014
00015
00016 class ClusterFeatures : public Listener
00017 {
00018 public:
00019
00020 typedef Feature::Computor Computor;
00021 typedef Feature::Clusteror Clusteror;
00022 typedef Feature::FeatureTable FeatureTable;
00023
00024 ClusterFeatures(Computor* computor, String clusteror, Reporter* reporter,
00025 CmdOptions& options)
00026 {
00027 mReporter = reporter;
00028 mComputor = computor;
00029
00030 if (options.GetNrArg() < 7)
00031 ILOG_ERROR("missing argument");
00032 String mode = options.GetArg(4);
00033 int nrWantedClusters = atoi(options.GetArg(5));
00034 int nrSamplesAtime = atoi(options.GetArg(6));
00035 ILOG_INFO("mode = " << mode << ", wanted = " << nrWantedClusters <<
00036 ", samplesAtime = " << nrSamplesAtime);
00037
00038 mComputor->MakeRegionFeatureTableSet();
00039
00040 for (int p=0 ; p<mComputor->GetNrPixelFeatureSets() ; p++)
00041 {
00042 for (int r=0 ; r<mComputor->GetNrRegionFeatureSets() ; r++)
00043 {
00044
00045 int minElemsInCluster = 2;
00046 Feature::ClusterorFactory::Instance().Construct
00047 (mClusterors, p, r, nrWantedClusters, nrSamplesAtime,
00048 minElemsInCluster, clusteror, options);
00049 }
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 }
00068
00069 virtual void
00070 HandleNewFrame(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00071 {
00072 Quid quid = vs->GetQuidFrame(fileId, src->FrameNr());
00073 Array::Array2dVec3UInt8* im = Array::ArrayCreate<Array::Array2dVec3UInt8>
00074 (src->FrameWidth(), src->FrameHeight(), 0, 0, src->DataPtr(), true);
00075
00076 mComputor->ComputeRegionFeatures(im, quid);
00077
00078 for (int p=0 ; p<mComputor->GetNrPixelFeatureSets() ; p++)
00079 {
00080 for (int r=0 ; r<mComputor->GetNrRegionFeatureSets() ; r++)
00081 {
00082 FeatureTable* tab = mComputor->GetRegionFeatureTable(p, r);
00083 for (int clustID=0 ; clustID<mClusterors.size() ; clustID++)
00084 {
00085 if (mClusterors[clustID]->GetPixelFeatureSet() == p
00086 && mClusterors[clustID]->GetRegionFeatureSet() == r)
00087 {
00088 mClusterors[clustID]->Cluster(tab);
00089 }
00090 }
00091 }
00092 }
00093
00094 mComputor->GetRegionFeatureTableSet()->SetEmpty();
00095 delete im;
00096
00097
00098 bool allDone = true;
00099 for (int i=0 ; i<mClusterors.size() ; i++)
00100 {
00101 if (mReporter->DoPrint())
00102 mClusterors[i]->PrintStatus();
00103 allDone = allDone && mClusterors[i]->HadEnough();
00104 }
00105 if (allDone)
00106 {
00107 ILOG_INFO("all clusterors had enough");
00108 HandleDoneWalk(vs);
00109 ILOG_INFO("had enough, bye");
00110 exit(0);
00111 }
00112 }
00113
00114 virtual void
00115 HandleDoneWalk(VideoSet* vs)
00116 {
00117 ILOG_INFO("Done Walk");
00118 for (int i=0 ; i<mClusterors.size() ; i++)
00119 mClusterors[i]->FinishBuffer();
00120 std::cout << std::endl;
00121
00122 for (int i=0 ; i<mClusterors.size() ; i++)
00123 {
00124 Clusteror* c = mClusterors[i];
00125 FeatureTable* tab = mComputor->MakeProtoFeatureTable
00126 (c->GetPixelFeatureSet(), c->GetRegionFeatureSet(),
00127 c->GetClusterType(), c->GetClusterVal());
00128 c->Clusters2FeatureTable(tab);
00129 }
00130
00131 mComputor->WriteProtoFeatureTableSet(vs);
00132 }
00133
00134 private:
00135
00136 Reporter* mReporter;
00137 Feature::Computor* mComputor;
00138 std::vector<Clusteror*> mClusterors;
00139
00140 ILOG_VAR_DEC;
00141
00142 };
00143
00144 ILOG_VAR_INIT(ClusterFeatures, Impala.Core.VideoSet);
00145
00146 }
00147 }
00148 }
00149
00150 #endif