Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'module' object has no attribute 'xfeatures2d' [Python/OpenCV 2.4]

Tags:

python

opencv

This line:

sift = cv2.xfeatures2d.SIFT_create()

return error:

Traceback (most recent call last):
  File "C:/Python27/openCVskrypty/GUI/SOLUTION2.py", line 11, in <module>
    sift = cv2.xfeatures2d.SIFT_create()
AttributeError: 'module' object has no attribute 'xfeatures2d'

I read something about this error and it appears in OpenCV version 3.0. This is quite weird because I have 2.4.11 version.

I check dir(cv2) and I haven't got xfeatures2d module. Does anyone know why? Can I download it separately?

Thanks for help how fix this.

like image 622
Lipstick Avatar asked May 04 '16 22:05

Lipstick


3 Answers

I think you should install opencv-contrib-python instead. The module you're using is not support in opencv-python. See opencv-contrib-python.

To install:

pip install opencv-contrib-python
like image 178
Shao-Kui Avatar answered Nov 16 '22 18:11

Shao-Kui


SIFT is a patented algorithm, hence not available in each open-cv version. What you can do is install opencv and its contrib part simultaneously, i.e,

pip install opencv-python==3.3.0.10 opencv-contrib-python==3.3.0.10

SIFT worked fine for me on above versions of opencv.

like image 32
Shankul Shukla Avatar answered Nov 16 '22 16:11

Shankul Shukla


For CV2 Version 4.5.1, this works

sift = cv2.SIFT_create()
kp = sift.detect(gimg,None)
img=cv2.drawKeypoints(gimg,kp,img)
plt.imshow(img)
like image 19
Usama Imdad Avatar answered Nov 16 '22 16:11

Usama Imdad