Fix AttributeError: module ‘cv2’ has no attribute ‘xfeatures2d’ – Python OpenCV Tutorial

By | August 1, 2022

When we are using python opencv to compare the similarity of two images, we may get this error: AttributeError: module ‘cv2’ has no attribute ‘xfeatures2d’. In this tutorial, we will introduce how to fix it.

This error may look like:

Fix AttributeError module 'cv2' has no attribute 'xfeatures2d'

As to code:

sift = cv2.xfeatures2d.SIFT_create()

cv2.xfeatures2d does not exist in python opencv.

How to fix this AttributeError?

We should change the opencv version.

As to us, we can fix this error by these steps:

Step 1: uninstall python opencv installed.

pip uninstall opencv-python

Step 2: install opencv-python==3.4.2.16

pip install -i https://mirrors.aliyun.com/pypi/simple/ opencv-python==3.4.2.16 --trusted-host mirrors.aliyun.com

Step 3: install opencv-contrib-python==3.4.2.16

pip install -i https://mirrors.aliyun.com/pypi/simple/ opencv-contrib-python==3.4.2.16 --trusted-host mirrors.aliyun.com

Then, this error is fixed in our python application.

We should notice: if the python version is >3.7, this method may do not work. Because opencv-python==3.4.2.16 is not supported then python version > 3.7

Fix AttributeError module 'cv2' has no attribute 'xfeatures2d' - Python OpenCV Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *