Переглянути джерело

Merge branch 'master', remote branch 'dbv/master' into experimental

Alexander Luetz 12 роки тому
батько
коміт
e293f8e171

+ 1 - 1
cbaselib/LabeledFileList.cpp

@@ -24,7 +24,7 @@ using namespace NICE;
 
 LabeledFileList::LabeledFileList()
 {
-  debug_dataset = false;
+  debug_dataset = true;
 }
 
 LabeledFileList::~LabeledFileList()

+ 262 - 262
cbaselib/MultiDataset.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file MultiDataset.cpp
 * @brief multiple datasets
 * @author Erik Rodner
@@ -25,300 +25,300 @@ using namespace NICE;
 #undef DEBUG_MultiDataset
 
 void MultiDataset::selectExamples ( const std::string & examples_command,
-		      const LabeledSet & base,
-		      LabeledSet & positives,
-		      LabeledSet & negatives,
-		      const ClassNames & cn ) const
+                                    const LabeledSet & base,
+                                    LabeledSet & positives,
+                                    LabeledSet & negatives,
+                                    const ClassNames & cn ) const
 {
-    vector<string> examples;
-    StringTools::split ( examples_command, ';', examples );
-    set<int> processed_classes;
-
-    for ( vector<string>::const_iterator i  = examples.begin();
-					 i != examples.end();
-					 i++ )
+  vector<string> examples;
+  StringTools::split ( examples_command, ';', examples );
+  set<int> processed_classes;
+
+  for ( vector<string>::const_iterator i  = examples.begin();
+        i != examples.end();
+        i++ )
+  {
+    const std::string & cmd = *i;
+    vector<string> parts;
+    StringTools::split ( cmd, ' ', parts );
+
+    if ( (parts.size() != 3) && ((parts.size() != 2) || (parts[0] != "all")) )
+      fthrow( Exception, "Syntax error " << examples_command );
+
+    const std::string & mode = parts[0];
+    const std::string & csel = parts[1];
+    double parameter = (parts.size() == 3 ) ? atof(parts[2].c_str()) : 0.0;
+    map<int, int> fpe;
+
+    set<int> selection;
+    cn.getSelection ( csel, selection );
+    for ( set<int>::const_iterator j  = selection.begin();
+          j != selection.end();
+          j++ )
     {
-		const std::string & cmd = *i;
-		vector<string> parts;
-		StringTools::split ( cmd, ' ', parts );
-		
-		if ( (parts.size() != 3) && ((parts.size() != 2) || (parts[0] != "all")) ) 
-			fthrow( Exception, "Syntax error " << examples_command );
-		
-		const std::string & mode = parts[0];
-		const std::string & csel = parts[1];
-		double parameter = (parts.size() == 3 ) ? atof(parts[2].c_str()) : 0.0;
-		map<int, int> fpe;
-
-		set<int> selection;
-		cn.getSelection ( csel, selection );
-		for ( set<int>::const_iterator j  = selection.begin();
-						   j != selection.end();
-						   j++ )
-		{
-			int classno = *j;
-			if ( processed_classes.find(classno) == processed_classes.end() )
-			{
+      int classno = *j;
+      if ( processed_classes.find(classno) == processed_classes.end() )
+      {
 #ifdef DEBUG_MultiDataset
-				fprintf (stderr, "class %s: %s %d\n", cn.text(classno).c_str(),
-					mode.c_str(), (int)parameter );
+        fprintf (stderr, "class %s: %s %d\n", cn.text(classno).c_str(),
+                 mode.c_str(), (int)parameter );
 #endif
-				fpe[*j] = (int)parameter;
-				processed_classes.insert(classno);
-			} else {
-				if ( csel != "*" ) {
-					fthrow ( Exception, "Example selection method for class %s has multiple specifications" << cn.text(classno) );
-				}
-			}
-		}
-
-		if ( mode == "seq" ) {
-			LabeledSetSelection<LabeledSet>::selectSequential ( 
-			fpe, base, positives, negatives );   
+        fpe[*j] = (int)parameter;
+        processed_classes.insert(classno);
+      } else {
+        if ( csel != "*" ) {
+          fthrow ( Exception, "Example selection method for class %s has multiple specifications" << cn.text(classno) );
+        }
+      }
+    }
+
+    if ( mode == "seq" ) {
+      LabeledSetSelection<LabeledSet>::selectSequential (
+        fpe, base, positives, negatives );
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "MultiDataset: after special seq selection: %d\n", positives.count() );
+      fprintf (stderr, "MultiDataset: after special seq selection: %d\n", positives.count() );
 #endif
-		} else if ( mode == "step" ) {
-			LabeledSetSelection<LabeledSet>::selectSequentialStep ( 
-			fpe, base, positives, negatives );   
+    } else if ( mode == "step" ) {
+      LabeledSetSelection<LabeledSet>::selectSequentialStep (
+        fpe, base, positives, negatives );
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "MultiDataset: after special step selection: %d\n", positives.count() );
+      fprintf (stderr, "MultiDataset: after special step selection: %d\n", positives.count() );
 #endif
-		} else if ( mode == "random" ) {
-			LabeledSetSelection<LabeledSet>::selectRandom ( 
-			fpe, base, positives, negatives );   
+    } else if ( mode == "random" ) {
+      LabeledSetSelection<LabeledSet>::selectRandom (
+        fpe, base, positives, negatives );
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "MultiDataset: after special random selection: %d\n", positives.count() );
+      fprintf (stderr, "MultiDataset: after special random selection: %d\n", positives.count() );
 #endif
-		} else if ( mode == "all" ) {
-			if ( (int)selection.size() == cn.numClasses() ) 
-			{
-				// preserve permutation
-				LabeledSet::Permutation permutation;
-				base.getPermutation ( permutation );
-				for ( LabeledSet::Permutation::iterator i = permutation.begin(); i != permutation.end(); i++ )
-				{
-					int classno = i->first;
-					ImageInfo *element = const_cast< ImageInfo * > ( i->second );
-					positives.add_reference ( classno, element );
-				}
-			} else {
-				LabeledSetSelection<LabeledSet>::selectClasses ( selection, base, positives, negatives );
-			}
+    } else if ( mode == "all" ) {
+      if ( (int)selection.size() == cn.numClasses() )
+      {
+        // preserve permutation
+        LabeledSet::Permutation permutation;
+        base.getPermutation ( permutation );
+        for ( LabeledSet::Permutation::iterator i = permutation.begin(); i != permutation.end(); i++ )
+        {
+          int classno = i->first;
+          ImageInfo *element = const_cast< ImageInfo * > ( i->second );
+          positives.add_reference ( classno, element );
+        }
+      } else {
+        LabeledSetSelection<LabeledSet>::selectClasses ( selection, base, positives, negatives );
+      }
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "MultiDataset: after special class selection: %d\n", positives.count() );
+      fprintf (stderr, "MultiDataset: after special class selection: %d\n", positives.count() );
 #endif
-		} else {
-			fthrow ( Exception, "Wrong value for parameter example\n");
-		}
+    } else {
+      fthrow ( Exception, "Wrong value for parameter example\n");
     }
+  }
 
 #ifdef DEBUG_MultiDataset
-    fprintf (stderr, "MultiDataset: after special selection operations: %d\n", positives.count() );
+  fprintf (stderr, "MultiDataset: after special selection operations: %d\n", positives.count() );
 #endif
-    
-    set<int> allclasses;
-    cn.getSelection ( "*", allclasses );
 
-    set<int> allnegative_classes;
+  set<int> allclasses;
+  cn.getSelection ( "*", allclasses );
+
+  set<int> allnegative_classes;
 
-    // add all examples from allclasses \setminus processed_classes
-    set_difference(allclasses.begin(), allclasses.end(), processed_classes.begin(), processed_classes.end(),
-                      inserter(allnegative_classes, allnegative_classes.end()));
+  // add all examples from allclasses \setminus processed_classes
+  set_difference(allclasses.begin(), allclasses.end(), processed_classes.begin(), processed_classes.end(),
+                 inserter(allnegative_classes, allnegative_classes.end()));
 
-    LabeledSet dummy;
-    LabeledSetSelection<LabeledSet>::selectClasses ( allnegative_classes, 
-	base, negatives, dummy );
+  LabeledSet dummy;
+  LabeledSetSelection<LabeledSet>::selectClasses ( allnegative_classes,
+      base, negatives, dummy );
 
 }
 
 /** MultiDataset ------- constructor */
 MultiDataset::MultiDataset( const Config *conf )
 {
-    std::set<string> blocks;
-    conf->getAllBlocks ( blocks );
-
-    map<string, Config> dsconfs;
-    map<string, string> dirs;
-    for ( set<string>::iterator i = blocks.begin();
-	    i != blocks.end();  )
+  std::set<string> blocks;
+  conf->getAllBlocks ( blocks );
+
+  map<string, Config> dsconfs;
+  map<string, string> dirs;
+  for ( set<string>::iterator i = blocks.begin();
+        i != blocks.end();  )
+  {
+    if ( conf->gB(*i, "disable", false) )
     {
-		if ( conf->gB(*i, "disable", false) )
-		{
-			i++;
-			continue;
-		}
-
-		std::string dataset = conf->gS( *i, "dataset", "unknown" );
-		if ( dataset == "unknown" )
-			blocks.erase(i++);
-		else {
+      i++;
+      continue;
+    }
+
+    std::string dataset = conf->gS( *i, "dataset", "unknown" );
+    if ( dataset == "unknown" )
+      blocks.erase(i++);
+    else {
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "Reading dataset config for block [%s]\n", i->c_str() );
+      fprintf (stderr, "Reading dataset config for block [%s]\n", i->c_str() );
 #endif
-			Config dsconf ( (dataset + "/dataset.conf").c_str() );
-			
-			dirs[*i] = dataset;
-			dsconfs[*i] = dsconf;
-			i++;
-		}
+      Config dsconf ( (dataset + "/dataset.conf").c_str() );
+
+      dirs[*i] = dataset;
+      dsconfs[*i] = dsconf;
+      i++;
     }
-  
-    if ( blocks.find("traintest") != blocks.end() )
+  }
+
+  if ( blocks.find("traintest") != blocks.end() )
+  {
+    LabeledSet ls_base;
+    LabeledSet ls_train (true);
+    LabeledSet ls_nontrain (true);
+    LabeledSet ls_test (true);
+    LabeledSet dummy (true);
+    LabeledSet temp (true);
+
+    bool localizationInfoDisabled = conf->gB("traintest", "disable_localization_info", false );
+
+    std::string classselection_train = conf->gS("traintest", "classselection_train", "*");
+    std::string classselection_test = conf->gS("traintest", "classselection_test", "*");
+    classnames["traintest"] = ClassNames();
+
+    std::string classNamesTxt = dirs["traintest"] + "/classnames.txt";
+    if ( FileMgt::fileExists ( classNamesTxt ) )
     {
-		LabeledSet ls_base;
-		LabeledSet ls_train (true);
-		LabeledSet ls_nontrain (true);
-		LabeledSet ls_test (true);
-		LabeledSet dummy (true);
-		LabeledSet temp (true);
-
-		bool localizationInfoDisabled = conf->gB("traintest", "disable_localization_info", false );
-
-		std::string classselection_train = conf->gS("traintest", "classselection_train", "*");
-		std::string classselection_test = conf->gS("traintest", "classselection_test", "*");
-		classnames["traintest"] = ClassNames();
-		
-		std::string classNamesTxt = dirs["traintest"] + "/classnames.txt";
-		if ( FileMgt::fileExists ( classNamesTxt ) )
-		{
-			classnames["traintest"].read ( classNamesTxt );
-		} else {
-			classnames["traintest"].readFromConfig ( dsconfs["traintest"], classselection_train );
-		}
-		
-		lfl.get ( dirs["traintest"], dsconfs["traintest"], classnames["traintest"], ls_base,
-			localizationInfoDisabled, conf->gB("traintest", "debug_dataset", false ) ); 
-
-		std::string examples_train =  conf->gS("traintest", "examples_train" );
-		selectExamples ( examples_train, ls_base, ls_train, ls_nontrain, classnames["traintest"] );
-			
-		set<int> selection_test;
-		classnames["traintest"].getSelection ( classselection_test, selection_test );
-
-		std::string examples_test =  conf->gS("traintest", "examples_test" );
-		if ( examples_test == "reclassification" )
-		{
-			LabeledSetSelection<LabeledSet>::selectClasses 
-			( selection_test, ls_train, ls_test, dummy );
-
-		} else {
-			selectExamples ( examples_test, ls_nontrain, temp, dummy, classnames["traintest"] );
-			LabeledSetSelection<LabeledSet>::selectClasses 
-			( selection_test, temp, ls_test, dummy );
-		}
-
-		classnames["train"] = classnames["traintest"];
-		classnames["test"] = ClassNames ( classnames["traintest"], classselection_test );
-		datasets["test"] = ls_test;
-		datasets["train"] = ls_train;
+      classnames["traintest"].read ( classNamesTxt );
+    } else {
+      classnames["traintest"].readFromConfig ( dsconfs["traintest"], classselection_train );
     }
 
-    for ( set<string>::const_iterator i = blocks.begin();
-				      i != blocks.end();
-				      i++ )
+    lfl.get ( dirs["traintest"], dsconfs["traintest"], classnames["traintest"], ls_base,
+              localizationInfoDisabled, conf->gB("traintest", "debug_dataset", false ) );
+
+    std::string examples_train =  conf->gS("traintest", "examples_train" );
+    selectExamples ( examples_train, ls_base, ls_train, ls_nontrain, classnames["traintest"] );
+
+    set<int> selection_test;
+    classnames["traintest"].getSelection ( classselection_test, selection_test );
+
+    std::string examples_test =  conf->gS("traintest", "examples_test" );
+    if ( examples_test == "reclassification" )
     {
-		std::string name = *i;
-		if ( classnames.find(name) != classnames.end() )
-			continue;
+      LabeledSetSelection<LabeledSet>::selectClasses
+      ( selection_test, ls_train, ls_test, dummy );
+
+    } else {
+      selectExamples ( examples_test, ls_nontrain, temp, dummy, classnames["traintest"] );
+      LabeledSetSelection<LabeledSet>::selectClasses
+      ( selection_test, temp, ls_test, dummy );
+    }
+
+    classnames["train"] = classnames["traintest"];
+    classnames["test"] = ClassNames ( classnames["traintest"], classselection_test );
+    datasets["test"] = ls_test;
+    datasets["train"] = ls_train;
+  }
 
-		if ( conf->gB(name, "disable", false) == true )
-			continue;
+  for ( set<string>::const_iterator i = blocks.begin();
+        i != blocks.end();
+        i++ )
+  {
+    std::string name = *i;
+    if ( classnames.find(name) != classnames.end() )
+      continue;
 
-		if ( dsconfs.find(name) == dsconfs.end() )
-			continue;
+    if ( conf->gB(name, "disable", false) == true )
+      continue;
 
-		LabeledSet ls_base;
-		LabeledSet ls (true);
-		LabeledSet dummy (true);
-		LabeledSet temp (true);
+    if ( dsconfs.find(name) == dsconfs.end() )
+      continue;
 
-		bool localizationInfoDisabled = conf->gB(name, "disable_localization_info", false );
+    LabeledSet ls_base;
+    LabeledSet ls (true);
+    LabeledSet dummy (true);
+    LabeledSet temp (true);
 
-		std::string classselection = conf->gS(name, "classselection", "*");
-		classnames[name] = ClassNames();
+    bool localizationInfoDisabled = conf->gB(name, "disable_localization_info", false );
 
-		std::string classNamesTxt = dirs[name] + "/classnames.txt";
-		if ( FileMgt::fileExists ( classNamesTxt ) )
-		{
+    std::string classselection = conf->gS(name, "classselection", "*");
+    classnames[name] = ClassNames();
+
+    std::string classNamesTxt = dirs[name] + "/classnames.txt";
+    if ( FileMgt::fileExists ( classNamesTxt ) )
+    {
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "MultiDataset: reading class names from %s\n", classNamesTxt.c_str() );
+      fprintf (stderr, "MultiDataset: reading class names from %s\n", classNamesTxt.c_str() );
 #endif
-			classnames[name].read ( classNamesTxt );
-		} else {
+      classnames[name].read ( classNamesTxt );
+    } else {
 #ifdef DEBUG_MultiDataset
-			fprintf (stderr, "MultiDataset: reading class names from dataset config file\n" );
+      fprintf (stderr, "MultiDataset: reading class names from dataset config file\n" );
 #endif
-			classnames[name].readFromConfig ( dsconfs[name], classselection );
-		}
-		
-		lfl.get ( dirs[name], dsconfs[name], classnames[name], ls_base,
-			localizationInfoDisabled, conf->gB(name, "debug_dataset", false ) ); 
+      classnames[name].readFromConfig ( dsconfs[name], classselection );
+    }
+
+    lfl.get ( dirs[name], dsconfs[name], classnames[name], ls_base,
+              localizationInfoDisabled, conf->gB(name, "debug_dataset", false ) );
 #ifdef DEBUG_MultiDataset
-		fprintf (stderr, "MultiDataset: class names -->\n" );
-		classnames[name].store ( cerr );
-		fprintf (stderr, "MultiDataset: all information about %s set obtained ! (size %d)\n", name.c_str(), ls_base.count() );
+    fprintf (stderr, "MultiDataset: class names -->\n" );
+    classnames[name].store ( cerr );
+    fprintf (stderr, "MultiDataset: all information about %s set obtained ! (size %d)\n", name.c_str(), ls_base.count() );
 #endif
 
-		std::string examples = conf->gS(name, "examples", "all *" );
-		selectExamples ( examples, ls_base, ls, dummy, classnames[name] );
-		
+    std::string examples = conf->gS(name, "examples", "all *" );
+    selectExamples ( examples, ls_base, ls, dummy, classnames[name] );
+
 #ifdef DEBUG_MultiDataset
-		fprintf (stderr, "MultiDataset: size after selection %d\n", ls.count() );
+    fprintf (stderr, "MultiDataset: size after selection %d\n", ls.count() );
 #endif
 
-		datasets[name] = ls;
-    }
+    datasets[name] = ls;
+  }
 
-    bool dumpSelections = conf->gB("datasets", "dump_selection", false);
-    if ( dumpSelections )
+  bool dumpSelections = conf->gB("datasets", "dump_selection", false);
+  if ( dumpSelections )
+  {
+    for ( map<string, LabeledSet>::const_iterator i = datasets.begin();
+          i != datasets.end(); i++ )
     {
-		for ( map<string, LabeledSet>::const_iterator i = datasets.begin();
-			i != datasets.end(); i++ )
-		{
-			const std::string & name = i->first;
-			const LabeledSet & ls = i->second;
-			const ClassNames & classNames = classnames[name];
-
-			mkdir ( name.c_str(), 0755 );
-
-			std::string filelist = name + "/files.txt";
-			ofstream olist ( filelist.c_str(), ios::out );
-			if ( !olist.good() )
-				fthrow (IOException, "Unable to dump selections to " << filelist );
-			
-			LOOP_ALL_S(ls)
-			{
-				EACH_S(classno, file);
-				std::string classtext = classNames.code(classno);
-				olist << classtext << " " << file << endl;
-			}
-			olist.close();
-
-			std::string datasetconf = name + "/dataset.conf";
-			ofstream oconf ( datasetconf.c_str(), ios::out );
-			if ( !oconf.good() )
-				fthrow (IOException, "Unable to dump selections to " << datasetconf );
-
-			set<int> classnos;
-			classNames.getSelection ( "*", classnos);
-
-			oconf << "[main]" << endl;
-			oconf << "filelist = \"files.txt\"" << endl << endl;
-
-			oconf << "[classnames]" << endl;
-			for ( set<int>::const_iterator i = classnos.begin();
-					i != classnos.end(); i++ )
-			{
-				const std::string & code = classNames.code(*i);
-				const std::string & text = classNames.text(*i);
-				oconf << code << "     =     \"" << text << "\"" << endl;
-			}
-			oconf.close();
-			
-			classNames.save ( name + "/classnames.txt" );
-		}
+      const std::string & name = i->first;
+      const LabeledSet & ls = i->second;
+      const ClassNames & classNames = classnames[name];
+
+      mkdir ( name.c_str(), 0755 );
+
+      std::string filelist = name + "/files.txt";
+      ofstream olist ( filelist.c_str(), ios::out );
+      if ( !olist.good() )
+        fthrow (IOException, "Unable to dump selections to " << filelist );
+
+      LOOP_ALL_S(ls)
+      {
+        EACH_S(classno, file);
+        std::string classtext = classNames.code(classno);
+        olist << classtext << " " << file << endl;
+      }
+      olist.close();
+
+      std::string datasetconf = name + "/dataset.conf";
+      ofstream oconf ( datasetconf.c_str(), ios::out );
+      if ( !oconf.good() )
+        fthrow (IOException, "Unable to dump selections to " << datasetconf );
+
+      set<int> classnos;
+      classNames.getSelection ( "*", classnos);
+
+      oconf << "[main]" << endl;
+      oconf << "filelist = \"files.txt\"" << endl << endl;
+
+      oconf << "[classnames]" << endl;
+      for ( set<int>::const_iterator i = classnos.begin();
+            i != classnos.end(); i++ )
+      {
+        const std::string & code = classNames.code(*i);
+        const std::string & text = classNames.text(*i);
+        oconf << code << "     =     \"" << text << "\"" << endl;
+      }
+      oconf.close();
+
+      classNames.save ( name + "/classnames.txt" );
     }
+  }
 
 }
 
@@ -328,32 +328,32 @@ MultiDataset::~MultiDataset()
 
 const ClassNames & MultiDataset::getClassNames ( const std::string & key ) const
 {
-    map<string, ClassNames>::const_iterator i = classnames.find(key);
-    if ( i == classnames.end() )
-    {
-	fprintf (stderr, "MultiDataSet::getClassNames() FATAL ERROR: dataset <%s> not found !\n", key.c_str() );
-	exit(-1);
-    } 
-    return (i->second);
+  map<string, ClassNames>::const_iterator i = classnames.find(key);
+  if ( i == classnames.end() )
+  {
+    fprintf (stderr, "MultiDataSet::getClassNames() FATAL ERROR: dataset <%s> not found !\n", key.c_str() );
+    exit(-1);
+  }
+  return (i->second);
 
 }
 
 const LabeledSet *MultiDataset::operator[] ( const std::string & key ) const
 {
-    map<string, LabeledSet>::const_iterator i = datasets.find(key);
-    if ( i == datasets.end() )
-    {
-	fprintf (stderr, "MultiDataSet: FATAL ERROR: dataset <%s> not found !\n", key.c_str() );
-	exit(-1);
-    } 
-    return &(i->second);
+  map<string, LabeledSet>::const_iterator i = datasets.find(key);
+  if ( i == datasets.end() )
+  {
+    fprintf (stderr, "MultiDataSet: FATAL ERROR: dataset <%s> not found !\n", key.c_str() );
+    exit(-1);
+  }
+  return &(i->second);
 }
 
 const LabeledSet *MultiDataset::at ( const std::string & key ) const
 {
-    map<string, LabeledSet>::const_iterator i = datasets.find(key);
-    if ( i == datasets.end() )
-	return NULL;
-    else
-	return &(i->second);
+  map<string, LabeledSet>::const_iterator i = datasets.find(key);
+  if ( i == datasets.end() )
+    return NULL;
+  else
+    return &(i->second);
 }

+ 1 - 2
classifier/fpclassifier/logisticregression/FPCSMLR.cpp

@@ -28,8 +28,7 @@ FPCSMLR::~FPCSMLR()
 
 ClassificationResult FPCSMLR::classify ( Example & pce )
 {
-  FullVector overall_distribution ( maxClassNo + 1 );
-  overall_distribution[maxClassNo] = 0.0;
+  FullVector overall_distribution ( maxClassNo);
 
   double maxp = -numeric_limits<double>::max();
   int classno = 0;

+ 1 - 3
classifier/vclassifier/VCDTSVM.cpp

@@ -119,9 +119,7 @@ ClassificationResult VCDTSVM::classify ( const NICE::Vector & x ) const
     }
   }
   return ClassificationResult ( bclass, scores );
-#endif
-
-#ifndef WRITE
+#else
   int c2 = ( *counter ) [0];
   ( *counter ) [0]++;
   FullVector tmp ( results[c2].size() );

+ 221 - 221
features/localfeatures/LFColorSande.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LFColorSande.cpp
 * @brief interface to ColorSande implementation
 * @author Erik Rodner
@@ -28,40 +28,40 @@ using namespace NICE;
 
 
 
-LFColorSande::LFColorSande( const Config *conf, std::string section )
+LFColorSande::LFColorSande ( const Config *conf, std::string section )
 {
-    c_binaryExecutable = conf->gS( section, "binaryExecutable", "/home/bachi/libs/van_de_sande/x86_64-linux-gcc/colorDescriptor" );
-    c_params = conf->gS(section, "params", "--descriptor opponentsift");
-	scales = conf->gS(section, "scales", "1+1.5+3.0+4.5+6");
-	
-	descriptor_size = conf->gI(section, "descriptor_size", -1 );
-    
-	usegrid = conf->gB(section, "usegrid", false);
-	
-	int g = conf->gI( section, "grid", 5);
-	std::ostringstream temp;
-	temp << g;
-	gridsize = temp.str();
-	
-    if ( descriptor_size <= 0 ) 
-    {
-		fprintf (stderr, "LFColorSande::LFColorSande: No descriptor size found in config -> self test\n");
-		/** get feature dimension **/
-		NICE::Image testimg (DESCSIZE_DUMMY);
-		VVector features;
-		VVector positions;
-		extractFeatures ( testimg, features, positions );
-		if ( features.size() <= 0 )
-			fthrow( Exception, "No features found in " << DESCSIZE_DUMMY << " picture.");
-		descriptor_size = features[0].size();
-
-		fprintf (stderr, "LFColorSande::LFColorSande Self Test features:%d dimension:%d\n", (int)features.size(), descriptor_size );
-    }
-
-    if ( descriptor_size != conf->gI("features", "descriptor_size", descriptor_size) )
-    {
-		cerr << "Warning: LFColorSande: descriptor sizes do not match !!!" << endl;
-	}
+  c_binaryExecutable = conf->gS ( section, "binaryExecutable", "/home/bachi/libs/van_de_sande/x86_64-linux-gcc/colorDescriptor" );
+  c_params = conf->gS ( section, "params", "--descriptor opponentsift" );
+  scales = conf->gS ( section, "scales", "1+1.5+3.0+4.5+6" );
+
+  descriptor_size = conf->gI ( section, "descriptor_size", -1 );
+
+  usegrid = conf->gB ( section, "usegrid", false );
+
+  int g = conf->gI ( section, "grid", 5 );
+  std::ostringstream temp;
+  temp << g;
+  gridsize = temp.str();
+
+  if ( descriptor_size <= 0 )
+  {
+    fprintf ( stderr, "LFColorSande::LFColorSande: No descriptor size found in config -> self test\n" );
+    /** get feature dimension **/
+    NICE::Image testimg ( DESCSIZE_DUMMY );
+    VVector features;
+    VVector positions;
+    extractFeatures ( testimg, features, positions );
+    if ( features.size() <= 0 )
+      fthrow ( Exception, "No features found in " << DESCSIZE_DUMMY << " picture." );
+    descriptor_size = features[0].size();
+
+    fprintf ( stderr, "LFColorSande::LFColorSande Self Test features:%d dimension:%d\n", ( int ) features.size(), descriptor_size );
+  }
+
+  if ( descriptor_size != conf->gI ( "features", "descriptor_size", descriptor_size ) )
+  {
+    cerr << "Warning: LFColorSande: descriptor sizes do not match !!!" << endl;
+  }
 }
 
 LFColorSande::~LFColorSande()
@@ -70,199 +70,199 @@ LFColorSande::~LFColorSande()
 
 int LFColorSande::getDescSize () const
 {
-    return descriptor_size;
+  return descriptor_size;
 }
 
-int LFColorSande::extractFeatures ( const NICE::Image & img, VVector & features, 
-				     VVector & positions ) const
+int LFColorSande::extractFeatures ( const NICE::Image & img, VVector & features,
+                                    VVector & positions ) const
 {
-	cerr << "Warning: LFColorSande is a color local feature implementation, but you are calling the gray-image version of extractFeatures" << endl;
-	NICE::ColorImage colorimg;
-	NICE::grayToRGB (img, &colorimg);
-	extractFeatures( colorimg, features, positions);
+  cerr << "Warning: LFColorSande is a color local feature implementation, but you are calling the gray-image version of extractFeatures" << endl;
+  NICE::ColorImage colorimg;
+  NICE::grayToRGB ( img, &colorimg );
+  extractFeatures ( colorimg, features, positions );
 
-	return 0;
+  return 0;
 }
 
 int LFColorSande::extractFeatures ( const NICE::ColorImage & img, VVector & features, VVector & positions ) const
 {
-	if(features.size() != positions.size())
-	{
-		positions.clear();
-	}
-	
-	bool delete_imgfile = false;
-	std::string imgfile = Globals::getCurrentImgFN();
-
-	fprintf (stderr, "imgfile: %s\n", imgfile.c_str());
-	if ( (imgfile.size() <= 0) || (( !StringTools::regexMatch ( imgfile, ".[Jj][pP][Gg]$" ) ) 
-		     && ( !StringTools::regexMatch ( imgfile, ".[Pp][Nn][Gg]$" ))))
-	{
-		
-		if ( imgfile.size() <= 0 )
-		{
-			imgfile = FileMgt::createTempFile ( "/tmp/osl_lfColorSande_input_%s.png" );
-			fprintf (stderr, "LFColorSande: write image to %s (write image)\n", imgfile.c_str() );
-			ImageFile imgf ( imgfile );
-			imgf.writer ( &img );
-		} else {
-			std::string tmpfile = FileMgt::createTempFile ( "/tmp/osl_lfColorSande_input_%s.png" );
-			fprintf (stderr, "LFColorSande: write image to %s (convert)\n", tmpfile.c_str() );
-
-			std::string convertcall = "convert " + imgfile + " " + tmpfile;
-			cerr << "convert call: " << convertcall << endl;
-			system ( convertcall.c_str() );
-
-			imgfile = tmpfile;
-		}
-	    
-		delete_imgfile = true;
-	}
-    
-	std::string outputfn  = FileMgt::createTempFile ( "/tmp/osl_lfColorSande_output_%s" ) ;
-
-	std::string gridparams ="";
-	
-	if(usegrid)
-		gridparams = " --detector densesampling --ds_spacing " + gridsize +" --ds_scales "+scales;
-	
-	std::string call = c_binaryExecutable + " " +
-			   imgfile            + " " +   
-			   c_params           +
-			   gridparams         +
-			   " -output "        + outputfn;
-
-	cerr << "LFColorSande: parameters: <" << c_params+gridparams << ">" << endl;
-	clog << "Systemcall: " << call << endl;
-
-	
-	const int buffersize = 65536;
-	char *buffer = new char [buffersize];
-	FILE *f = popen ( call.c_str(), "r" );
-	if ( f == NULL )
-	{
-		fthrow(Exception, "Unable to run the implementation of van de Sande: " << call << endl << strerror(errno) );
-	}
-
-	while ( ! feof(f) ) 
-	{
-		if ( fgets ( buffer, buffersize, f ) <= 0 )
-		{
-			break;
-		} else {
-			fprintf (stderr, "LFColorSande::extractFeatures: [INFO] %s", buffer );
-		}
-	}
- 
-
-	pclose(f);
-
-	f = fopen ( outputfn.c_str(), "r" );
-	if ( f == NULL )
-	{
-		fthrow( Exception, "Unable to read output of van de Sande implementation\n");
-	}
-
-	if ( fgets ( buffer, buffersize, f ) <= 0 )
-	{
-		fprintf (stderr, "LFColorSande::extractFeatures: output is empty !\n");
-		fprintf (stderr, "img %s out %s\n", imgfile.c_str(), outputfn.c_str() );
-		fprintf (stderr, "call %s\n", call.c_str() );
-
-		exit(-1);
-	}
-
-	if ( ! strcmp(buffer, "KOEN1" ) ) 
-	{
-		fprintf (stderr, "LFColorSande::extractFeatures: wrong file format\n");
-		fprintf (stderr, "img %s out %s\n", imgfile.c_str(), outputfn.c_str() );
-		fprintf (stderr, "call %s\n", call.c_str() );
-
-		exit(-1);
-	}
-    
-    
-	fgets ( buffer, buffersize, f );
-	int dimension = atoi (buffer);
-	fprintf (stderr, "LFColorSande: descriptor dimension = %d\n", dimension );
-
-	if ( (descriptor_size > 0) && (dimension != descriptor_size) )
-	{
-		fprintf (stderr, "LFColorSande::extractFeatures: dimensions do not match %d -> %d!\n",
-			 dimension, descriptor_size);
-		fprintf (stderr, "img %s out %s\n", imgfile.c_str(), outputfn.c_str() );
-		fprintf (stderr, "call %s\n", call.c_str() );
-		fprintf (stderr, "dimension std::string buffer: \"%s\"", buffer );
-		exit(-1);
-	}
-
-	fgets ( buffer, buffersize, f );
-	int noDesc = atoi (buffer);
-
-	fprintf (stderr, "LFColorSande::extractFeatures: no. of descriptors = %d\n", noDesc );
- 
-	NICE::Vector x;
-	while ( ! feof(f) ) 
-	{
-	// <CIRCLE 119 307 1.26134 0 0.00014763>; 0 0 6 2 0 6 25 7 9 4 4 0 0 4 20 36 78 4 5 0 0 
-		if ( fgets(buffer, buffersize, f) == NULL )
-			break;
-
-		const char *buffer_data = strchr ( buffer, ';' );
-		if ( strlen(buffer_data) <= 0 )
-		{
-			fprintf (stderr, "LFColorSande::extractFeatures: it seems you forget to specify a descriptor\n");
-			exit(-1);
-		}
-
-		const char *buffer_key_start = strchr ( buffer, ' ' );
-		const char *buffer_key_end = strchr ( buffer, '>' );
-		buffer_key_start++;
-		int keylen = buffer_key_end - buffer_key_start;
-		char *key = new char [keylen+1];
-		strncpy ( key, buffer_key_start, keylen );
-		key[keylen] = '\0';
-
-		buffer_data+=2;
-
-		std::string buffer_data_s (buffer_data);
-
-		//clog << "[log] buffer = " << buffer_data_s << endl;		
-		
-		StringTools::splitVector ( buffer_data_s, ' ', x );
-		if ( (int)x.size() != dimension ) 
-		{
-			cerr << "Line = " << buffer_data_s << endl;
-			cerr << "Vector = " << x << endl;
-			cerr << "dimension = " << dimension << endl;
-			cerr << "x.size() = " << x.size() << endl;
-			fprintf (stderr, "LFColorSande::extractFeatures: error parsing output !!\n");
-			exit(-1);
-		} else {
-			NICE::Vector pos;
-
-			StringTools::splitVector ( key, ' ', pos );
-
-			if ( pos.size() != 5 ) {
-				fprintf (stderr, "LFColorSande::extractFeatures: dimension mismatch (position information)\n");
-				exit(-1);
-			}
-			// Van De Sande verwendet MatLab-Darstellung der Koordinaten. Diese fangen bei 1 an und nicht bei 0.
-			pos[0] --;
-			pos[1] --;
-			positions.push_back( pos );
-			features.push_back ( x );
-		}
-	}
-
-	fclose (f);
-
-	if ( delete_imgfile )
-		FileMgt::deleteTempFile ( imgfile );
-
-	FileMgt::deleteTempFile ( outputfn );
-
-	delete [] buffer;
-
-	return 0;
+  if ( features.size() != positions.size() )
+  {
+    positions.clear();
+  }
+
+  bool delete_imgfile = false;
+  std::string imgfile = Globals::getCurrentImgFN();
+
+  fprintf ( stderr, "imgfile: %s\n", imgfile.c_str() );
+  if ( ( imgfile.size() <= 0 ) || ( ( !StringTools::regexMatch ( imgfile, ".[Jj][pP][Gg]$" ) )
+                                    && ( !StringTools::regexMatch ( imgfile, ".[Pp][Nn][Gg]$" ) ) ) )
+  {
+
+    if ( imgfile.size() <= 0 )
+    {
+      imgfile = FileMgt::createTempFile ( "/tmp/osl_lfColorSande_input_%s.png" );
+      fprintf ( stderr, "LFColorSande: write image to %s (write image)\n", imgfile.c_str() );
+      ImageFile imgf ( imgfile );
+      imgf.writer ( &img );
+    } else {
+      std::string tmpfile = FileMgt::createTempFile ( "/tmp/osl_lfColorSande_input_%s.png" );
+      fprintf ( stderr, "LFColorSande: write image to %s (convert)\n", tmpfile.c_str() );
+
+      std::string convertcall = "convert " + imgfile + " " + tmpfile;
+      cerr << "convert call: " << convertcall << endl;
+      system ( convertcall.c_str() );
+
+      imgfile = tmpfile;
+    }
+
+    delete_imgfile = true;
+  }
+
+  std::string outputfn  = FileMgt::createTempFile ( "/tmp/osl_lfColorSande_output_%s" ) ;
+
+  std::string gridparams = "";
+
+  if ( usegrid )
+    gridparams = " --detector densesampling --ds_spacing " + gridsize + " --ds_scales " + scales;
+
+  std::string call = c_binaryExecutable + " " +
+                     imgfile            + " " +
+                     c_params           +
+                     gridparams         +
+                     " -output "        + outputfn;
+
+  cerr << "LFColorSande: parameters: <" << c_params + gridparams << ">" << endl;
+  clog << "Systemcall: " << call << endl;
+
+
+  const int buffersize = 65536;
+  char *buffer = new char [buffersize];
+  FILE *f = popen ( call.c_str(), "r" );
+  if ( f == NULL )
+  {
+    fthrow ( Exception, "Unable to run the implementation of van de Sande: " << call << endl << strerror ( errno ) );
+  }
+
+  while ( ! feof ( f ) )
+  {
+    if ( fgets ( buffer, buffersize, f ) <= 0 )
+    {
+      break;
+    } else {
+      fprintf ( stderr, "LFColorSande::extractFeatures: [INFO] %s", buffer );
+    }
+  }
+
+
+  pclose ( f );
+
+  f = fopen ( outputfn.c_str(), "r" );
+  if ( f == NULL )
+  {
+    fthrow ( Exception, "Unable to read output of van de Sande implementation\n" );
+  }
+
+  if ( fgets ( buffer, buffersize, f ) <= 0 )
+  {
+    fprintf ( stderr, "LFColorSande::extractFeatures: output is empty !\n" );
+    fprintf ( stderr, "img %s out %s\n", imgfile.c_str(), outputfn.c_str() );
+    fprintf ( stderr, "call %s\n", call.c_str() );
+
+    exit ( -1 );
+  }
+
+  if ( ! strcmp ( buffer, "KOEN1" ) )
+  {
+    fprintf ( stderr, "LFColorSande::extractFeatures: wrong file format\n" );
+    fprintf ( stderr, "img %s out %s\n", imgfile.c_str(), outputfn.c_str() );
+    fprintf ( stderr, "call %s\n", call.c_str() );
+
+    exit ( -1 );
+  }
+
+
+  fgets ( buffer, buffersize, f );
+  int dimension = atoi ( buffer );
+  fprintf ( stderr, "LFColorSande: descriptor dimension = %d\n", dimension );
+
+  if ( ( descriptor_size > 0 ) && ( dimension != descriptor_size ) )
+  {
+    fprintf ( stderr, "LFColorSande::extractFeatures: dimensions do not match %d -> %d!\n",
+              dimension, descriptor_size );
+    fprintf ( stderr, "img %s out %s\n", imgfile.c_str(), outputfn.c_str() );
+    fprintf ( stderr, "call %s\n", call.c_str() );
+    fprintf ( stderr, "dimension std::string buffer: \"%s\"", buffer );
+    exit ( -1 );
+  }
+
+  fgets ( buffer, buffersize, f );
+  int noDesc = atoi ( buffer );
+
+  fprintf ( stderr, "LFColorSande::extractFeatures: no. of descriptors = %d\n", noDesc );
+
+  NICE::Vector x;
+  while ( ! feof ( f ) )
+  {
+    // <CIRCLE 119 307 1.26134 0 0.00014763>; 0 0 6 2 0 6 25 7 9 4 4 0 0 4 20 36 78 4 5 0 0
+    if ( fgets ( buffer, buffersize, f ) == NULL )
+      break;
+
+    const char *buffer_data = strchr ( buffer, ';' );
+    if ( strlen ( buffer_data ) <= 0 )
+    {
+      fprintf ( stderr, "LFColorSande::extractFeatures: it seems you forget to specify a descriptor\n" );
+      exit ( -1 );
+    }
+
+    const char *buffer_key_start = strchr ( buffer, ' ' );
+    const char *buffer_key_end = strchr ( buffer, '>' );
+    buffer_key_start++;
+    int keylen = buffer_key_end - buffer_key_start;
+    char *key = new char [keylen+1];
+    strncpy ( key, buffer_key_start, keylen );
+    key[keylen] = '\0';
+
+    buffer_data += 2;
+
+    std::string buffer_data_s ( buffer_data );
+
+    //clog << "[log] buffer = " << buffer_data_s << endl;
+
+    StringTools::splitVector ( buffer_data_s, ' ', x );
+    if ( ( int ) x.size() != dimension )
+    {
+      cerr << "Line = " << buffer_data_s << endl;
+      cerr << "Vector = " << x << endl;
+      cerr << "dimension = " << dimension << endl;
+      cerr << "x.size() = " << x.size() << endl;
+      fprintf ( stderr, "LFColorSande::extractFeatures: error parsing output !!\n" );
+      exit ( -1 );
+    } else {
+      NICE::Vector pos;
+
+      StringTools::splitVector ( key, ' ', pos );
+
+      if ( pos.size() != 5 ) {
+        fprintf ( stderr, "LFColorSande::extractFeatures: dimension mismatch (position information)\n" );
+        exit ( -1 );
+      }
+      // Van De Sande verwendet MatLab-Darstellung der Koordinaten. Diese fangen bei 1 an und nicht bei 0.
+      pos[0] --;
+      pos[1] --;
+      positions.push_back ( pos );
+      features.push_back ( x );
+    }
+  }
+
+  fclose ( f );
+
+  if ( delete_imgfile )
+    FileMgt::deleteTempFile ( imgfile );
+
+  FileMgt::deleteTempFile ( outputfn );
+
+  delete [] buffer;
+
+  return 0;
 }

+ 49 - 49
features/localfeatures/LFColorSande.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LFColorSande.h
 * @brief interface to ColorSande implementation
 * @author Erik Rodner
@@ -14,7 +14,7 @@
 
 #include "LocalFeatureRepresentation.h"
 #include "core/basics/Config.h"
-  
+
 
 namespace OBJREC {
 
@@ -22,53 +22,53 @@ namespace OBJREC {
 class LFColorSande : public LocalFeatureRepresentation
 {
 
-    protected:
-		std::string c_binaryExecutable;
-		std::string c_params;
-		double c_minScale;
-		
-		//! size of the descriptor
-		int descriptor_size;
-		
-		//! use grid for SIFT Positions
-		bool usegrid;
-	
-		//! size of the grid
-		std::string gridsize;
-	
-		//! used scales
-		std::string scales;
-		
-    public:
-  
-		/** simple constructor */
-		LFColorSande( const NICE::Config *conf, std::string section = "LFColorSande" );
-		  
-		/** simple destructor */
-		virtual ~LFColorSande();
-		
-		int getDescSize () const;
-		
-		/**
-		 * get the colorSIFT features
-		 * @param img grayvalue input image
-		 * @param features features (output)
-		 * @param positions position of the features
-		 * @return 
-		 */
-		int extractFeatures ( const NICE::Image & img, NICE::VVector & features, 
-					  NICE::VVector & positions ) const;
-		
-		/**
-		 * get the colorSIFT features
-		 * @param img color input image
-		 * @param features features (output)
-		 * @param positions position of the features
-		 * @return 
-		 */
-		int extractFeatures ( const NICE::ColorImage & img, NICE::VVector & features, 
-					  NICE::VVector & positions ) const;
-		 
+  protected:
+    std::string c_binaryExecutable;
+    std::string c_params;
+    double c_minScale;
+
+    //! size of the descriptor
+    int descriptor_size;
+
+    //! use grid for SIFT Positions
+    bool usegrid;
+
+    //! size of the grid
+    std::string gridsize;
+
+    //! used scales
+    std::string scales;
+
+  public:
+
+    /** simple constructor */
+    LFColorSande ( const NICE::Config *conf, std::string section = "LFColorSande" );
+
+    /** simple destructor */
+    virtual ~LFColorSande();
+
+    int getDescSize () const;
+
+    /**
+     * get the colorSIFT features
+     * @param img grayvalue input image
+     * @param features features (output)
+     * @param positions position of the features
+     * @return
+     */
+    int extractFeatures ( const NICE::Image & img, NICE::VVector & features,
+                          NICE::VVector & positions ) const;
+
+    /**
+     * get the colorSIFT features
+     * @param img color input image
+     * @param features features (output)
+     * @param positions position of the features
+     * @return
+     */
+    int extractFeatures ( const NICE::ColorImage & img, NICE::VVector & features,
+                          NICE::VVector & positions ) const;
+
 };
 
 

+ 15 - 0
features/localfeatures/LFColorWeijer.cpp

@@ -438,6 +438,21 @@ void LFColorWeijer::visualizeFeatures( const NICE::ColorImage & cimg, NICE::Colo
   }
 
   getDescriptors( cimg, pos, feats );
+  
+  //heatmap for a special class
+  /*ofstream fout("out.txt");
+  
+  int counter = 0;
+  for ( int y = 0; y < cimg.height(); y++ )
+  {
+    for ( int x = 0; x < cimg.width(); x++, counter++ )
+    {
+      fout << feats[counter][8] << " ";
+    }
+  }
+  cout << "counter: " << counter << " feats.size(): " << feats.size() << endl;
+  
+  fout.close();*/
 
   out.resize( cimg.width(), cimg.height() );
   out.set( 0, 0, 0 );

+ 19 - 19
features/localfeatures/progs/testColorWeijer.cpp

@@ -11,24 +11,24 @@ using namespace NICE;
 using namespace OBJREC;
 
 int main(int argc, char **argv)
-{	
-	if(argc < 1)
-	{
-		cerr << "Bitte Bild angeben" << endl;
-		return -1;
-	}
-	
-	Config *conf = new Config();
-	LFColorWeijer lfc(conf);
-		
-	//! testen
-	ColorImage cimg(argv[1]);
-	ColorImage out;
-	lfc.visualizeFeatures (cimg,out);
-	
-	cimg.writePPM("org.ppm");
-	out.writePPM("out.ppm");
-	
-	return 0;
+{
+  if (argc < 1)
+  {
+    cerr << "Bitte Bild angeben" << endl;
+    return -1;
+  }
+
+  Config *conf = new Config();
+  LFColorWeijer lfc(conf);
+
+  //! testen
+  ColorImage cimg(argv[1]);
+  ColorImage out;
+  lfc.visualizeFeatures (cimg, out);
+
+  cimg.writePPM("org.ppm");
+  out.writePPM("out.ppm");
+
+  return 0;
 }