Prechádzať zdrojové kódy

LFColorSance - Removed hard coded dependency to binary, added Exception handling, KMeans - started proper exception handling

Alexander Freytag 11 rokov pred
rodič
commit
3b7972cd7a

+ 11 - 1
features/localfeatures/LFColorSande.cpp

@@ -32,7 +32,17 @@ LFColorSande::LFColorSande ( const Config *conf, std::string section )
 {
   std::cerr << "LF COLOR SANDE SECTION ====================== :" << section << ":"<<std::endl;
   
-  c_binaryExecutable = conf->gS ( section, "binaryExecutable", "/home/bachi/libs/van_de_sande/x86_64-linux-gcc/colorDescriptor" );
+  try
+  {
+    //a possible location on dbv could be: "/home/bachi/libs/van_de_sande/x86_64-linux-gcc/colorDescriptor" );
+    c_binaryExecutable = conf->gS ( section, "binaryExecutable" /*we do not add a default here, this has to adapted to your system!!!*/); 
+  }
+  catch (NICE::Exception exception )
+  {
+    std::cerr << "\nWARNING --- Add the location where the colorDescriptor-binary is located. \n  A possible location on dbv could be: \"/home/bachi/libs/van_de_sande/x86_64-linux-gcc/colorDescriptor\" \n Source code be obtained at http://staff.science.uva.nl/~ksande/research/colordescriptors/ \n" << std::endl;
+    throw exception;
+  }
+
   c_params = conf->gS ( section, "params", "--descriptor opponentsift" );
   scales = conf->gS ( section, "scales", "1+1.5+3.0+4.5+6" );
   std::cerr << "scales: " << scales << std::endl;

+ 6 - 3
math/cluster/KMeans.cpp

@@ -12,6 +12,7 @@
 
 #include <set>
 #include <iostream>
+#include <string>
 
 #include "vislearning/math/cluster/KMeans.h"
 #include "vislearning/math/distances/genericDistance.h"
@@ -244,9 +245,11 @@ void KMeans::cluster(const NICE::VVector & features, NICE::VVector & prototypes,
       dimension = features[0].size();
   else
   {
-      fprintf(stderr,
-              "FATAL ERROR: Not enough feature vectors provided for kMeans\n");
-      exit(-1);
+    std::ostringstream stringStream;
+    stringStream << "FATAL ERROR: Not enough feature vectors provided for kMeans \n k: " << this->noClusters << " numberOfFeatures: "  << features.size()  << "\n";
+    std::string errormessage ( stringStream.str() );
+    
+    throw NICE::Exception( errormessage );
   }
 
   for (int k = 0; k < this->noClusters; k++)

+ 6 - 2
math/cluster/KMeans.h

@@ -7,14 +7,18 @@
 #ifndef KMEANSINCLUDE
 #define KMEANSINCLUDE
 
+// nice-core includes
+#include "core/basics/Exception.h"
 #include <core/basics/Config.h>
+// 
 #include <core/vector/Distance.h>
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-  
-#include "ClusterAlgorithm.h"
 #include <core/vector/Distance.h>
 
+#include "ClusterAlgorithm.h"
+
+
 namespace OBJREC {
 
 /** K-Means */