Search code examples
imageopencvcomputer-visionsurf

Using SURF in openv fails because of write access violation


I am trying to find the position of an image in another image using SURF, but every time I try to initialize the detector, it fails, telling me that there was an access violation and that detector.Ptr was "0xFFFFFFFFFFFFFF". My code:

auto detector = cv::xfeatures2d::SurfFeatureDetector::create();
        detector->detect(map,keypointsMap);
        detector->detectAndCompute(compare, noArray(), keypointsCompare, descriptorComp);

This happens even when i use the example code from the opencv documentation (https://docs.opencv.org/3.4/d7/dff/tutorial_feature_homography.html). I can use the other non-free features like SIFT without any problems. I am using opencv4 and I am including the following libraries:

#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/xfeatures2d/nonfree.hpp"
#include "opencv2/imgproc.hpp"

Has anybody seen this issue before and maybe knows a solution? Thank you


Solution

  • I have found the problem, when I reinstalled opencv on my laptop. It seems that you have to configure cmake the right way (specify path for modules and allow nonfree) when you build opencv the first try to get SURF and SIFT to work. If you don't, you can't fix it by overwriting the old files. SIFT will work then, but not SURF, for some reason. So I deleted everything on my PC and then did the configuration right from the start and now it works. Oh, and also make sure you add everything to the path correctly. Extremely useful description to install opencv on windows 10: https://www.youtube.com/watch?v=x5EWlNQ6z5w Thank you Grillteller and everyone who read this!