4

I am using OpenCV version 3.2.0 and xfeatures2d is not found on this. Is there any way I can install this to the same version of OpenCV?

>>> import cv2
>>> help(cv2.xfeatures2d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'xfeatures2d'
Megha
  • 121
  • 1
  • 1
  • 9
  • did you install `opencv_contrib` also? The modules were moved in opencv 3 see http://www.pyimagesearch.com/2015/07/16/where-did-sift-and-surf-go-in-opencv-3/ – EdChum Mar 06 '17 at 11:07
  • @EdChum yes I have installed opencv_contrib as well. – Megha Mar 06 '17 at 11:57
  • It seems that the `opencv_contrib` modules didn't work in your installation. Have you installed Anaconda to run Python (`2.7` or `3.6`?) with your OpenCV? – thewaywewere Apr 16 '17 at 13:28

3 Answers3

1

I encountered the same problem. SURF and SIFT are not a part of the main repo module of OpenCV. Instead, they are available in opencv_contrib folder. The README file of opencv_contrib gives clear instructions on how to install the modules in opencv_contrib.

cd <opencv_build_directory>
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
make -j5

Also note that if you are using OpenCV 3.2, these modules will be installed on Python3.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
1

http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/ This link has all the steps required to install opencv 3 along with opencv_contrib.

In case the xfeatures2d doesn't work even after finishing all the steps mentioned in the above link, then clone https://github.com/opencv/opencv_contrib.git for opencv_contrib.

Megha
  • 121
  • 1
  • 1
  • 9
1

For cv2 version '4.5.2' and '4.5.1' it works!

sift = cv2.SIFT_create()
kp = sift.detect(gimg,None)
img=cv2.drawKeypoints(gimg,kp,img)
plt.imshow(img)

Thanks to https://stackoverflow.com/a/65790734/14578749