cv2.DescriptorMatcher_create()使用BruteForce的代码
时间: 2024-05-08 22:16:17 浏览: 110
以下是使用BruteForce匹配器的示例代码:
```python
import cv2
# 读取图像
img1 = cv2.imread('img1.jpg', cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread('img2.jpg', cv2.IMREAD_GRAYSCALE)
# 创建ORB特征点检测器和描述符提取器
orb = cv2.ORB_create()
# 检测关键点和描述符
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)
# 创建BruteForce匹配器
bf = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_BRUTEFORCE_HAMMING)
# 匹配特征点描述符
matches = bf.match(des1, des2)
# 根据匹配结果排序
matches = sorted(matches, key=lambda x: x.distance)
# 绘制匹配结果
img3 = cv2.drawMatches(img1, kp1, img2, kp2, matches[:10], None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
# 显示图像
cv2.imshow('Matches', img3)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
阅读全文