I am trying to run the simplest opencv SIFT code through the shell of Ubuntu, with no luck
I get an error:
AttributeError: 'module' object has no attribute 'SURF'
The code:
import cv2
cv2.SIFT()
My configurations:
cv2.__version__
is 2.4.5'scaleAdd', 'segmentMotion', 'sepFilter2D', 'setIdentity', 'setMouseCallback', 'setTrackbarPos', 'setUseOptimized', 'setWindowProperty', 'solve', 'solveCubic', 'solvePnP', 'solvePnPRansac', 'solvePoly', 'sort', 'sortIdx', 'split', 'sqrt', 'startWindowThread', 'stereoCalibrate', 'stereoRectify', 'stereoRectifyUncalibrated', 'subtract', 'sumElems'
import cv2
sift = cv2.SIFT()
This code will not work if you are using opencv version 3.0 or greater. an alternative of this code is
sift = cv2.xfeatures2d.SIFT_create()
(Only works if you have installed opencv-contrib-python library )
Now again if you have an opencv-contrib-python version > 3.4 than it won't work with a different erro
error: OpenCV(4.1.0) 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'
best solution for this is:
**step 1: pip uninstall opencv-python**
**step 2: pip install opencv-contrib-python==3.4.2.16**
This worked for me.
[Note : If you have not installed opencv using pip install opencv-python, than just go and delete the downloaded library and follow the above instruction]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With