Ask Your Question

cv::xfeatures2d::SURF abstract?

asked 2014-10-20 19:29:35 -0500

kovand11 gravatar image

updated 2014-10-23 15:53:46 -0500

berak gravatar image

With all default opencv + opencv_contrib build (vs2013), it seems that the mentioned class is abstract.

Test code:

#include <opencv2\core.hpp>
#include <opencv2\features2d.hpp>
#include <opencv2\xfeatures2d\nonfree.hpp>
//the corresponding libraries are linked

int main()
    cv::Mat m;
    cv::xfeatures2d::SURF surf;
    return 0;


Error   1   error C2259: 'cv::xfeatures2d::SURF' : cannot instantiate abstract class    c:\documents\visual studio 2013\projects\xfeattest\xfeattest\main.cpp   8   1   xfeatTest

2   IntelliSense: object of abstract class type "cv::xfeatures2d::SURF" is not allowed:
        function "cv::xfeatures2d::SURF::setHessianThreshold" is a pure virtual function
        function "cv::xfeatures2d::SURF::getHessianThreshold" is a pure virtual function
        function "cv::xfeatures2d::SURF::setNOctaves" is a pure virtual function

The nonfree.hpp:


#include "opencv2/features2d.hpp"

namespace cv
namespace xfeatures2d

 SIFT implementation.

 The class implements SIFT algorithm by D. Lowe.
class CV_EXPORTS_W SIFT : public Feature2D
    CV_WRAP static Ptr<SIFT> create( int nfeatures = 0, int nOctaveLayers = 3,
                                    double contrastThreshold = 0.04, double edgeThreshold = 10,
                                    double sigma = 1.6);

typedef SIFT SiftFeatureDetector;
typedef SIFT SiftDescriptorExtractor;

 SURF implementation.

 The class implements SURF algorithm by H. Bay et al.
class CV_EXPORTS_W SURF : public Feature2D
    CV_WRAP static Ptr<SURF> create(double hessianThreshold=100,
                  int nOctaves = 4, int nOctaveLayers = 3,
                  bool extended = false, bool upright = false);

    CV_WRAP virtual void setHessianThreshold(double hessianThreshold) = 0;
    CV_WRAP virtual double getHessianThreshold() const = 0;

    CV_WRAP virtual void setNOctaves(int nOctaves) = 0;
    CV_WRAP virtual int getNOctaves() const = 0;

    CV_WRAP virtual void setNOctaveLayers(int nOctaveLayers) = 0;
    CV_WRAP virtual int getNOctaveLayers() const = 0;

    CV_WRAP virtual void setExtended(bool extended) = 0;
    CV_WRAP virtual bool getExtended() const = 0;

    CV_WRAP virtual void setUpright(bool upright) = 0;
    CV_WRAP virtual bool getUpright() const = 0;

typedef SURF SurfFeatureDetector;
typedef SURF SurfDescriptorExtractor;

} /* namespace cv */


Any idea what the problem could be?

edit retag flag offensive close merge delete


because namespace two loop, please add: using namespace cv::xfeatures2d

wuling gravatar imagewuling ( 2014-10-21 01:26:41 -0500 )edit

@wulling, he is explicitly adding the namespaces himself so that is not the problem :)

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-21 04:31:12 -0500 )edit

dear StevenPuttemans,I saw that.I am worng.

wuling gravatar imagewuling ( 2014-10-21 07:48:41 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-10-21 01:43:43 -0500

berak gravatar image

updated 2014-10-23 03:56:50 -0500

yes, they are all 'abstract' (lack a public constructor).

the only way to make one is the 'create' function, like:

using namespace cv::xfeatures2d;

Ptr<SIFT> sift = SIFT::create(...);

[EDIT: 2014.10.23 : below is no more possible.]

if you want to use the Feature2D::create method, that's another way:


// both detector and extractor:   
Ptr<Feature2D> sift = Feature2D::create("SIFT");

// or, if you need the detector part only:    
Ptr<FeatureDetector> sift = FeatureDetector::create("SIFT");

edit flag offensive delete link more


Should it be difficult to add those public constructors? Or is there a reason for not doing so that you can think off?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-21 04:32:48 -0500 )edit

i think they want to enforce the use of cv::Ptr there. (no, it wouldn't be difficult at all)

berak gravatar imageberak ( 2014-10-21 05:34:40 -0500 )edit

I hate the use of the Ptr interface, but hey, I will have to get used to it.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-21 07:01:45 -0500 )edit

Haha nice, did you adjust it with a PR?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-23 04:04:33 -0500 )edit

@StevenPuttemans - ? sorry, i don't get what you're sayin ?.

(if you meant the edit above, that's just a <strike> )

berak gravatar imageberak ( 2014-10-23 04:20:50 -0500 )edit

@VanGog, this topic is more than a year old !

and you should pass a number to the crreate function, like SIFT::create(500); not a declaration

berak gravatar imageberak ( 2016-06-17 09:38:53 -0500 )edit

@berak: Is it problem that I used Google and did not created duplicate question? The SIFT is not SURF. And SURF does not work. Maybe it is not finished? As I read doc 3.0 beta and I miss 3.1 docs. SIFT works but it is rather slow.

VanGog gravatar imageVanGog ( 2016-06-20 10:14:34 -0500 )edit

@VanGog, there is a fine distinction between "SURF does not work" (library problem), and "I'm unable to use it" (pebcak)

also, please use for docs

berak gravatar imageberak ( 2016-06-20 10:28:29 -0500 )edit

Thank you very much. I used the exact syntax as used in constructor declaration and voila it works. SURF is almost 2x faster than SIFT.

VanGog gravatar imageVanGog ( 2016-06-21 05:07:09 -0500 )edit

Question Tools

1 follower


Asked: 2014-10-20 19:29:35 -0500

Seen: 6,244 times

Last updated: Oct 23 '14