用python写一段ShiTomasi角点检测的代码
时间: 2024-03-17 22:40:28 浏览: 117
好的,以下是用Python实现Shi-Tomasi角点检测的示例代码:
```python
import cv2
import numpy as np
# 读取图片
img = cv2.imread('test.jpg')
# 灰度化处理
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Shi-Tomasi角点检测参数
maxCorners = 100
qualityLevel = 0.3
minDistance = 7
blockSize = 7
# 进行角点检测
corners = cv2.goodFeaturesToTrack(gray, maxCorners, qualityLevel, minDistance, blockSize)
# 转换数据类型
corners = np.int0(corners)
# 绘制角点
for i in corners:
x, y = i.ravel()
cv2.circle(img, (x, y), 3, (0, 0, 255), -1)
# 显示结果
cv2.imshow('Shi-Tomasi Corner Detection', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
这段代码使用OpenCV库实现了Shi-Tomasi角点检测。首先读取一张图片,然后将其转换为灰度图像。接着,设置角点检测的参数,使用`cv2.goodFeaturesToTrack`函数进行角点检测。最后,将检测到的角点绘制在原始图像上,并显示结果。
阅读全文