72

So I am trying to use:

sift = cv2.xfeatures2d.SIFT_create()

and it is coming up with this error:

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

I am using Python 3.5.0 and opencv(3.4.3) and I am just using idle. This occured after I tried to install TensorFlow and I have tried looking around and have installed opencv-contrib-python but I am still getting the same error. Thank you in advance and I apologise if I have not included enough info

papabiceps
  • 899
  • 2
  • 16
  • 30
rhonda.rooster
  • 835
  • 1
  • 6
  • 8

4 Answers4

156

I had the same problem. It seems that SIRF and SURF are no longer available in opencv > 3.4.2.16. I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the history version about opencv-python, and I use the following code :

pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16

Edit

For Anaconda User just this instead of pip

conda install -c menpo opencv

this will install cv2 3.4.1 and everything you need to run SIFT

good luck~

FooBar167
  • 2,431
  • 1
  • 24
  • 37
J.Zhao
  • 2,112
  • 1
  • 11
  • 11
  • 5
    This is not working with Python 3.7. I tried with version 3.4.2.16, and I am getting DLL not found error. Base OpenCV is working with version 3.4.5.20 – Nithish V Feb 10 '19 at 14:05
  • 1
    @NithishV did you find solution fot that? im using v3.7 and having this issue. – DragonKnight Feb 25 '19 at 15:44
  • 2
    @DragonKnight, I am able to get it working with opencv-contrib-python version 3.4.5.20 only. Install it using "pip install opencv-contrib-python==3.4.5.20" – Nithish V Feb 26 '19 at 11:01
  • 4
    Quite tricky solution! Seemingly, it only works with a particular version! For the 3.4.2.16 version, I guess the OPENCV_ENABLE_NONFREE is turned on; when I install other version like 4.1.x.x, it will report a error like `OpenCV(4.1.0) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SIFT::create'` – YinchaoOnline May 03 '19 at 13:59
  • 2
    OpenCV stopped including non-free/patented algorithms like SIFT and SURF as of v3.4.3. So either stick with v3.4.2.17, or compile the latest version from source if you need it. – HUSMEN May 14 '19 at 03:00
  • Why is this the solution? I don' get python, it's weird. – Derk Jan Speelman Aug 23 '19 at 14:08
  • It is one of the working solutions (for both python terminal and anaconda environment, both works) I found in the internet. It is Nov 2019, and this still works. Thank you for the simple solution. – CrmXao Nov 18 '19 at 09:45
  • I managed to install the [non conda] solution on Python 3.5, but not on 3.8. seems to work fine. – Ari May 30 '20 at 14:29
  • Works with python 3.6.9. – Mostafa Hadian Nov 11 '20 at 00:30
  • 1
    Not worked for me in Google Colab .it says python version 3.4.2.16 is not available – RusJ Jun 08 '21 at 06:36
  • ```pip install opencv-python==3.4.2.16``` doesn't work. "This release has been yanked" says in OpenCV version history, and videos/articles on how to build from source? Thanks in advance everyone. – Vaggelis Manousakis Mar 11 '22 at 15:05
13

Edit: The opencv-contrib-python-nonfree was removed from pypi.

On Linux/ MacOS, I've found a better solution! To access nonfree detectors use: pip install opencv-contrib-python-nonfree

Udi
  • 27,155
  • 8
  • 91
  • 123
I.R.
  • 422
  • 1
  • 6
  • 15
  • 4
    Could not find a version that satisfies the requirement opencv-contrib-python-nonfree (from versions: ) No matching distribution found for opencv-contrib-python-nonfree – Gulzar Jun 02 '20 at 21:03
  • @Gulzar, I had this issue too. Possible reasons are: 1. Your OS is Windows; 2. You are using Python 3.8. According to this page: https://pypi.org/project/opencv-contrib-python-nonfree/ Windows support is canceled and python 3.8 is not supported (possibly yet). I didn't found any solution to this problem, but on my other computers (Linux and MacOS), everything is fine. – I.R. Jun 03 '20 at 06:59
  • @I.R. What Python version do you use? – Roi Mulia Jul 14 '20 at 11:42
  • @RoiMulia, I use Python 3.6 – I.R. Jul 14 '20 at 13:46
11

Since SIFT patent expired, SIFT has been moved to the main repo. To use SIFT in Opencv, You should use cv2.SIFT_create() instead of cv2.xfeatures2d.SIFT_create() now. (xfeatures2d only exists in the contrib package, but sift is part of the main package now.)

Below link will be helpful. https://github.com/opencv/opencv/issues/16736

Abhi
  • 143
  • 1
  • 9
  • The SIFT patent expired 6th March, 2020. https://patents.google.com/patent/US6711293 – Mel Apr 25 '22 at 00:18
6

It may be due to a mismatch of opencv version and opencv-contrib version. If you installed opencv from the source using CMake, and the source version is different from the version of opencv-contrib-python, uninstall the current opencv-contrib-python and do pip install opencv-contrib-python==<version of the source>.X or an another compatible version. One version setup that I have running is opencv source (3.2), opencv-python (3.4.0.14) and opencv-contrib-python (3.4.2.17)

Ben
  • 61
  • 3
  • The request for info should make into the comments section of the question. You could edit your answer and leave just the workaround/solution. – Cleptus Sep 13 '18 at 08:41
  • Thank you for the comment. Both my opencv-python and opencv-contrib-python version is 3.4.3.18. I assume these would be compatible? – rhonda.rooster Sep 15 '18 at 12:17
  • I am guessing you installed them with `pip install`. Have you done another opencv installation, more specifically have you also installed opencv from the source ? If yes, what is the version of the sources ? I have installed the same version of `opencv-python, opencv-contrib-python` as you but with my 3.2 source installation and I get the same error msg. I would say an easy and lazy hack would be to uninstall opencv-python and opencv-contrib-python and reinstall with the same versions as me and give it a try. – Ben Sep 15 '18 at 16:46
  • still giving me this error :error: OpenCV(4.2.0) /io/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1210: 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' – vanetoj Mar 13 '20 at 16:35
  • According to the error msg, you are using opencv-python==4.2.0 Did you also install `opencv-contrib-python` by running `pip3 install opencv-contrib-python==4.2.0`? – Ben Mar 17 '20 at 13:26