SIFT() in opencv is not working: 'module' object has no attribute 'SURF'

This was driving me crazy but scratch all the other suggestions, turns out you can now get SIFT and SURF with just two terminal commands!

  1. Be sure there is no other opencv on you computer...

    pip uninstall opencv-python
    
  2. Then get the contribute version (has SIFT and SURF + others)...

    pip install opencv-contrib-python
    

It should install but note that the names are a little different.

import cv2
sift = cv2.xfeatures2d.SIFT_create()

!!!pip pip hurray!!! (that's just a pun, not part of the code)


import cv2
sift = cv2.SIFT()

This code will not work if you are using opencv version 3.0 or greater. an alternative of this code is

sift = cv2.xfeatures2d.SIFT_create()
(Only works if you have installed opencv-contrib-python library )

Now again if you have an opencv-contrib-python version > 3.4 than it won't work with a different erro

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SIFT::create'

best solution for this is:

**step 1: pip uninstall opencv-python**

**step 2: pip install opencv-contrib-python==3.4.2.16**

This worked for me.

[Note : If you have not installed opencv using pip install opencv-python, than just go and delete the downloaded library and follow the above instruction]


Not the smoothest way to do it, but it worked for me.

@Berak explained to me, as you can observe in the comments on my question, that the SIFT algorithm, as well as FAST algorithm are patented, which means that they are not part of the regular opencv installation.

Therefore I searched for a python distribution that will have it all - and I found one. So, I didn't actually solved the problem, as @Berak suggested, alternatively I bypassed it using Python(x,y)

Thanks for the help,

Ozrad