Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use SURF, SIFT in OpenCV

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.

like image 635
Linda Avatar asked Sep 01 '13 19:09

Linda


People also ask

Which version of Opencv has surf?

To get access to the original SIFT and SURF implementations found in OpenCV 2.4. X, you'll need to pull down both the opencv and opencv_contrib repositories from GitHub and then compile and install OpenCV 3 from source.


1 Answers

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() 
like image 155
Tripp Cannella Avatar answered Sep 20 '22 18:09

Tripp Cannella