Can't use SURF, SIFT in OpenCV

Linda picture Linda · Sep 1, 2013 · Viewed 130.3k times · Source

I'm trying a simple thing like

detector = cv2.SIFT()

and get this bad error

detector = cv2.SIFT()
AttributeError: 'module' object has no attribute 'SIFT'

I do not understand that because cv2 is installed.

cv2.__version__ is

$Rev: 4557 $

My system is Ubuntu 12.04.

Maybe someone has got the same problem and could help me.

EDIT:

Long story short, testypypypy.py:

import cv2

detector = cv2.SIFT()

ERROR:

Traceback (most recent call last):
  File "testypypy.py", line 3, in <module>
    detector = cv2.SIFT()
AttributeError: 'module' object has no attribute 'SIFT

If I take SURF it works because SURF is in dir(cv2) but if I also take cv2.BFMatcher() I get the same error... So it's missing and I have to add it but I don't know how.

Answer

Tripp Cannella picture Tripp Cannella · Nov 30, 2017

There is a pip source that makes this very easy.

  1. If you have another version of opencv-python installed use this command to remove it to avoid conflicts:

    pip uninstall opencv-python
    
  2. Then install the contrib version with this:

    pip install opencv-contrib-python
    
  3. SIFT usage:

    import cv2
    sift = cv2.xfeatures2d.SIFT_create()