Reputation: 875
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
Upvotes: 76
Views: 137280
Reputation: 363
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.
Upvotes: 23
Reputation: 41
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.
Upvotes: 1
Reputation: 91
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.
A popup window should appear, choose the suitable configurations
Wait for the progress bar to finish.
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'
Extra:
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!
Upvotes: 2
Reputation: 61
You can try if python version is latest.
pip install opencv-contrib-python==4.4.0.46
Upvotes: 0
Reputation: 2330
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
Upvotes: 156
Reputation: 502
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
Upvotes: 13
Reputation: 71
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)
Upvotes: 7