16 #include <mrpt/otherlibs/do_opencv_includes.h>    18 #ifdef HAVE_OPENCV_NONFREE  //MRPT_HAS_OPENCV_NONFREE    19 # include <opencv2/nonfree/nonfree.hpp>    21 #ifdef HAVE_OPENCV_FEATURES2D    22 # include <opencv2/features2d/features2d.hpp>    24 #ifdef HAVE_OPENCV_XFEATURES2D    25 # include <opencv2/xfeatures2d.hpp>    36 #if defined(HAVE_OPENCV_XFEATURES2D) || (MRPT_OPENCV_VERSION_NUM < 0x300 && MRPT_OPENCV_VERSION_NUM >= 0x240)    37 # define HAVE_OPENCV_WITH_SURF 1    39 # define HAVE_OPENCV_WITH_SURF 0    49         unsigned int                    nDesiredFeatures,
    52 #if HAVE_OPENCV_WITH_SURF    56         const Mat 
img = cvarrToMat( img_grayscale.
getAs<IplImage>() );
    58         vector<KeyPoint> cv_feats; 
    62 #       if MRPT_OPENCV_VERSION_NUM < 0x300 && MRPT_OPENCV_VERSION_NUM >= 0x240    64                 Ptr<Feature2D> surf = Algorithm::create<Feature2D>(
"Feature2D.SURF");
    66                         CV_Error(CV_StsNotImplemented, 
"OpenCV <v3.0 was built without SURF support");
    68                 surf->set(
"hessianThreshold", options.SURFOptions.hessianThreshold);
    69                 surf->set(
"nOctaves", options.SURFOptions.nOctaves);
    70                 surf->set(
"nOctaveLayers", options.SURFOptions.nLayersPerOctave);
    72                 surf->set(
"extended", options.SURFOptions.rotation_invariant);
    74                 surf->operator()(
img, Mat(), cv_feats, cv_descs);
    77                 Ptr<xfeatures2d::SURF> surf = xfeatures2d::SURF::create(100.0, 4, 3, 0, 0);
    80                         CV_Error(CV_StsNotImplemented, 
"OpenCV 3.0 was built without SURF support");
    81                 surf->setHessianThreshold(options.SURFOptions.hessianThreshold);
    82                 surf->setNOctaves(options.SURFOptions.nOctaves);
    83                 surf->setNOctaveLayers(options.SURFOptions.nLayersPerOctave);
    85                 surf->setExtended(options.SURFOptions.rotation_invariant);
    87                 surf->detectAndCompute(
img, Mat(), cv_feats, cv_descs);
    94         unsigned int    nCFeats         = init_ID;
    95         int                             offset          = (int)this->options.patchSize/2 + 1;
    97         unsigned int    imgW            = inImg.
getWidth();
    99         const size_t n_feats = (nDesiredFeatures== 0) ?
   102                 std::min((
size_t)nDesiredFeatures, cv_feats.size());
   104         for(
size_t i = 0; i < n_feats; i++ )
   108                 const KeyPoint &point = cv_feats[i];
   110                 const int xBorderInf = (int)floor( point.pt.x - options.patchSize/2 );
   111                 const int xBorderSup = (int)floor( point.pt.x + options.patchSize/2 );
   112                 const int yBorderInf = (int)floor( point.pt.y - options.patchSize/2 );
   113                 const int yBorderSup = (int)floor( point.pt.y + options.patchSize/2 );
   115                 if( options.patchSize == 0 || ( (xBorderSup < (
int)imgW) && (xBorderInf > 0) && (yBorderSup < (int)imgH) && (yBorderInf > 0) ) )
   120                         ft->orientation = point.angle;                          
   121                         ft->scale               = point.size*1.2/9;             
   123                         ft->patchSize   = options.patchSize;            
   125                         if( options.patchSize > 0 )
   136                         ft->descriptors.SURF.resize( cv_descs.cols );
   137                         for( 
int m = 0; m < cv_descs.cols; ++m )
   138                                 ft->descriptors.SURF[m] = cv_descs.at<
float>(i,m);
   147         THROW_EXCEPTION(
"Method not available: MRPT compiled without OpenCV, or against a version of OpenCV without SURF")
   148 #endif //MRPT_HAS_OPENCV   159 #if HAVE_OPENCV_WITH_SURF   162         if (in_features.
empty()) 
return;
   165         const Mat 
img = cvarrToMat( img_grayscale.
getAs<IplImage>() );
   167         vector<KeyPoint> cv_feats; 
   171         cv_feats.resize(in_features.
size());
   172         for (
size_t i=0;i<in_features.
size();++i)
   174                 cv_feats[i].pt.x = in_features[i]->x;
   175                 cv_feats[i].pt.y = in_features[i]->y;
   176                 cv_feats[i].size = 16;  
   181 #       if MRPT_OPENCV_VERSION_NUM < 0x300      && MRPT_OPENCV_VERSION_NUM >= 0x240   183                 Ptr<Feature2D> surf = Algorithm::create<Feature2D>(
"Feature2D.SURF");
   185                         CV_Error(CV_StsNotImplemented, 
"OpenCV was built without SURF support");
   186                 surf->set(
"hessianThreshold", options.SURFOptions.hessianThreshold);
   187                 surf->set(
"nOctaves", options.SURFOptions.nOctaves);
   188                 surf->set(
"nOctaveLayers", options.SURFOptions.nLayersPerOctave);
   190                 surf->set(
"extended", options.SURFOptions.rotation_invariant);
   192                 surf->compute(
img, cv_feats, cv_descs); 
   196                 Ptr<xfeatures2d::SURF> surf = xfeatures2d::SURF::create(100.0, 4, 3, 0, 0);
   199                         CV_Error(CV_StsNotImplemented, 
"OpenCV was built without SURF support");
   200                         surf->setHessianThreshold(options.SURFOptions.hessianThreshold);
   201                         surf->setNOctaves(options.SURFOptions.nOctaves);
   202                         surf->setNOctaveLayers(options.SURFOptions.nLayersPerOctave);
   204                         surf->setExtended(options.SURFOptions.rotation_invariant);
   206                 surf->detectAndCompute(
img, Mat(), cv_feats, cv_descs);
   214         for (i=0, itList=in_features.
begin();itList!=in_features.
end();itList++,i++)
   217                 CFeaturePtr ft = *itList;
   218                 const KeyPoint &point = cv_feats[i];
   220                 ft->orientation = point.angle;                          
   221                 ft->scale               = point.size*1.2/9;             
   224                 ft->descriptors.SURF.resize( cv_descs.cols );
   225                 for( 
int m = 0; m < cv_descs.cols; ++m )
   226                         ft->descriptors.SURF[m] = cv_descs.at<
float>(i,m);              
   230         THROW_EXCEPTION(
"Method not available: MRPT compiled without OpenCV, or against a version of OpenCV without SURF")
   231 #endif //MRPT_HAS_OPENCV Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL. 
 
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
 
A class for storing images as grayscale or RGB bitmaps. 
 
#define THROW_EXCEPTION(msg)
 
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. 
 
A structure for defining a ROI within an image. 
 
Classes for computer vision, detectors, features, etc. 
 
void push_back(const CFeaturePtr &f)
 
A list of visual features, to be used as output by detectors, as input/output by trackers, etc. 
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
Speeded Up Robust Feature [BAY'06]. 
 
void extract_patch(CImage &patch, const unsigned int col=0, const unsigned int row=0, const unsigned int width=1, const unsigned int height=1) const
Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten)...
 
int round(const T value)
Returns the closer integer (int) to x. 
 
TInternalFeatList::iterator iterator
 
static CFeaturePtr Create()
 
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels. 
 
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels.