ParallelSurfExtractor.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  SurfExtractor.cpp
00003  *
00004  *  (C) 2008 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  $Id: $
00008  *
00009  *******************************************************************************/
00010 
00011 #include "ParallelSurfExtractor.h"
00012 
00013 
00014 #include <cmath>
00015 #include <sstream>
00016 #include <float.h>
00017 
00018 #include "../ParallelSurf/Image.h"
00019 #include "../ParallelSurf/KeyPointDetector.h"
00020 #include "../ParallelSurf/KeyPointDescriptor.h"
00021 #include "../ParallelSurf/KeyPoint.h"
00022 
00023 #define THIS ParallelSurfExtractor
00024 
00025 #define FULL_DEBUG
00026 
00027 using namespace std;
00028 
00029 
00030 THIS::THIS( int numThreads )
00031 {
00032   m_IntegralImage = 0;
00033   
00034   if ( numThreads != 0 )
00035   {
00036     m_ThreadPool = new boost::threadpool::pool( numThreads );
00037   }  
00038   else
00039   {
00040     m_ThreadPool = new boost::threadpool::pool( boost::thread::hardware_concurrency() );
00041   }
00042 }
00043 
00044 
00045 THIS::~THIS()
00046 {
00047   ROS_DEBUG_STREAM ( "Deleting member variables.." );
00048   delete m_IntegralImage;
00049 //  delete m_ThreadPool;
00050 }
00051 
00052 
00053 
00054 THIS::THIS ( const THIS& other ) : SurfExtractorBase ( other )
00055 {
00056 }
00057 
00058 
00059 THIS& THIS::operator= ( const THIS & other )
00060 {
00061   SurfExtractorBase::operator=(other);
00062   return *this;
00063 }
00064 
00065 
00066 
00067 std::string THIS::getName()
00068 {
00069   std::ostringstream s;
00070   s << "ParallelSURF (" << m_ThreadPool->size() << " threads)";
00071   return s.str();
00072 }
00073 
00074 
00075 void THIS::setImage ( const cv::Mat &image )
00076 {
00077     cv::Mat dest;
00078     // if it is a color image convert it to grayscale
00079     if(image.type() == CV_8UC3)
00080     {
00081         cvCvtColor( &image, &dest, CV_RGB2GRAY );
00082     }
00083     else
00084     {
00085         dest = image;
00086     }
00087 
00088     unsigned char *data[dest.rows];
00089     for(int i = 0; i < dest.rows; i++)
00090     {
00091         data[i] =  dest.row(i).data;
00092     }
00093 
00094   delete m_IntegralImage;
00095   m_IntegralImage = new parallelsurf::Image( (const unsigned char**) data, dest.cols, dest.rows );
00096 }
00097 
00098 void THIS::getKeyPoints ( std::vector< KeyPoint >& keyPoints )
00099 {
00100   
00101   std::vector<parallelsurf::KeyPoint> panoKeyPoints;
00102 
00103   parallelsurf::KeyPointDetector detector( *m_IntegralImage, *m_ThreadPool );
00104   parallelsurf::KeyPointDescriptor descriptor( *m_IntegralImage, *m_ThreadPool, m_Extended );
00105   
00106   //insertor inserts into panoKeyPoints
00107   KeyPointVectInsertor insertor( panoKeyPoints );
00108   
00109   //Detect
00110   detector.setMaxOctaves( m_Octaves );
00111   detector.setScoreThreshold( m_BlobResponseThreshold );
00112   
00113   detector.detectKeyPoints( insertor );
00114   
00115   //Compute orientation & descriptor
00116   
00117   if ( m_RotationInvariance)
00118   {
00119     descriptor.assignOrientations( panoKeyPoints.begin(), panoKeyPoints.end() );
00120   }
00121   else
00122   {
00123     for ( unsigned i=0; i<panoKeyPoints.size(); i++ )
00124     {
00125       panoKeyPoints[i]._ori=0;
00126     }
00127   }
00128   
00129   descriptor.makeDescriptors( panoKeyPoints.begin(), panoKeyPoints.end() );
00130   
00131   //Copy results
00132   keyPoints.resize( panoKeyPoints.size() );
00133   
00134   for ( unsigned i=0; i<panoKeyPoints.size(); i++ )
00135   {
00136     keyPoints[i].x = panoKeyPoints[i]._x;
00137     keyPoints[i].y = panoKeyPoints[i]._y;
00138     keyPoints[i].scale = panoKeyPoints[i]._scale;
00139     keyPoints[i].orientation = panoKeyPoints[i]._ori;
00140     keyPoints[i].strength = panoKeyPoints[i]._score;
00141     keyPoints[i].sign = panoKeyPoints[i]._trace;
00142     keyPoints[i].featureVector = panoKeyPoints[i]._vec;
00143   }
00144   
00145 }
00146 


or_libs
Author(s): raphael
autogenerated on Mon Oct 6 2014 02:53:18