Ask Your Question
2

What are the SURF support restrictions?

asked 2013-04-19 21:33:08 -0600

DutchMark gravatar image

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 flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-04-22 15:37:04 -0600

DutchMark gravatar image

updated 2013-04-22 15:38:15 -0600

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?

edit flag offensive delete link more

Comments

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

Guanta gravatar imageGuanta ( 2013-04-23 02:16:26 -0600 )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 !

Flouse gravatar imageFlouse ( 2015-03-12 03:41:04 -0600 )edit
3

answered 2013-04-20 05:47:28 -0600

Guanta gravatar image

updated 2013-04-20 05:50:19 -0600

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.

edit flag offensive delete link more

Comments

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.

DutchMark gravatar imageDutchMark ( 2013-04-21 16:49:52 -0600 )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.

DutchMark gravatar imageDutchMark ( 2013-04-22 14:10:39 -0600 )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?

Guanta gravatar imageGuanta ( 2013-05-03 02:06:06 -0600 )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 !

Flouse gravatar imageFlouse ( 2015-03-12 03:47:11 -0600 )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).

Guanta gravatar imageGuanta ( 2015-03-12 04:18:46 -0600 )edit
0

answered 2013-05-02 09:57:12 -0600

RubeRad gravatar image

updated 2013-05-02 10:01:44 -0600

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.

edit flag offensive delete link more

Comments

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.

DutchMark gravatar imageDutchMark ( 2013-05-21 20:11:01 -0600 )edit

Question Tools

Stats

Asked: 2013-04-19 21:33:08 -0600

Seen: 6,165 times

Last updated: May 02 '13