opencv4.7实现提取彩色图像的SURF角点
时间: 2023-11-08 11:06:08 浏览: 72
用opencv实现的SURF特征提取算法
4星 · 用户满意度95%
要在OpenCV 4.7中使用SURF算法提取彩色图像的角点,可以按照以下步骤操作:
1. 导入必要的库和模块:
```
import cv2
import numpy as np
```
2. 读取彩色图像:
```
img = cv2.imread('color_image.jpg')
```
3. 将彩色图像转换为灰度图像:
```
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
```
4. 创建SURF对象:
```
surf = cv2.xfeatures2d.SURF_create()
```
5. 检测图像中的关键点:
```
kp, des = surf.detectAndCompute(gray, None)
```
6. 将关键点绘制在彩色图像上:
```
img_with_keypoints = cv2.drawKeypoints(img, kp, None, (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
```
7. 显示结果:
```
cv2.imshow('SURF keypoints', img_with_keypoints)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
完整代码如下:
```
import cv2
import numpy as np
img = cv2.imread('color_image.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
surf = cv2.xfeatures2d.SURF_create()
kp, des = surf.detectAndCompute(gray, None)
img_with_keypoints = cv2.drawKeypoints(img, kp, None, (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow('SURF keypoints', img_with_keypoints)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
阅读全文