AttributeError: module 'cv2' has no attribute 'SURF'
时间: 2023-09-24 08:09:56 浏览: 198
This error occurs when you try to use the SURF feature detector in OpenCV using the cv2 module, but it is not available in the version of OpenCV you are using.
SURF is a patented algorithm and was removed from OpenCV due to licensing issues. It has been replaced by the SIFT feature detector.
To use SIFT, you can use the following code:
```
import cv2
# Load an image
img = cv2.imread('image.jpg')
# Convert the image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Initialize SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
# Detect keypoints and descriptors
keypoints, descriptors = sift.detectAndCompute(gray, None)
```
Note that you need to install the `opencv-contrib-python` package to use the `xfeatures2d` module.
阅读全文