0

I'm currently using OpenCV 3.4.0, c++ in QT creator. I've tried sample code in this page https://docs.opencv.org/2.4/doc/tutorials/features2d/feature_description/feature_description.html

int minHessian = 400;
cv::xfeatures2d::SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);

// computing descriptors
cv::xfeatures2d::SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);

// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);

but the code kept returning error

no matching function for call to 'cv::xfeatures2d::SURF::SURF(int&)(2nd line)

cannot declare variable 'detector' to be of abstract type 'cv::xfeatures2d::SURF'(2nd line)

cannot declare variable 'extractor' to be of astract type 'cv::xfeatures2d::SURF'(7th line)

I have imported all the necessary modules I think including xfeatures2d

What is the problem?

And are there any other sample codes that I can try?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Hyunjun
  • 37
  • 4
  • in case someone want to know what I've included, [#include "opencv2/imgcodecs.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" #include #include #include #include #include "opencv2/features2d/features2d.hpp" #include "opencv2/core/core.hpp" #include "opencv2/xfeatures2d.hpp" #include "opencv2/features2d.hpp"] – Hyunjun Jul 02 '18 at 01:41

1 Answers1

0

Your coding reflects an older version of OpenCV which is not compatible with OpenCV 3.4.0. You can try like so. It is better to convert the template image to a grayscale image for better matching:

cv::Ptr<Feature2D> detector = cv::xfeatures2d::SurfFeatureDetector::create();
detector->detect(img1, keypoints1);

cv::Ptr<DescriptorExtractor> extractor = cv::xfeatures2d::SurfFeatureDetector::create();
extractor->compute(img1, keypoints1, descriptors1);
seccpur
  • 4,996
  • 2
  • 13
  • 21
  • Thanks for your help!! It works! But I want to know where can i get the such informations about opencv 3.4.0. – Hyunjun Jul 02 '18 at 02:00