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

Oz Radiano picture Oz Radiano · Feb 9, 2014 · Viewed 15.8k times · Source

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'

Answer

Tripp Cannella picture Tripp Cannella · Nov 29, 2017

This was driving me crazy but scratch all the other suggestions, turns out you can now get SIFT and SURF with just two terminal commands!

  1. Be sure there is no other opencv on you computer...

    pip uninstall opencv-python
    
  2. Then get the contribute version (has SIFT and SURF + others)...

    pip install opencv-contrib-python
    

It should install but note that the names are a little different.

import cv2
sift = cv2.xfeatures2d.SIFT_create()

!!!pip pip hurray!!! (that's just a pun, not part of the code)