2

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

Safiya
  • 185
  • 1
  • 3
  • 11
  • 1
    did you install contrib (and if it exist: nonfree) modules? https://stackoverflow.com/questions/44633378/attributeerror-module-cv2-cv2-has-no-attribute-createlbphfacerecognizer – Micka Sep 13 '18 at 18:03
  • Yes, I try "pip install opencv-contrib-python" but i still have the same error. Thank you but Is there any thing also that I should do? – Safiya Sep 14 '18 at 04:33
  • traditionally, sift ist part of the "nonfree" stuff in opencv. Are you sure that cv2.sift() is right syntax? Have a look at https://www.pyimagesearch.com/2015/07/16/where-did-sift-and-surf-go-in-opencv-3/ – Micka Sep 14 '18 at 07:42

1 Answers1

1

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.

Lansorian
  • 149
  • 3
  • 11