How can I "Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'"?

asked 2018-10-28 16:55:33 -0500

viohh gravatar image

I built opencv_contrib and some of the modules are working, however when I'm trying to use SURF I get: "error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'". So how can I enable nonfree?

edit retag flag offensive close merge delete

Comments

CMake -DOPENCV_ENABLE_NONFREE:BOOL=ON

LBerger gravatar imageLBerger ( 2018-10-29 02:21:25 -0500 )edit

Thank you, but where should I make it? In xfeatures2d?

viohh gravatar imageviohh ( 2018-10-29 06:43:31 -0500 )edit

You have to build opencv and opencv_contrib (git cloneyourself). it is recommended to use them alongside the master branch or latest releases of OpenCV.

Then you can setOPENCV_ENABLE_NONFREE in cmake-gui or in cmake command line

LBerger gravatar imageLBerger ( 2018-10-29 06:47:55 -0500 )edit

I built opencv and opencv_contrib, but which cmake file I need?

viohh gravatar imageviohh ( 2018-10-29 07:01:47 -0500 )edit

if you built opencv and and opencv_contrib do it again :

CMake -DOPENCV_ENABLE_NONFREE:BOOL=ON -DOPENCV_EXTRA_MODULES_PATH=.your_path/opencv_contrib/modules
LBerger gravatar imageLBerger ( 2018-10-29 07:51:27 -0500 )edit

I 'm having the same problem.

I built opencv and opencv_contrib 3.4.3 and I set OPENCV_ENABLE_NONFREE in cmake-gui ON and I checked that the Non-free algorithms were installed.

In the test code of surf, at the following line:

detector = SURF::create(minHessian);

it enters in this parte of code (inside surf.cpp)

else // ! #ifdef OPENCV_ENABLE_NONFREE

Ptr<surf> SURF::create(double, int, int, bool, bool) { CV_Error(Error::StsNotImplemented, "This algorithm is patented and is excluded in this configuration; " "Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library"); }

endif

What can I do to enable #ifdef OPENCV_ENABLE_NONFREE?

Thanks for any help

carnar gravatar imagecarnar ( 2018-11-14 08:30:14 -0500 )edit

@carnar delete cmakecache.txt and rebuild opencv with OPENCV_ENABLE_NONFREE:BOOL=ON

LBerger gravatar imageLBerger ( 2018-11-14 09:06:18 -0500 )edit

I made it, but still it doesn't work.

Here what I have in the cmakecache.txt...I think is correct...

//Enable non-free algorithms OPENCV_ENABLE_NONFREE:BOOL=ON

//Where to look for additional OpenCV modules (can be ;-separated // list of paths) OPENCV_EXTRA_MODULES_PATH:PATH=C:/Codice/OpenCV/opencv_contrib-3.4.3/modules

carnar gravatar imagecarnar ( 2018-11-14 09:31:12 -0500 )edit

I've noted that surf.cpp include

#include "precomp.hpp" and #include "surf.hpp". Both are only in the directory  'opencv_contrib-3.4.3\modules\xfeatures2d\src'.

Moreover 'precomp.hpp' include opencv_modules,hpp which has the following lines:

// This definition means that OpenCV is built with enabled non-free code.
// For example, patented algorithms for non-profit/non-commercial use only.
/* #undef OPENCV_ENABLE_NONFREE  */

Should I change anything here to define OPENCV_ENABLE_NONFREE = 1?

carnar gravatar imagecarnar ( 2018-11-14 09:53:38 -0500 )edit

No don't change source code. again delete cmakecache an run cmakegui and set OPENCV_ENABLE_NONFEE and after generate you will see in cmake output :

    Unavailable:                 java js python2 python3
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         YES

  Windows RT support:            NO
LBerger gravatar imageLBerger ( 2018-11-14 09:57:44 -0500 )edit