10

When I try to run the sample find_obj.cpp or any OpenCV SURF program I get the following error in command prompt while executing the code. The project builds without errors and warnings. I am using VS2011 beta, OpenCV 2.4 and windows7.

Error message:

OpenCV Error: The function/feature is not implemented < OpenCV was built without SURF support> in unknown function,file ..\..\..\src\opencv\modules\legacy\src\features2d.cpp, line 77

I tried to build the OpenCV 2.4 again using Cmake and then VS2011 in debug mode and then added the lib paths in the IDE, but still no result.

How can I fix that?

    #include <opencv2/objdetect/objdetect.hpp>
    #include <opencv2/features2d/features2d.hpp>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/legacy/legacy.hpp>
    #include <opencv2/legacy/compat.hpp>
    #include <opencv2/flann/flann.hpp>
    #include <opencv2/calib3d/calib3d.hpp>
    #include <opencv2/nonfree/features2d.hpp>
    #include <opencv2/nonfree/nonfree.hpp>

using namespace std;
using namespace cv;
int main()
{
    cv::initModule_nonfree();//THIS LINE IS IMPORTANT   

   IplImage *image1 = cvLoadImage("C:\\SURF\\1.jpg"); 
    IplImage *image2 = cvLoadImage("C:\\SURF\\2.jpg");

    CvMemStorage* memoryBlock = cvCreateMemStorage();
    CvSeq* image1KeyPoints;
    CvSeq* image1Descriptors;
    CvSeq* image2KeyPoints;
    CvSeq* image2Descriptors;

    // Only values with a hessian greater than 500 are considered for keypoints
   CvSURFParams params = cvSURFParams(500, 1);
   cvExtractSURF(image1, 0, &image1KeyPoints, &image1Descriptors, memoryBlock, params);
   cvExtractSURF(image2, 0, &image2KeyPoints, &image2Descriptors, memoryBlock, params);

   return 0;
}
rotating_image
  • 3,046
  • 4
  • 28
  • 46

4 Answers4

10

Taken from this answer (why don't you google your question before asking?):

The SIFT and SURF code was moved in OpenCV v2.4 to a new module called nonfree. Make sure you are linking (DLL in Windlows) to it. In linux this library is called libopencv_nonfree.so.

ArtemStorozhuk
  • 8,715
  • 4
  • 35
  • 53
  • 2
    ya i googled the opencv forums and i included the opencv_nonfree240.lib ..and the headers are 1......opencv2/objdetect/objdetect.hpp....... 2......opencv2/features2d/features2d.hpp..... 3......opencv2/highgui/highgui.hpp...... 4......opencv2/calib3d/calib3d.hpp..... 5......opencv2/nonfree/nonfree.hpp...... 6......opencv2/imgproc/imgproc_c.h....... 7......opencv2/legacy/legacy.hpp...... 8......opencv2/legacy/compat.hpp...... – rotating_image Jun 24 '12 at 10:28
  • @Astor....in the IDE...i set the path to the C:\OpenCV2.4\opencv\build\x86\vc10\lib...i have saved the opencv2.4 in c drive...the bin folder contains all the dll where i have checked it contains the opencv_nonfree240.dll...and in the additional dependencies i have given the opencv_nonfree240.lib – rotating_image Jun 24 '12 at 10:32
  • library directories = C:\OpenCV2.4\opencv\build\x86\vc10\lib additional dependencies = opencv_nonfree240.lib this is my setting in VS2011 – rotating_image Jun 24 '12 at 10:50
  • @astor...ya i have done all d necessary...all the other programs using opencv libraries are working fine ..i donno why this is showing problem...i m posting a small sample code which i wrote – rotating_image Jun 24 '12 at 11:43
  • thanx astor for your guidelines...the problem got solved...i was forgettin the cv::initModule_nonfree() line... – rotating_image Jun 24 '12 at 14:48
  • @Astor I googled and I was taken here, solving my problem, thanks. I dind't know they were moved as I use CMake and I don't have to usually worry about libs, but it is good to know. Do you know why they were moved? – Jav_Rock Sep 17 '12 at 14:52
8

It's not a bug. SURF is located in nonfree module. To use it you should initialize nonfree module:

    #include <opencv2/nonfree/nonfree.hpp> 
    ... 
    cv::initModule_nonfree();
erlingmusan
  • 81
  • 1
  • 2
3

Recently, I am learning the SURF. For this question you can add the opencv_nonfree240d.lib and opencv_nonfree240.lib to your project's lib path.

fay
  • 31
  • 1
0

For ubuntu the script at https://help.ubuntu.com/community/OpenCV can be modified for nonfree surf/sift use by adding

libopencv_nonfree

to the end of the sudo apt-get command, and

-D BUILD_opencv_nonfree=ON

to the end of the cmake command. It only worked for me after uninstalling everything I could find dealing with opencv from the software center. Incidentally the software center also had an opencv nonfree library, "libopencv-nonfree2.4" which didn't seem to help matters. I am not an expert in such stuff so I don't know if what I did is 100% right, but it allows commands such as

surf = cv2.SURF(400)

and

keypoints = surfDetector.detect(im)

to run which hadnt previously (the first caused a 'not found' type error while the second caused a segfault).

The version of opencv.sh which allowed me to use nonfree surf/sift pasted to http://pastebin.com/sQzDdx5i
The version that is working now is opencv-2.4.9 but possibly this would work for other versions as the script seems to be somewhat agnostic as do the lib names.

jeremy_rutman
  • 3,552
  • 4
  • 28
  • 47