sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed
Asked Answered
E

7

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

Elamitic answered 13/9, 2018 at 1:52 Comment(0)
F
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

Fabric answered 26/9, 2018 at 9:13 Comment(12)
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.20Fetishist
@NithishV did you find solution fot that? im using v3.7 and having this issue.Mcalpin
@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"Fetishist
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'Steffi
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.Amboise
Why is this the solution? I don' get python, it's weird.Bucaramanga
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.Acentric
I managed to install the [non conda] solution on Python 3.5, but not on 3.8. seems to work fine.Toadeater
Works with python 3.6.9.Indivisible
Not worked for me in Google Colab .it says python version 3.4.2.16 is not availableGamages
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.Zebada
Why downgrading the whole module when you can get the same feature by simply doing sift = cv2.SIFT_create() ?Propraetor
J
20

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.

Javelin answered 11/8, 2021 at 6:19 Comment(1)
The SIFT patent expired 6th March, 2020. patents.google.com/patent/US6711293Marcellemarcellina
C
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

Cardiff answered 2/5, 2020 at 10:4 Comment(4)
Could not find a version that satisfies the requirement opencv-contrib-python-nonfree (from versions: ) No matching distribution found for opencv-contrib-python-nonfreeJohppa
@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: 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.Cardiff
@Cardiff What Python version do you use?Geodesy
@RoiMulia, I use Python 3.6Cardiff
T
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)

Twittery answered 13/9, 2018 at 8:24 Comment(5)
The request for info should make into the comments section of the question. You could edit your answer and leave just the workaround/solution.Irate
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?Elamitic
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.Twittery
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'Middleclass
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?Twittery
C
2

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!

Chockfull answered 17/4, 2023 at 2:30 Comment(0)
G
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.

Gouty answered 15/6, 2023 at 7:0 Comment(0)
G
0

You can try if python version is latest.

pip install opencv-contrib-python==4.4.0.46

Gynecology answered 6/4, 2023 at 3:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.