Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' [Opencv 3.4.3]

Tags:

python

opencv

I have opencv 3.4.3 installed (using pip3 install opencv-python and pip3 install opencv-python-contrib)

When I run a code containing this line:
sift = cv2.xfeatures2d.SIFT_create()
I got this error:

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

Is xfeatures2d function not anymore supported by opencv 3.4.3?

like image 297
singrium Avatar asked Oct 05 '18 16:10

singrium


2 Answers

The error message you have is related to the fact that the module xfeatures2d does not exist. It is not directly related to SIFT algorithm nor any algorithm in xfeatures2d (all will send that error). I suggest you to either reinstall opencv-contrib-python(pip install opencv-contrib-python) or if you are using anaconda or equivalent to re-install the two opencv package from another source repository. A last option consist to compile the full OpenCV ("regular" + contrib) by yourself if you are comfortable with it.

Hope it helps.

like image 187
John_Sharp1318 Avatar answered Sep 21 '22 10:09

John_Sharp1318


After hours of hair pulling and installing / compiling everything from the scratch, I needed to post this for other people who might be doing the same little stupid mistake I was doing.

If you have both opencv-python and opencv-contrib-python installed in your system and still getting this error, instead of

 sift = cv2.xfeatures2d.SIFT_create()

try

 sift = cv2.SIFT_create()
like image 33
Ege Akat Avatar answered Sep 19 '22 10:09

Ege Akat