Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIFT() in opencv is not working: 'module' object has no attribute 'SURF'

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:

  • Ubuntu version is 13.10 64bit
  • cv2.__version__ is 2.4.5
  • the output of dir(cv2) is (for the S letter only)

'scaleAdd', 'segmentMotion', 'sepFilter2D', 'setIdentity', 'setMouseCallback', 'setTrackbarPos', 'setUseOptimized', 'setWindowProperty', 'solve', 'solveCubic', 'solvePnP', 'solvePnPRansac', 'solvePoly', 'sort', 'sortIdx', 'split', 'sqrt', 'startWindowThread', 'stereoCalibrate', 'stereoRectify', 'stereoRectifyUncalibrated', 'subtract', 'sumElems'

like image 271
Oz Radiano Avatar asked Feb 09 '14 18:02

Oz Radiano


1 Answers

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]

like image 185
shubham singh Avatar answered Oct 17 '22 09:10

shubham singh