소스 검색

sift gpu anpassungen eric bach

bach 13 년 전
부모
커밋
db59b98ef9

+ 31 - 43
features/localfeatures/LocalFeatureRGBSift.cpp

@@ -1,11 +1,4 @@
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include <iostream>
-
-#include "vislearning/features/localfeatures/sift.h"
-#include "vislearning/features/localfeatures/LocalFeatureRGBSift.h"
+#include "objrec/features/localfeatures/LocalFeatureRGBSift.h"
 
 using namespace OBJREC;
 using namespace std;
@@ -22,37 +15,38 @@ LocalFeatureRGBSift::~LocalFeatureRGBSift()
 
 }
 
-int LocalFeatureRGBSift::getDescriptors (const NICE::ColorImage & img,
-    VVector & positions,
-    VVector & descriptors) const
+int 
+LocalFeatureRGBSift::getDescriptors (const NICE::ColorImage & img, VVector & positions, VVector & descriptors) const
 {
-  sortPositions (positions);
-  descriptors.clear();
-  // Fuer jede Position wird ein leerer NICE::Vector in descriptors eingefuegt
-  for (int i = 0; i < (int) positions.size(); i++) {
-    NICE::Vector v;
-    descriptors.push_back (v);
-  }
-
-  vector<VVector> desc (3);
+	sortPositions (positions);
+	descriptors.clear();
+	for (int i = 0; i < (int) positions.size(); i++) 
+	{
+		NICE::Vector v;
+		descriptors.push_back (v);
+	}
 
-  // Maximale Anzahl an Thread ist abhaengig von der Anzahl der verfuegbaren Grafikkarten
-  // bzw. (wenn siftGPU nicht genutzt wird) von der Anzahl der Prozessoren
-  const int numberOfGPU = getNumOfDevices();
-  const int numberOfCPU = omp_get_num_procs();
+	vector<VVector> desc (3);
 
-  if (numberOfGPU == -1) { // siftGPU wird nicht genutzt
-    omp_set_num_threads (numberOfCPU);
-  }
-  else if (numberOfGPU == 0) {
-    fthrow (Exception, "No Devices");
-  }
-  else { // siftGPU wird genutzt: LocalFeatureSiftGPU kuemmert sich um die threads.
-    omp_set_num_threads (numberOfGPU);
-  }
+#ifdef NICE_USELIB_OPENMP
+	// check whether siftGPU should be used
+	int numberOfCPU = omp_get_num_procs();
+	int numberOfThreads = 0;
+	if (isGpuUsed()) 
+	{ 
+		// in case of siftGPU it is possible to use one device
+		numberOfThreads = 1;
+		clog << "[log] LocalFeatureRGBSift: no multithreading" << endl;
+	}
+	else 
+	{
+		// in case of siftpp it is possible to use all given cores
+		numberOfThreads = numberOfCPU;
+		clog << "[log] LocalFeatureRGBSift: multithreading with (max) " << numberOfCPU << " threads" << endl;
+	}
+#endif
 
-#pragma omp parallel for
-  // Descriptor fuer jeden der 3 Kanaele berechnen
+#pragma omp parallel for num_threads(numberOfThreads)
   for (int i = 0; i < 3; i++) {
     NICE::Image tmp (img.width(), img.height());
 
@@ -65,23 +59,17 @@ int LocalFeatureRGBSift::getDescriptors (const NICE::ColorImage & img,
     computeDesc (tmp, pos, desc[i]);
   }
 
-  // ab hier stehen wird nur noch mit dem Prozessor gerechnet
-  omp_set_num_threads (numberOfCPU);
-
-  // ?
-  //desc[0] = desc[2];
   for (int i = 0; i < 3; i++) {
     assert (desc[i].size() == descriptors.size());
 
     if (i == 0) {
-#pragma omp parallel for
+#pragma omp parallel for num_threads( numberOfCPU )
       for (int j = 0; j < (int) desc[i].size(); j++) {
-        // kopiere den roten (1.)-Kanal in den Descriptorsvektor
         descriptors[j] = desc[i][j];
       }
     }
     else {
-#pragma omp parallel for
+#pragma omp parallel for num_threads( numberOfCPU )
       for (int j = 0; j < (int) desc[i].size(); j++) {
         descriptors[j].append (desc[i][j]);
       }

+ 42 - 42
features/localfeatures/LocalFeatureRGBSift.h

@@ -1,20 +1,22 @@
-/**
+/** 
 * @file LocalFeatureRGBSift.h
 * @brief local feature with color sift
-* @author Björn Fröhlich
-* @date 03/08/2010
+* @author Björn Fröhlich
+* @date 03/10/2012 (Eric Bach)
 */
 
 #ifndef LocalFeatureRGBSiftINCLUDE
 #define LocalFeatureRGBSiftINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-
-#include "core/basics/Config.h"
+#include "vislearning/baselib/Config.h"
 #include "vislearning/features/localfeatures/LocalFeatureSift.h"
+#include "vislearning/features/localfeatures/sift.h"
+
+#ifdef NICE_USELIB_OPENMP
+#include <omp.h>
+#endif
 
+#include <iostream>
 
 namespace OBJREC {
 
@@ -22,40 +24,38 @@ namespace OBJREC {
 class LocalFeatureRGBSift : public LocalFeatureSift
 {
 
-  protected:
-    int octaves;
-    int levels;
-    bool normalizeFeature;
-    int first_octave;
-    double magnif;
-
-  public:
-
-    /** simple constructor */
-    LocalFeatureRGBSift ( const NICE::Config *conf );
-
-    /** simple destructor */
-
-    virtual ~LocalFeatureRGBSift();
-
-    /**
-     * returns the size of each the SIFT-Feature
-     * @return 128
-     */
-    int getDescSize() const {
-      return 384;
-    };
-
-    /**
-     * get the descriptor
-     * @param img input color image
-     * @param positions positions for the SIFT features
-     * @param descriptors output
-     * @return 0
-     */
-    virtual int getDescriptors ( const NICE::ColorImage & cimg,
-                                 NICE::VVector & positions,
-                                 NICE::VVector & descriptors ) const;
+    protected:
+	int octaves;
+	int levels;
+	bool normalizeFeature;
+	int first_octave;
+	double magnif;
+
+    public:
+  
+	/** simple constructor */
+	LocalFeatureRGBSift ( const Config *conf );
+      
+	/** simple destructor */
+
+	virtual ~LocalFeatureRGBSift();
+	
+	/**
+	 * returns the size of each the SIFT-Feature
+	 * @return 128
+	 */
+	int getDescSize() const { return 384; };
+	
+	/** 
+	 * get the descriptor
+	 * @param img input color image
+	 * @param positions positions for the SIFT features
+	 * @param descriptors output
+	 * @return 0
+	 */
+	virtual int getDescriptors ( const NICE::ColorImage & cimg, 
+			     VVector & positions,
+			     VVector & descriptors ) const;     
 };
 
 

+ 229 - 158
features/localfeatures/LocalFeatureSift.cpp

@@ -2,102 +2,160 @@
 * @file LocalFeatureSift.cpp
 * @brief local feature with sift
 * @author Erik Rodner
-* @date 02/05/2008
+* @date 03/10/2012
 */
-#include <iostream>
-
-#include "vislearning/features/localfeatures/sift.h"
-#include "vislearning/features/localfeatures/LocalFeatureSift.h"
-#include "LocalFeatureSiftGPU.h"
+#include "objrec/features/localfeatures/LocalFeatureSift.h"
 
 
 using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-LocalFeatureSift::LocalFeatureSift ( const Config *conf )
+LocalFeatureSift::LocalFeatureSift( const Config *conf )
 {
-  this->conf = conf;
-
-  octaves          = conf->gI ( "LFSiftPP", "octaves",    6 );
-  levels           = conf->gI ( "LFSiftPP", "levels",    3 );
-  first_octave     = conf->gI ( "LFSiftPP", "first_octave",   -1 );
-  normalizeFeature = conf->gB ( "LFSiftPP", "normalize_feature",  true );
-  magnif       = conf->gD ( "LFSiftPP", "magnif",    3 );
-  deletemode       = conf->gB ( "LFSiftPP", "deletemode",   true );
-  integerValues    = conf->gB ( "LFSiftPP", "integer_values",   true );
-  usegpu       = conf->gB ( "LFSiftPP", "use_siftgpu",  false );
-
-  if ( usegpu ) numOfGPU = conf->gI ( "SIFTGPU", "numgpu", 1 );
-  else numOfGPU = -1;
+    this->conf = conf;
+
+    octaves          = conf->gI("LFSiftPP", "octaves", 			6);
+    levels           = conf->gI("LFSiftPP", "levels", 			3);
+    first_octave     = conf->gI("LFSiftPP", "first_octave", 	-1);
+    normalizeFeature = conf->gB("LFSiftPP", "normalize_feature", true );
+    magnif 	         = conf->gD("LFSiftPP", "magnif", 			3 );
+    deletemode       = conf->gB("LFSiftPP", "deletemode", 		true );
+    integerValues    = conf->gB("LFSiftPP", "integer_values", 	true );
+
+#ifdef NICE_USELIB_CUDASIFT
+    usegpu 	     	 = conf->gB("LFSiftPP", "use_siftgpu",		false );
+#else
+	usegpu = false;
+#endif
 }
 
 LocalFeatureSift::~LocalFeatureSift()
 {
 }
 
-void LocalFeatureSift::sortPositions ( VVector & positions ) const
+void LocalFeatureSift::sortPositions(VVector & positions) const
 {
-  // < Key  , Val >
-  map<double, bool> scales;
-
-  // in der Map entpsrechende Skalewerte auf true setzten, jeder Skalewert ist dabei einzigartig
-  for ( vector< NICE::Vector >::iterator i  = positions.begin();
-        i != positions.end();i++ )
-  {
-    const NICE::Vector & pos = *i;
-    scales[pos[2]] = true;
-  }
-
-  VVector newpositions;
-
-  map<double, bool>::iterator iter;
-  // Map durchlaufen
-  for ( iter = scales.begin(); iter != scales.end(); ++iter )
-  {
-    // alle Positionen durchlaufen
+    // < Key  , Val >
+    map<double, bool> scales;
+
     for ( vector< NICE::Vector >::iterator i  = positions.begin();
-          i != positions.end();i++ )
+            i != positions.end();i++)
+    {
+        const NICE::Vector & pos = *i;
+        scales[pos[2]] = true;
+    }
+
+    VVector newpositions;
+
+    map<double,bool>::iterator iter;
+    for ( iter = scales.begin(); iter != scales.end(); ++iter )
+    {
+        for ( vector< NICE::Vector >::iterator i  = positions.begin();
+                i != positions.end();i++)
+        {
+
+            const NICE::Vector & pos = *i;
+            if (pos[2] == iter->first)
+            {
+                newpositions.push_back(pos);
+            }
+        }
+    }
+    positions = newpositions;
+}
+
+void LocalFeatureSift::computeDesc( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
+{
+    if ( usegpu ) {
+        try {
+#ifdef NICE_USELIB_CUDASIFT
+            withGPU( img, positions, descriptors );
+#endif
+        }
+        catch ( runtime_error& rte ) {
+            cerr << "[err] LocalFeatureSift: " << rte.what() << endl;
+            clog << "[log] use SIFTPP implementation:" << endl;
+            withPP( img, positions, descriptors );
+        }
+    }
+    else {
+        withPP( img, positions, descriptors );
+    }
+}
+
+int LocalFeatureSift::getDescriptors ( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
+{
+    sortPositions(positions);
+
+    computeDesc(img, positions, descriptors);
+
+    return 0;
+}
+
+void LocalFeatureSift::visualizeFeatures ( NICE::Image & mark, const VVector & positions, size_t color ) const
+{
+	/* TODO: switch to NICE instead of ICE
+    ice::Image mark_ice = ice::NewImg ( mark.width(),
+                                        mark.height(), 255 );
+    for ( size_t k = 0 ; k < positions.size() ; k++ )
     {
+        const NICE::Vector & pos = positions[k];
+        ice::Matrix points ( 0, 2 );
+        const int size = 6;
+        points.Append ( ice::Vector(-size, -size) );
+        points.Append ( ice::Vector(-size, size) );
+        points.Append ( ice::Vector(size, size) );
+        points.Append ( ice::Vector(size, -size) );
+
+        ice::Trafo tr;
+
+        tr.Scale ( 0, 0, pos[2] );
+        tr.Rotate ( 0, 0, pos[3] );
+        tr.Shift ( pos[0], pos[1] );
 
-      const NICE::Vector & pos = *i;
-      if ( pos[2] == iter->first )
-      {
-        newpositions.push_back ( pos );
-      }
+        ice::TransformList(tr, points);
+
+        for ( int j = 0 ; j < points.rows(); j++ )
+        {
+            if (points[j][0] < 0 )
+                points[j][0] = 0;
+            if (points[j][0] >= mark_ice->xsize)
+                points[j][0] = mark_ice->xsize - 1;
+            if (points[j][1] < 0 )
+                points[j][1] = 0;
+            if (points[j][1] >= mark_ice->ysize)
+                points[j][1] = mark_ice->ysize - 1;
+        }
+        ice::DrawPolygon ( points, color, mark_ice );
     }
-  }
-  positions = newpositions;
+
+    for ( unsigned int y = 0 ; y < mark.height(); y++ )
+        for ( unsigned int x = 0 ; x < mark.width(); x++ )
+            mark.setPixel(x,y, GetVal(mark_ice,x,y));*/
 }
 
-void LocalFeatureSift::computeDesc ( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
+void LocalFeatureSift::withPP( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
 {
-  if ( usegpu )
-  {
-    LocalFeatureSiftGPU sift ( conf );
-    sift.computeDesc ( img, positions, descriptors );
-  }
-  else
-  {
     int         O      = octaves ;
     int const   S      = levels ;
     int const   omin   = first_octave;
     float const sigman = .5 ; //.5
-    float const sigma0 = 1.6 * powf ( 2.0f, 1.0f / S ) ;
+    float const sigma0 = 1.6 * powf(2.0f, 1.0f / S) ;
 
-    if ( O < 1 )
+    if (O < 1)
     {
-      O = std::max ( int ( std::floor ( log2
-                                        ( std::min ( img.width(), img.height() ) ) ) - omin - 3 ), 1 ) ;
+        O = std::max(int(std::floor(log2
+                                    (std::min(img.width(),img.height()))) - omin - 3), 1) ;
     }
 
-    const unsigned char *blockimg = ( unsigned char* ) img.getPixelPointer();
-    float *blockimgfl = new float[img.width() * img.height() ];
+    const unsigned char *blockimg = (unsigned char*) img.getPixelPointer();
+    float *blockimgfl = new float[img.width() * img.height()];
     for ( int k = 0 ; k < img.width() * img.height() ; k++ )
-      blockimgfl[k] = blockimg[k];
+        blockimgfl[k] = blockimg[k];
 
-    VL::Sift sift ( blockimgfl, img.width(), img.height(),
-                    sigman, sigma0, O, S, omin, -1, S + 1 ) ;
+    VL::Sift sift( blockimgfl, img.width(), img.height(),
+                   sigman, sigma0, O, S, omin, -1, S+1) ;
 
     sift.process ( blockimgfl, img.width(), img.height() );
 
@@ -108,118 +166,131 @@ void LocalFeatureSift::computeDesc ( const NICE::Image & img, VVector & position
     VL::float_t *descr_pt = new VL::float_t [descr_size];
     VL::float_t angles[4] ;
 
-    NICE::Vector feature ( descr_size );
-    NICE::Vector pos ( 4 );
+    NICE::Vector feature (descr_size);
+    NICE::Vector pos     ( 4 );
 
 
     for ( vector< NICE::Vector >::iterator i  = positions.begin();
-          i != positions.end(); )
+            i != positions.end();)
     {
-      const NICE::Vector & pos = *i;
-      double x = pos[0];
-      double y = pos[1];
-      assert ( pos[0] < img.width() );
-      assert ( pos[1] < img.height() );
-      double s = pos[2];
-      bool deleteFeature = false;
-      VL::Sift::Keypoint kp = sift.getKeypoint ( x, y, s );
-
-      double angle = 0.0;
-
-      if ( pos.size() < 4 )
-      {
-        int nangles = sift.computeKeypointOrientations ( angles, kp );
-
-        if ( nangles > 0 )
+        const NICE::Vector & pos = *i;
+        double x = pos[0];
+        double y = pos[1];
+        assert(pos[0] < img.width());
+        assert(pos[1] < img.height());
+        double s = pos[2];
+        bool deleteFeature = false;
+        VL::Sift::Keypoint kp = sift.getKeypoint (x,y,s);
+
+        double angle = 0.0;
+
+        if ( pos.size() < 4 )
         {
-          angle = angles[0];
+            int nangles = sift.computeKeypointOrientations(angles, kp);
+
+            if ( nangles > 0 )
+            {
+                angle = angles[0];
+            }
+            else
+            {
+                if (deletemode)
+                    deleteFeature = true;
+                else
+                    angle = 0;
+            }
         }
         else
         {
-          if ( deletemode )
-            deleteFeature = true;
-          else
-            angle = 0;
+            angle = pos[3];
+        }
+
+        if ( ! deleteFeature )
+        {
+            sift.computeKeypointDescriptor ( descr_pt, kp, angle );
+            for ( int j = 0 ; j < descr_size ; j++ )
+                // Umwandlung in Integer moegl.
+                feature[j] = (integerValues ? (int)(512*descr_pt[j]) : descr_pt[j]);
+
+            descriptors.push_back ( feature );
+
+            i++;
+        }
+        else
+        {
+            i = positions.erase(i);
         }
-      }
-      else
-      {
-        angle = pos[3];
-      }
-
-      if ( ! deleteFeature )
-      {
-        sift.computeKeypointDescriptor ( descr_pt, kp, angle );
-        for ( int j = 0 ; j < descr_size ; j++ )
-          // Umwandlung in Integer moegl.
-          feature[j] = ( integerValues ? ( int ) ( 512 * descr_pt[j] ) : descr_pt[j] );
-
-        descriptors.push_back ( feature );
-
-        i++;
-      }
-      else
-      {
-        i = positions.erase ( i );
-      }
     }
 
     delete [] blockimgfl;
     delete [] descr_pt;
-  }
 }
 
-int LocalFeatureSift::getDescriptors ( const NICE::Image & img, VVector & positions, VVector & descriptors ) const
+#ifdef NICE_USELIB_CUDASIFT
+void LocalFeatureSift::withGPU(const NICE::Image& img, OBJREC::VVector& positions, OBJREC::VVector& descriptors) const
 {
-  sortPositions ( positions );
+    // fill the parameter for
+    char* argv[] = {
+        // First octave to detect DOG keypoints
+        "-fo" , const_cast<char*> (StringTools::convertToString<int> (first_octave).c_str()),
+        // Maximum number of Octaves
+        "-no" , const_cast<char*> (StringTools::convertToString<int> (octaves).c_str()),
+        // Number of DOG levels in an octave.
+        "-d"  , const_cast<char*> (StringTools::convertToString<int> (levels).c_str()),
+        // Write unnormalized descriptor if specified.
+        const_cast<char*> (normalizeFeature ? "" : "-unn"),
+        // Descriptor grid size factor (magnif ??)
+        "-dw" , const_cast<char*> (StringTools::convertToString<float> (magnif).c_str()),
+        // verbose levels
+        "-v", "0"
+    };
+    int argc = sizeof (argv) / sizeof (char*);
+
+    // sift Instanz
+    SiftGPU sift;
+
+    // give parameter to sift
+    sift.ParseParam (argc, argv);
+
+    // check, whether siftgpu is full supported
+    int support = sift.CreateContextGL();
+    if( support != SiftGPU::SIFTGPU_FULL_SUPPORTED )
+      throw runtime_error( "SiftGPU-support is not given by your device.");
+
+    // set keypoints
+    const int numberOfKeypoints = positions.size();
+    SiftGPU::SiftKeypoint keys[numberOfKeypoints];
+
+    // copy the NICEKeypoints into SiftKeypoints
+    for (int i = 0; i < numberOfKeypoints; i++) {
+        keys[i].x = positions[i][0];
+        keys[i].y = positions[i][1];
+        keys[i].s = positions[i][2];
+        keys[i].o = positions[i][3];
+    }
+    sift.SetKeypointList (numberOfKeypoints, keys);
 
-  computeDesc ( img, positions, descriptors );
+    // run SIFT
+    const int imageWidth  = img.width();
+    const int imageHeight = img.height();
+    const unsigned char* rawImageData = img.getPixelPointer();
 
-  return 0;
-}
+    sift.RunSIFT (imageWidth, imageHeight, rawImageData, GL_LUMINANCE, GL_UNSIGNED_BYTE);
 
-void LocalFeatureSift::visualizeFeatures ( NICE::Image & mark,
-    const VVector & positions,
-    size_t color ) const
-{
-  /*TODO: switch to NICE instead of ICE
-  ice::Image mark_ice = ice::NewImg ( mark.width(),
-                                      mark.height(), 255 );
-  for ( size_t k = 0 ; k < positions.size() ; k++ )
-  {
-    const NICE::Vector & pos = positions[k];
-    ice::Matrix points ( 0, 2 );
-    const int size = 6;
-    points.Append ( ice::Vector ( -size, -size ) );
-    points.Append ( ice::Vector ( -size, size ) );
-    points.Append ( ice::Vector ( size, size ) );
-    points.Append ( ice::Vector ( size, -size ) );
-
-    ice::Trafo tr;
-
-    tr.Scale ( 0, 0, pos[2] );
-    tr.Rotate ( 0, 0, pos[3] );
-    tr.Shift ( pos[0], pos[1] );
-
-    ice::TransformList ( tr, points );
-
-    for ( int j = 0 ; j < points.rows(); j++ )
-    {
-      if ( points[j][0] < 0 )
-        points[j][0] = 0;
-      if ( points[j][0] >= mark_ice->xsize )
-        points[j][0] = mark_ice->xsize - 1;
-      if ( points[j][1] < 0 )
-        points[j][1] = 0;
-      if ( points[j][1] >= mark_ice->ysize )
-        points[j][1] = mark_ice->ysize - 1;
+    // get descriptors
+    const int descr_size = 128;
+    const int numberOfDescriptors = sift.GetFeatureNum();
+    float desc[descr_size * numberOfDescriptors];
+
+    sift.GetFeatureVector (NULL, desc);
+
+    Vector localDesc (descr_size);
+    // copy the SiftDescriptors into NICEDescriptors
+    for (int i = 0; i < numberOfDescriptors; i++) {
+        for (int j = 0; j < descr_size; j++) {
+            localDesc[j] = (integerValues ? (int) (512 * desc[i*descr_size+j]) : desc[i*descr_size+j]);
+        }
+        descriptors.push_back (localDesc);
     }
-    ice::DrawPolygon ( points, color, mark_ice );
-  }
-
-  for ( unsigned int y = 0 ; y < mark.height(); y++ )
-    for ( unsigned int x = 0 ; x < mark.width(); x++ )
-      mark.setPixel ( x, y, GetVal ( mark_ice, x, y ) );
-    */
-  throw("not yet implemented");
 }
+#endif

+ 49 - 36
features/localfeatures/LocalFeatureSift.h

@@ -2,30 +2,35 @@
 * @file LocalFeatureSift.h
 * @brief local feature with sift
 * @author Erik Rodner
-* @date 02/05/2008
-
+* @date 03/10/2012 (Eric Bach)
+* @note some notes to the use of siftGPU (added by Eric Bach)
+*		- install cudaSift & siftGPU (see Makefile.config)
+*		- add to libdepend.inc: $(call PKG_DEPEND_EXT, CUDASIFT) to specify: -DNICE_USELIB_CUDASIFT as compilerflag
+*		- add to section [LFSiftPP] use_siftgpu=true (or 'false' to disable the gpu-support)
+*		
+*		If you use the gpu-support just one device is supported until now.
+*		If your device do not support the siftGPU completly the class switch to "normal" sift.
+*		It is possible to compile this class without siftGPU, but then you must not specify the flag: -DNICE_USELIB_CUDASIFT.
 */
 #ifndef LOCALFEATURESIFTINCLUDE
 #define LOCALFEATURESIFTINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
-
-#include "core/basics/Config.h"
-
-// SIFTGPU includes
-#include <src/SiftGPU.h>
-
-// GL includes
-#include <GL/gl.h>
-
-#include "core/basics/Config.h"
+// NICE includes
+#include <objrec/baselib/StringTools.h>
+#include <objrec/baselib/Config.h>
 #include "LocalFeature.h"
+#include "sift.h"
+
+// std includes
+#include <iostream>
+#include <string>
+#include <stdexcept>
 
-// GLEW include
-//#include <GL/glew.h>
+// SiftGPU & GL
+#ifdef NICE_USELIB_CUDASIFT
+		#include <src/SiftGPU.h>
+		#include <GL/gl.h>
+#endif
 
 
 namespace OBJREC {
@@ -33,10 +38,10 @@ namespace OBJREC {
 /** local feature with sift */
 class LocalFeatureSift : public LocalFeature
 {
-  private:
-    const NICE::Config* conf;
+private:
+    const Config* conf;
 
-  protected:
+protected:
     int octaves;
     int levels;
     bool normalizeFeature;
@@ -47,15 +52,19 @@ class LocalFeatureSift : public LocalFeature
 
     // for SiftGPU
     bool usegpu;
-    int numOfGPU;
 
     float threshold;
     float edgeThreshold;
 
-  public:
+    void withPP( const NICE::Image & img, VVector & positions, VVector & descriptors ) const;
+#ifdef NICE_USELIB_CUDASIFT
+    void withGPU( const NICE::Image & img, VVector & positions, VVector & descriptors ) const;
+#endif
+
+public:
 
     /** simple constructor */
-    LocalFeatureSift ( const NICE::Config *conf );
+    LocalFeatureSift ( const Config *conf );
 
     /** simple destructor */
 
@@ -66,15 +75,17 @@ class LocalFeatureSift : public LocalFeature
      * @return 128
      */
     int getDescSize() const {
-      return 128;
+        return 128;
     };
 
-    /**
-     * returns the number of devices
-     * @return { -1 : sift without gpu, n (given devices) else }
-     */
-    int getNumOfDevices () const {
-      return numOfGPU;
+
+    //! returns true if gpu is used
+    bool isGpuUsed() const {
+#ifdef NICE_USELIB_CUDASIFT
+        return usegpu;
+#else
+		return false;
+#endif
     };
 
     /**
@@ -85,8 +96,8 @@ class LocalFeatureSift : public LocalFeature
      * @return 0
      */
     virtual int getDescriptors ( const NICE::Image & img,
-                                 NICE::VVector & positions,
-                                 NICE::VVector & descriptors ) const;
+                                 VVector & positions,
+                                 VVector & descriptors ) const;
 
     /**
      * computes the descriptor for a single image
@@ -94,15 +105,17 @@ class LocalFeatureSift : public LocalFeature
      * @param positions
      * @param descriptors
      */
-    void computeDesc ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors ) const;
+    void computeDesc( const NICE::Image & img, VVector & positions, VVector & descriptors ) const;
 
     /**
      * sort positions by scales for faster computing of the Keypoint orientation
      * @param positions
      */
-    void sortPositions ( NICE::VVector & positions ) const;
+    void sortPositions(VVector & positions) const;
+
+    void visualizeFeatures ( NICE::Image & mark, const VVector & positions, size_t color ) const;
+
 
-    void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
 
 
 };

+ 0 - 145
features/localfeatures/LocalFeatureSiftGPU.cpp

@@ -1,145 +0,0 @@
-/**
-* @file LocalFeaturesiftGPU.cpp
-* @brief A Sift-Implementation, which uses the GPU.
-* @author Eric Bach
-* @date 11/20/2011
-*/
-
-#include "LocalFeatureSiftGPU.h"
-
-#include "core/basics/StringTools.h"
-
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-LocalFeatureSiftGPU::LocalFeatureSiftGPU (const Config* conf) : LocalFeatureSift (conf)
-{
-  const string section = "SIFTGPU";
-
-  gpuLanguage = conf->gS (section, "language", "cuda");
-  multiGPU    = conf->gB (section, "multigpu",  false);
-  numOfGPU    = conf->gI (section, "numgpu"  ,      1);
-
-  // for multiGPU its neccessary, that you got more the one devices
-  /*if( multiGPU && ( numOfGPU < 2 ) )
-    fthrow( Exception, "For multiple GPU, you need more the one device!");
-
-  // fill deviceStat: all devices are unused (=free)
-  for( unsigned int i=0; i < numOfGPU; i++ )
-    deviceStat.insert(pair<unsigned int, bool>(i, true));*/
-}
-
-LocalFeatureSiftGPU::~LocalFeatureSiftGPU ()
-{
-}
-
-int LocalFeatureSiftGPU::getNextDeviceID()
-{
-  StatTable::iterator it = deviceStat.begin();
-  for (; it != deviceStat.end(); ++it) {
-    bool free = it->second;
-    if (free) {
-      it->second = !free;
-      return it->first;
-    }
-  }
-  // no free device was found
-  return -1;
-}
-
-void LocalFeatureSiftGPU::releaseDevice (int id)
-{
-  StatTable::iterator it = deviceStat.find (id);
-  // if given id is associated with a device, set this gpu on free
-  if (it != deviceStat.end()) it->second = true;
-}
-
-void LocalFeatureSiftGPU::computeDesc (const NICE::Image & img, VVector & positions, VVector & descriptors) const
-{
-  // fill the parameter for
-  //char device[2] = {'0' + deviceID, '\0'};
-  char* argv[] = {
-    // First octave to detect DOG keypoints
-    "-fo" , const_cast<char*> (StringTools::convertToString<int> (first_octave).c_str()),
-    // Maximum number of Octaves
-    "-no" , const_cast<char*> (StringTools::convertToString<int> (octaves).c_str()),
-    // Number of DOG levels in an octave.
-    "-d"  , const_cast<char*> (StringTools::convertToString<int> (levels).c_str()),
-    // Write unnormalized descriptor if specified.
-    const_cast<char*> (normalizeFeature ? "" : "-unn"),
-    // Descriptor grid size factor (magnif ??)
-    "-dw" , const_cast<char*> (StringTools::convertToString<float> (magnif).c_str()),
-    // use cuda / which device TODO
-    const_cast<char*> (gpuLanguage == "cuda" ? "-cuda" : "-pack"),  const_cast<char*> (gpuLanguage == "cuda" ? "0" : ""),
-    // verbose levels
-    "-v", "0"
-  };
-  int argc = sizeof (argv) / sizeof (char*);
-
-  // sift Instanz
-  SiftGPU sift;
-
-  // give parameter to sift
-  sift.ParseParam (argc, argv);
-
-  // check, whether siftgpu is full supported
-  const int support = sift.CreateContextGL();
-//   const int support = sift.VerifyContextGL();
-  /*if( support == SiftGPU::SIFTGPU_PARTIAL_SUPPORTED ) 
-    clog << "·[log] LocalFeatureSift: SIFTGPU spartial supported" << endl;*/
-  
-  if ( support != SiftGPU::SIFTGPU_FULL_SUPPORTED) {
-    fthrow( Exception, "LocalFeatureSift: Its not able to use SIFTGPU, because it is not supported." );
-  }
-  else{ clog << "[log] LocalFeatureSift: SIFTGPU full supported" << endl; }
-
-  // set keypoints
-  const int numberOfKeypoints = positions.size();
-  SiftGPU::SiftKeypoint keys[numberOfKeypoints];
-
-  // copy the NICEKeypoints into SiftKeypoints
-  for (int i = 0; i < numberOfKeypoints; i++) {
-    keys[i].x = positions[i][0];
-    keys[i].y = positions[i][1];
-    keys[i].s = positions[i][2];
-    keys[i].o = positions[i][3];
-  }
-  sift.SetKeypointList (numberOfKeypoints, keys);
-
-  // run SIFT
-  const int imageWidth  = img.width();
-  const int imageHeight = img.height();
-  const unsigned char* rawImageData = img.getPixelPointer();
-
-  sift.RunSIFT (imageWidth, imageHeight, rawImageData, GL_LUMINANCE, GL_UNSIGNED_BYTE);
-
-  // get descriptors
-  const int descr_size = 128;
-  const int numberOfDescriptors = sift.GetFeatureNum();
-  float desc[descr_size * numberOfDescriptors];
-  
-  //vector<float> desc (descr_size * numberOfDescriptors);
-
-  sift.GetFeatureVector (keys, desc);
-
-  // TODO: kopieren durch Iterator erledigen
-
-  Vector localDesc (descr_size);
-  // copy the SiftDescriptors into NICEDescriptors
-  for (int i = 0; i < numberOfDescriptors; i++) {
-    for (int j = 0; j < descr_size; j++) {
-      localDesc[j] = (integerValues ? (int) (512 * desc[i*descr_size+j]) : desc[i*descr_size+j]);
-    }
-    descriptors.push_back (localDesc);
-  }
-}
-
-int LocalFeatureSiftGPU::getDescriptors (const NICE::Image & img, VVector & positions, VVector & descriptors) const
-{
-  sortPositions (positions);
-
-  computeDesc (img, positions, descriptors);
-
-  return 0;
-}

+ 0 - 62
features/localfeatures/LocalFeatureSiftGPU.h

@@ -1,62 +0,0 @@
-/** 
-* @file LocalFeaturesiftGPU.h
-* @brief A Sift-Implementation, which uses the GPU.
-* @author Eric Bach
-* @date 11/20/2011
-*/
-#ifndef LOCALFEATURESIFTGPUINCLUDE
-#define LOCALFEATURESIFTGPUINCLUDE
-
-#ifdef NOVISUAL
-#include <objrec/nice_nonvis.h>
-#else
-#include <objrec/nice.h>
-#endif
-
-/* NICE - include */
-#include "core/vector/VVector.h"
-#include "LocalFeatureSift.h"
-
-/* std - include */
-#include <map>
-#include <string>
-
-#ifdef NICE_USELIB_CUDASIFT
-/* SiftGPU - include */
-#include <src/SiftGPU.h>
-#endif
-
-typedef std::map<unsigned int, bool> StatTable;
-
-namespace OBJREC {
-  /** local feature interface */
-  class LocalFeatureSiftGPU: public LocalFeatureSift
-  {
-    private:
-    protected:
-      StatTable deviceStat;
-      int numOfGPU;
-      std::string gpuLanguage;
-      bool multiGPU;
-      
-      //! return the id of a unused device
-      int getNextDeviceID();
-      //! set the device (id) to stat unused
-      void releaseDevice(int id);
-      
-    public:
-      /** simple constructor */
-      LocalFeatureSiftGPU( const NICE::Config* conf );
-    
-      /** simple destructor */
-      ~LocalFeatureSiftGPU();
-      
-      //! returns the number of available devices
-      int getNumOfDevices() const { return numOfGPU; };
-      
-      void computeDesc( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
-      
-      int getDescriptors( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & descriptors) const;
-  };
-} // namespace
-#endif