# What are the SURF support restrictions?

I made a nice application to find matching features in photos. I noticed however that the libraries are not included when I build the application, which makes it difficult to give it to other people.

So I managed to build the app with static libraries that I built from source (originally I used MacPorts to install opencv). But during run-time it tells me that SURF support was not compiled in.

The exact message I get is this:

OpenCV Error: The function/feature is not implemented (OpenCV was built without SURF support) in cvExtractSURF, file /Users/mboon/Documents/workspaceGit/opencv-2.4.5/modules/legacy/src/features2d.cpp, line 77

So I looked around the web to solve that and ran into a few things. One was a suggestion that I needed to include the nonfree library. But I already do that and I still get the message that SURF is disabled. The libopencv_nonfree.a file is 1.5Mb but I don't really know what's in there.

The other thing I saw is that the reason SURF is not included by default since version 2.4 due to patent or import restrictions. Can anyone point me to information about what those restrictions are? Can I actually use it, or not? Would I need a license?

Can someone tell me what exactly I'd need to do to build OpenCV including SURF support? Is there a CMake option I missed? Something else?

Any information or help is greatly appreciated.

edit retag close merge delete

Sort by » oldest newest most voted

I finally figured out what was the problem. It turned out to be the order in which the libraries were linked. When I moved libopencv_nonfree.a to the front of the list of libraries it suddenly worked.

No need for the inclusion of "opencv2/features2d/features2d.hpp" and "opencv2/nonfree/nonfree.hpp". The former is already included through cv.hpp, the purpose of the latter is purely to include "opencv2/features2d/features2d.hpp" and declare cv::initModule_nonfree(). But there's no need for any call to cv::initModule_nonfree(), maybe that's an obsolete requirement?

more

Glad to hear that you could solve your problem! I don't know if 'initModule_nonfree' is obsolete...

( 2013-04-23 02:16:26 -0500 )edit

Hi, what do you mean by "build the app with static libraries that I built from source" ? Where is located your libopencv_nonfree.a ? In my folder /open_cv-2.4.11/build/lib I have the following files : libopencv_nonfree.so, libopencv_nonfree.so.2.4, libopencv_nonfree.so.2.4.11, libopencv_nonfree_pch_dephelp.a. And what do you mean by move the libopencv_nonfree.a to the front ? Where ?

thank you in advance, it's been 2 days I've been searching a solution !

( 2015-03-12 03:41:04 -0500 )edit

The developers of SURF hold a patent on their algorithm. However, for scientific purposes you can use it (for commercial ones you have to be aware of the patent, read it carefully and if you may violate it: ask the original developers (not the OpenCV-crew!) about a licence).

Three steps to get it run (used version: OpenCV 2.4.4):

1. build OpenCV with nonfree options, i.e. BUILD_opencv_nonfree needs to be set! (e.g. by using ccmake) or call cmake with -DBUILD_opencv_nonfree. (Note: afaik the standard case is that it is activated - haven't checked the latest version yet though.)
2. include <opencv2/features2d/features2d.hpp> and <opencv2/nonfree/nonfree.hpp>
3. call cv::initModule_nonfree(); before you want to use SURF (or SIFT)

Btw. if you are devloping commercial products always be aware that sth. could be under a patent, e.g. non-local means which is also available in OpenCV - but not part of the nonfree-module - actually also has an EU-patent.

more

Thanks for the answer, I'm going to try it out on Monday. I already have BUILD_opencv_nonfree set and libopencv_nonfree.a is buing built, but I didn't know the cv::initModule_nonfree() call was required. When I link it with dynamic libraries it does not require it, nor the include statements you mention.

With regards to the patent, when the time comes this application will be commercialized we'll make sure we're not violating anything or get the appropriate license. I was under the understanding though that algorithms can't be patented, only specific applications using it. But being in the software business ourselves we're more than willing to pay for work by others, provided the cost is reasonable.

( 2013-04-21 16:49:52 -0500 )edit

OK, I tried it out just now and it didn't solve the problem. I still get the same message. The method where it gets stuck is this: CV_IMPL void cvExtractSURF( const CvArr* _img, const CvArr* _mask, CvSeq* _keypoints, CvSeq* _descriptors, CvMemStorage* storage, CvSURFParams params, int useProvidedKeyPts) { . . . Ptr<Feature2D> surf = Algorithm::create<Feature2D>("Feature2D.SURF"); if( surf.empty() ) CV_Error(CV_StsNotImplemented, "OpenCV was built without SURF support"); . . .

which is in 'modules/src/legacy/features2d.hpp'.

Would I need to do something for it to use 'nonfree/features2d.hpp'? If so, how? (I did add the include statements you recommended)

Apologies for the formatting.

( 2013-04-22 14:10:39 -0500 )edit

Have you solved your problem? Sry that I write just now. I have no idea any more, but you shouldn't need sth from the legacy module. Do you use it? Which OpenCV version do you use?

( 2013-05-03 02:06:06 -0500 )edit

Hi, how do you call the cv::initModule_nonfree(); in c and not c++ ? Where should I call it ? In my project ? Thanks for your help !

( 2015-03-12 03:47:11 -0500 )edit

I don't think you can't call it in a purely C compiled version (how could you call SIFT / SURF at all?). In OpenCV version < 3.0 you'd have to call cv::initModule_nonfree(); directly before you want to create SIFT or SURF (via their constructors or the factory method of cv::FeatureDetector::create("...") and cv::DescriptorExtractor::create("..."), respectively).

( 2015-03-12 04:18:46 -0500 )edit

My recommendation; ditch SURF and just use ORB. It's faster and gets better quality matches and it's not patent-restricted like SIFT and SURF. Win Win Win.

You shouldn't have to change much code if you are using all opencv capabilities for keypoints, descriptors, and matching; just a different call to find keypoints and generate descriptors, and switch your descriptor matcher to a HammingDistance one instead of L2.

more

I tried this with another project. Unfortunately, the quality of the matches is much lower using ORB so it's not an option for me.

( 2013-05-21 20:11:01 -0500 )edit

Official site

GitHub

Wiki

Documentation