Ask Your Question
0

cv::xfeatures2d::SURF abstract?

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

kovand11 gravatar image

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

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:

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:

#ifndef __OPENCV_XFEATURES2D_FEATURES_2D_HPP__
#define __OPENCV_XFEATURES2D_FEATURES_2D_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
{
public:
    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
{
public:
    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 */

#endif

Any idea what the problem could be?

edit retag flag offensive close merge delete

Comments

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

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

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

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

dear StevenPuttemans,I saw that.I am worng.

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

1 answer

Sort by ยป oldest newest most voted
4

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

berak gravatar image

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

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:

xfeatures2d::initModule_xfeatures2d();

// 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

Comments

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 -0600 )edit
1

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 -0600 )edit
1

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 -0600 )edit

Haha nice, did you adjust it with a PR?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-23 04:04:33 -0600 )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 -0600 )edit
2

@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 -0600 )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 -0600 )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 http://docs.opencv.org/master/ for docs

berak gravatar imageberak ( 2016-06-20 10:28:29 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 7,650 times

Last updated: Oct 23 '14