Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module 'cv2.cv2' has no attribute 'sift'

When I try:

sift = cv2.sift()

I get at the end the following:

AttributeError: module 'cv2.cv2' has no attribute 'sift'

How can I fix it? Any help would be appreciated

like image 512
Safiya Avatar asked Feb 19 '26 10:02

Safiya


1 Answers

Short answer:

If anyone is getting error while running

sift = cv2.SIFT_create()

Make sure you have

  1. Installed the extra modules of opencv: opencv-contrib (GitHub Repo)
  2. Instead of the code above, run this:
sift = cv2.xfeatures2d.SIFT_create()

Long answer:

This may not be the answer to this specific question, but I decide to write this down just in case anyone might find it hlepful like I did.

I was learning SIFT via Introduction to SIFT (Scale-Invariant Feature Transform), and trying out the code

sift = cv2.SIFT_create()

Which told me the following

AttributeError: module 'cv2.cv2' has no attribute 'SIFT_create'

(Edit: the default doc version in the link above is 4.4.0-pre. If you switch it to 4.3.0 the doc correctly tell you to call the right method. I suppose this means that SIFT will back to main in the next release of 4.4.0)

Then I came to this question and in the comment above the link from @Micka gave me the answer, as shown in the short answer. Thank you Micka!

P.S. The patent has actually expired so SIFT is actually free now, but the work of moving SIFT to main modules is yet to be done as of this moment.

like image 150
Lansorian Avatar answered Feb 22 '26 02:02

Lansorian