75

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
  • 988
  • 2
  • 18
  • 33
rhonda.rooster
  • 865
  • 1
  • 6
  • 8

7 Answers7

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

starball
  • 20,030
  • 7
  • 43
  • 238
J.Zhao
  • 2,250
  • 1
  • 14
  • 12
  • 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
  • 3
    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
  • 2
    Not worked for me in Google Colab .it says python version 3.4.2.16 is not available – RusJaI 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
  • Why downgrading the whole module when you can get the same feature by simply doing `sift = cv2.SIFT_create()` ? – Tms91 Aug 06 '23 at 18:11
18

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()

xfeatures2d only exists in the contrib package, but sift is part of the main package now.

This link will be helpful.

Tms91
  • 3,456
  • 6
  • 40
  • 74
Abhirami V S
  • 313
  • 2
  • 9
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
  • 29,222
  • 9
  • 96
  • 129
I.R.
  • 442
  • 1
  • 7
  • 16
  • 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
7

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
  • 71
  • 4
  • 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
1

I use OpenCV version 4.7 and this works for me:

cv2.SIFT_create()

the xfeatures2d.SIFT_create() method was removed because of some patent issues and is available in the short form as above.

Tms91
  • 3,456
  • 6
  • 40
  • 74
gal peled
  • 31
  • 3
0

You can try if python version is latest.

pip install opencv-contrib-python==4.4.0.46

Bangash Owais
  • 61
  • 1
  • 7
0

I've been into this problem for many hours and finally I've solved it, and I'll share with you (and for any body else) how to solve it.

Here are the steps:

1- Download CMAKE from the official website.

2- Download Visual Studio

3- Download OpenCV Sources.zip files.

4- Download OpenCV-contrib from github.


  • First, we'll create a directory and name it 'OpenCV', this directory will contain the 'opencv-x.x.x' and 'opencv_contrib-x.x.x' downloaded extracted files.

  • We'll also create a 'build' directory that will contain the new OpenCV build files.

enter image description here


  • The next step is to run the CMake (cmake-gui) app. enter image description here

  • You should then
    1. locate the 'opencv-x.x.x' extracted folder in the directory we created 'OpenCV'.
    2. do the same for the 'build' folder.

enter image description here

  • After doing that, click on 'Configure'

enter image description here


  • A popup window should appear, choose the suitable configurations enter image description here

  • Wait for the progress bar to finish.


  • Check the OPENCV_ENABLE_NONFREE, then click 'Configure' again and wait for the progress bar.

enter image description here


  • After it is done loading, click 'Generate', right next to 'Configure' button.

  • Congrats, you've done the first steps!


  • Okay, close the CMAKE (cmake-gui) app and go to the 'build' directory we created.

  • locate 'OpenCV.sln' and run it using Visual Studio.

  • Change vs build mode from 'Debug' to 'Release'.

  • On the right 'Solution Explorer' menu, locate 'CMakeTargets' >> 'ALL_BUILD', right click it and select 'Build'

  • Wait for it to build (it may take 5+ minutes)

  • Again, on the right 'Solution Explorer' menu, locate 'CMakeTargets' >> 'INSTALL', right click it and select 'Build'

enter image description here

enter image description here

  • After it finishes loading, you can then use it, that's all!

Extra:

  • You can freely uninstall any pre-installations of 'opencv-python' and 'opencv-contrib-python' via the the pip
    pip uninstall opencv-python
    pip uninstall opencv-contrib-python
  • Reboot your device.

  • Test OpenCV. Open a terminal and type

    $ python
    >>> import cv2
    >>> cv2.__version__

Hope this helps, thank you!