4

I'm on Windows 10 and installed python3 and added OpenCV and OpenCV-contrib via pip. For the xfeatures_2d it gives the following error.

Can I add that option using pip?

detector = cv.xfeatures2d_SURF.create(hessianThreshold=minHessian)

cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\surf.cpp:1016: 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 'cv::xfeatures2d::SURF::create'

Jorg Lueke
  • 51
  • 1
  • 4
  • Unfortunately you cannot add this function directly by pip. This option a compiling option, if you do have the habits to compile your own version of the libraries you use it is not long to configure. Otherwise you can try something like anaconda which contain several version of opencv most are compiled with your missing flag. – John_Sharp1318 Sep 30 '18 at 04:44
  • This is not related to contrib. I compile three to four time per year OpenCV for the last five years, and I use both in C++ and Python daily. I work with both the regular and the contrib modules. I know that flag and I know you cannot fix it by pip. – John_Sharp1318 Sep 30 '18 at 05:05
  • @John_Sharp1318 just deleted my comment right before you added---I didn't read OP's error message, lol. I thought the syntax was wrong (should be `xfeatures2d.SURF_create()`), but you're right. – alkasm Sep 30 '18 at 05:06
  • Don't worry :). I know it is always boring when such thing happen. I strongly recommand you to use anaconda if you can it reduce a lot such burden. – John_Sharp1318 Sep 30 '18 at 05:14
  • 1
    I turned this into an actual answer on another one of the same questions here: https://stackoverflow.com/questions/52669705/attributeerror-module-cv2-cv2-has-no-attribute-xfeatures2d-opecv-3-4-3/52674646#52674646. @John_Sharp1318 if you had answered this question I could have flagged it as a duplicate! :P – alkasm Oct 06 '18 at 00:24
  • @Alexander Reynolds. I agree about the fact they are related, but I do disagree with the duplication. In the link you shared the issue come from the fact the whole 'xfeatures2d' module seem not have been compiled. xfeatures2d is not restricted to SIFT and SURF it also does contains many other features descriptor that are not conserned by the flag OPENCV_ENABLE_NONFREE. – John_Sharp1318 Oct 06 '18 at 19:29
  • @John_Sharp1318 fml, I swear I'm not usually this bad at answering questions. Please provide the correct answers if you have the time for these! – alkasm Oct 06 '18 at 21:56
  • @Alexander Reynolds, I post an answer I hope it helps. – John_Sharp1318 Oct 07 '18 at 06:25
  • @John_Sharp1318 great, and I've ported that other answer over to here. – alkasm Oct 07 '18 at 07:05
  • I had the same problem,you can see [answer](https://stackoverflow.com/questions/55154324/error-the-function-feature-is-not-implementedthe-algorithm-is-patented) Hope that can help you! – liwei ni Mar 14 '19 at 09:02

2 Answers2

4

As discussed in the comments, you can no longer get the non-free modules via pip. The PyPI package opencv-python-contrib used to "erroneously" contain the non-free packages such as SIFT. This was "fixed" recently, so they no longer install with newer versions of opencv-python-contrib. From the GitHub issue tracker for the PyPI package:

Those algorithms have been included erroneously before because they were not properly protected in the upstream by the OPENCV_ENABLE_NONFREE flag.

I am not a lawyer. I'm not sure if I can redistribute those algorithms.

Edit: See: opencv/opencv_contrib#1668

alkasm
  • 22,094
  • 5
  • 78
  • 94
0

This solution worked for me!

pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com opencv-contrib-python==3.4.2.17

source :[https://www.programmersought.com/article/36184723625/]

RusJaI
  • 666
  • 1
  • 7
  • 28