فهرست منبع

LFonHSG clean up, destructor, Generic Selection of LF and LocalFeature cleaned

Alexander Freytag 11 سال پیش
والد
کامیت
0fbdc17d69

+ 4 - 21
features/localfeatures/GenericLFSelection.h

@@ -44,7 +44,7 @@ class GenericLFSelection
        * @return LocalFeatureRepresentation* - The LocalFeatureRepresentation which contains the selected LocalFeature-Type.
        */
       static
-      LocalFeatureRepresentation *selectLocalFeatureRep ( const NICE::Config *conf, std::string section = "features", const UsageForTrainOrTest & useForTrainOrTest = NOTSPECIFIED )
+      LocalFeatureRepresentation *selectLocalFeatureRep ( const NICE::Config *conf, std::string section = "features", const UsageForTrainOrTest & useForTrainOrTest = GenericLFSelection::NOTSPECIFIED )
       {
         // return Value
         LocalFeatureRepresentation *lfrep = NULL;
@@ -85,8 +85,8 @@ class GenericLFSelection
           int numFeatures = conf->gI(section, "localfeature_count");
           lfrep = new LFPatches ( conf, numFeatures );
         } 
-        else if( ( localfeature_type == "onHSG" ) )
-        {
+        else if( localfeature_type == "onHSG" )
+        {          
           if ( useForTrainOrTest == TRAINING )
           {
             lfrep = new OBJREC::LFonHSG ( conf, "HSGTrain" );
@@ -97,7 +97,7 @@ class GenericLFSelection
           }
           else //not specified whether for training or testing, so we do not care about
           {
-            lfrep = new OBJREC::LFonHSG( conf);
+            lfrep = new OBJREC::LFonHSG( conf );
           }           
           
         }
@@ -106,23 +106,6 @@ class GenericLFSelection
           lfrep = NULL;
         }
 
-//         if ( conf->gB(section, "localfeature_cache_read", false) )
-//         {
-//           int numFeatures = conf->gI(section, "localfeature_count", -1);
-//           LocalFeatureRepresentation *lfrep_read = new LFReadCache ( conf, lfrep, numFeatures );
-//           lfrep = lfrep_read;
-//         }
-// 
-//         // no correct localfeature_type was given
-//         if ( lfrep == NULL )
-//           fthrow(NICE::Exception, "Local feature type not found: " << localfeature_type );
-// 
-//         if ( conf->gB(section, "localfeature_cache_write", false) )
-//         {
-//           LocalFeatureRepresentation *lfrep_write = new LFWriteCache ( conf, lfrep );
-//           lfrep = lfrep_write;
-//         }
-
         // read features?
         bool readfeat;
         readfeat = conf->gB ( section, "localfeature_cache_read", false );

+ 3 - 3
features/localfeatures/GenericLocalFeatureSelection.h

@@ -1,7 +1,7 @@
 /**
 * @file GenericLocalFeatureSelection.h
 * @brief This class provides a generic chooser function for different descriptors, which are derived from LocalFeature.
-* @author Eric Bach
+* @author Eric Bach, Alexander Freytag
 * @date 26.10.2011
 */
 
@@ -33,7 +33,7 @@ class GenericLocalFeatureSelection
     * @brief This methode switches between the different LocalFeature-Types. One has to set the "localfeature_type" on a valid value and the methode returns a LocalFeatureRepresentation derived Object.
     * @param[in] Config* - A pointer to the given configfile, which must contain "section" - "localfeature_type"
     * @param[in] string  - This string defines the value for "section" in the configfile.
-    * @return LocalFeatureRepresentation* - The LocalFeatureRepresentation which contains the selected LocalFeature-Type.
+    * @return LocalFeature* - The LocalFeature which contains the selected LocalFeature-Type.
     */
     static LocalFeature *selectLocalFeature ( const NICE::Config *conf, std::string section = "Features" )
     {
@@ -42,7 +42,7 @@ class GenericLocalFeatureSelection
 
       // string which defines the localfeature_type (for Ex. RGB, OppSift, Sift...)
       std::string localfeature_type = conf->gS ( section, "localfeature_type", "not defined" );
-
+      
       // The prefix NICE_* indicates that this implementation comes from a NICE-Developer.
       // Extern implementations can be added without NICE_* in this selection-class.
       if ( localfeature_type == "NICE_SIFT" )

+ 44 - 20
features/localfeatures/LFonHSG.cpp

@@ -22,44 +22,60 @@ LFonHSG::LFonHSG (const Config *conf, const string section)
   this->lf = NULL;
 
   /** get parameters for the grid **/
-  sampleScaling    = conf->gI (section, "sample_scaling", 50);
-  scales		 = conf->gS (section, "scales"        , "1");
+  this->sampleScaling = conf->gI (section, "sample_scaling", 50);
+  this->scales = conf->gS (section, "scales"        , "1");
   // the scales are seperated by '+', like in the Van de Sande implementation
   char separator = '+';
 
   /** get debuginformation **/
-  debug 		 = conf->gB ("debug", "show_log_HSG", false);
+  this->debug = conf->gB ("debug", "show_log_HSG", false);
 
   /** generate the descriptor-instanz **/
   lf = GenericLocalFeatureSelection::selectLocalFeature (conf, section);
 
   /** parse scales string **/
-  debug && clog << "[log] LocalFeatureHSG::LocalFeatureHSG" << endl;
-  debug && clog << "[log] try to parse the 'scales-string': " << scales << " -> ";
+  if ( this->debug )
+  {
+    clog << "[log] LocalFeatureHSG::LocalFeatureHSG" << std::endl;
+    clog << "[log] try to parse the 'scales-string': " << this->scales << " -> ";
+  }
 
 #ifdef NICE_USELIB_BOOST
   typedef tokenizer<boost::char_separator<char> > tokenizer;
   char_separator<char> sep (separator);
   tokenizer tokens (scales, sep);		// parse the string into tokens
-  for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
-    debug && clog << *tok_iter << " ";
+  for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
+  {
+    if ( this->debug )
+      clog << *tok_iter << " ";
+    
     scalesV.push_back(StringTools::convert<float>(*tok_iter));
   }
 #else // standard
-  vector<string> temp;
+  std::vector<std::string> temp;
   StringTools::split (scales, separator, temp);
-  for (vector<string>::const_iterator it = temp.begin(); it != temp.end(); ++it) {
-    debug && clog << *it << " ";
+  for ( std::vector<std::string>::const_iterator it = temp.begin(); it != temp.end(); ++it)
+  {
+    if ( this->debug )
+      clog << *it << " ";
+    
     scalesV.push_back(StringTools::convert<float>(*it));
-    //scalesV.push_back (strToFloat (*it));
   }
 #endif
-  debug && clog << endl;
+  if ( this->debug )
+    clog << std::endl;
 }
 
 LFonHSG::~LFonHSG()
 {
   /** free memory of descriptors **/
+  
+  // don't waste memory
+  if ( this->lf != NULL )
+  {
+    delete this->lf;
+    this->lf = NULL;
+  }
 }
 
 int LFonHSG::getDescSize() const
@@ -69,22 +85,30 @@ int LFonHSG::getDescSize() const
 
 void LFonHSG::getPositionsOnHSG (const unsigned int imageWidth, const unsigned int imageHeight, VVector& positions) const
 {
-  if (sampleScaling < 1) {
-    cerr << "[err] sample-scaling (" << sampleScaling << ") musst be larger the 0!" << endl;
+  if (sampleScaling < 1)
+  {
+    std::cerr << "[err] sample-scaling (" << sampleScaling << ") musst be larger the 0!" << std::endl;
     return;
   }
 
-  debug && clog << "[log] LocalFeatureHSG::getPositionsOnHSG calculate ";
+  if ( this->debug )
+    clog << "[log] LocalFeatureHSG::getPositionsOnHSG calculate ";
 
   bool oddRow = true;
   NICE::Vector pos (4);
 
   /** we have to calculate the koo. for every different scale **/
-  for (vector <float>::const_iterator it = scalesV.begin(); it != scalesV.end(); ++it) {
+  for ( std::vector<float>::const_iterator it = this->scalesV.begin(); it != this->scalesV.end(); ++it)
+  {
     oddRow = true;
 
-    for (unsigned int j = sampleScaling; j <= (imageHeight - sampleScaling); j += sampleScaling) {
-      for (unsigned int i = (oddRow ? sampleScaling + sampleScaling / 2 : sampleScaling); i <= (imageWidth - sampleScaling); i += sampleScaling) {
+    for (unsigned int j = sampleScaling; j <= (imageHeight - sampleScaling); j += sampleScaling)
+    {
+      for ( unsigned int i = (oddRow ? sampleScaling + sampleScaling / 2 : sampleScaling);
+            i <= (imageWidth - sampleScaling);
+            i += sampleScaling
+          )
+      {
         pos[ 0 ] = i;
         pos[ 1 ] = j;
         pos[ 2 ] = *it;
@@ -99,7 +123,7 @@ void LFonHSG::getPositionsOnHSG (const unsigned int imageWidth, const unsigned i
 int LFonHSG::extractFeatures (const NICE::ColorImage & cimg, VVector & features, VVector & positions) const
 {
   /** To get the keypoint descriptor, we need the positions of the keypoints. **/
-  getPositionsOnHSG (cimg.width(), cimg.height(), positions);
+  this->getPositionsOnHSG (cimg.width(), cimg.height(), positions);
 
   /** calulate the descriptor-values **/
   return lf->getDescriptors (cimg, positions, features);
@@ -109,7 +133,7 @@ int LFonHSG::extractFeatures (const NICE::ColorImage & cimg, VVector & features,
 int LFonHSG::extractFeatures (const NICE::Image & img, VVector & features, VVector & positions) const
 {
   /** To get the keypoint descriptor, we need the positions of the keypoints. **/
-  getPositionsOnHSG (img.width(), img.height(), positions);
+  this->getPositionsOnHSG (img.width(), img.height(), positions);
 
   /** calculate the descriptor-values **/
   return lf->getDescriptors (img, positions, features);

+ 15 - 15
features/localfeatures/LFonHSG.h

@@ -1,8 +1,8 @@
 /**
 * @file LFonHSG.h
-* @brief This class can be used to calculate the positions of keyfeatures in a Honeyrate Structure Grid (HSG). Also the class call the normal getDescriptors methode from a given type of SIFT.
-* @author Eric Bach
-* @date 26.10.2011
+* @brief This class can be used to calculate the positions of keyfeatures in a Honeyrate Structure Grid (HSG). Also the class call the normal getDescriptors methode from a given type of LocalFeature.
+* @author Eric Bach, Alexander Freytag
+* @date 26-10-2011 (dd-mm-yyyy)
 */
 
 #ifndef LFonHSGINCLUDE
@@ -15,11 +15,13 @@
 #include <vector>
 
 /** NICE includes **/
-#include <core/image/Convert.h>
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
 #include <core/basics/Config.h>
+// 
+#include <core/image/Convert.h>
+#include <core/image/ImageT.h>
+// 
+#include <core/vector/VectorT.h>
+#include <core/vector/MatrixT.h>
 #include <core/vector/VVector.h>
 
 /** LocalFeature*-header includes **/
@@ -49,6 +51,12 @@ class LFonHSG : public LocalFeatureRepresentation
     //! vector which save the different scales
     std::vector <float> scalesV;
 
+    //! if true, print some log-output
+    bool debug;
+
+    //! the descriptor instance
+    OBJREC::LocalFeature* lf;    
+    
     /** Calculate the keypoint-positions by given imagesize, sample-spacing and scales.
         @brief The methode returns the calculated positions on a honeyrate-grid. This
         positions starts with (0;0).
@@ -60,14 +68,6 @@ class LFonHSG : public LocalFeatureRepresentation
                              const unsigned int imageHeight,
                              NICE::VVector& positions ) const;
 
-    //! simple methode to convert a string into float
-    float strToFloat ( const std::string str ) const;
-
-    //! if true, print some log-output
-    bool debug;
-
-    //! the descriptor instance
-    LocalFeature* lf;
 
     /* public member */
   public: