00001 #ifndef Impala_Core_VideoSet_CombineConcepts_h
00002 #define Impala_Core_VideoSet_CombineConcepts_h
00003
00004 #include "Core/Column/AddAssign.h"
00005 #include "Core/Column/MulAssign.h"
00006 #include "Core/Column/DivAssign.h"
00007 #include "Core/Table/SimilarityTableSet.h"
00008 #include "Core/VideoSet/Reporter.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace VideoSet
00015 {
00016
00017
00018 class CombineConcepts : public Listener
00019 {
00020 public:
00021 typedef Feature::FeatureDefinition FeatureDefinition;
00022 typedef Table::SimilarityTableSet SimilarityTableSet;
00023
00024 CombineConcepts(Reporter* reporter, CmdOptions& options)
00025 {
00026 mReporter = reporter;
00027 if (options.GetNrArg() < 7)
00028 {
00029 ILOG_ERROR("Missing argument");
00030 return;
00031 }
00032 mConceptFileName = options.GetArg(2);
00033 mModel = options.GetArg(3);
00034 mResultName = options.GetArg(4);
00035 mCombi = options.GetArg(5);
00036 if ((mCombi != "mul") && (mCombi != "avg"))
00037 {
00038 ILOG_ERROR("Unknown combination method : " << mCombi);
00039 return;
00040 }
00041 for (int i=6 ; i<options.GetNrArg() ; i++)
00042 mFeatureDefs.push_back(options.GetArg(i));
00043 }
00044
00045 virtual void
00046 HandleNewWalk(VideoSet* vs, String walkType)
00047 {
00048 mWalkType = walkType;
00049 }
00050
00051 virtual void
00052 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00053 {
00054 SimilarityTableSet* combinedSet = SimilarityTableSet::MakeFromFile
00055 (vs, mWalkType, mConceptFileName, mModel, mFeatureDefs[0], fileId);
00056 for (int i=1 ; i<mFeatureDefs.size() ; i++)
00057 {
00058 SimilarityTableSet* simSet = SimilarityTableSet::MakeFromFile
00059 (vs, mWalkType, mConceptFileName, mModel, mFeatureDefs[i],
00060 fileId);
00061 for (int t=0 ; t<simSet->NrTables() ; t++)
00062 {
00063 if (mCombi == "mul")
00064 MulAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00065 simSet->GetSimTable(t)->GetColumn1(), 0, -1);
00066 else
00067 AddAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00068 simSet->GetSimTable(t)->GetColumn1(), 0, -1);
00069 }
00070 delete simSet;
00071 }
00072 if (mCombi == "avg")
00073 for (int t=0 ; t<combinedSet->NrTables() ; t++)
00074 DivAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00075 mFeatureDefs.size(), 0, -1);
00076 combinedSet->ComputeRanks(true);
00077
00078 combinedSet->Save(vs, mWalkType, mConceptFileName, mModel, mResultName,
00079 fileId, true);
00080 delete combinedSet;
00081 }
00082
00083 private:
00084
00085 Reporter* mReporter;
00086 String mConceptFileName;
00087 String mModel;
00088 String mResultName;
00089 String mCombi;
00090 std::vector<String> mFeatureDefs;
00091 String mWalkType;
00092
00093 ILOG_VAR_DEC;
00094
00095 };
00096
00097 ILOG_VAR_INIT(CombineConcepts, Impala.Core.VideoSet);
00098
00099 }
00100 }
00101 }
00102
00103 #endif