Harris角点检测算法Python代码
时间: 2023-11-03 18:10:44 浏览: 119
以下是Harris角点检测算法的Python代码示例:
```python
import cv2
import numpy as np
img = cv2.imread('test.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blockSize = 2
apertureSize = 3
k = 0.04
thresh = 200
dst = cv2.cornerHarris(gray, blockSize, apertureSize, k)
dst_norm = np.empty_like(dst)
cv2.normalize(dst, dst_norm, 0, 255, cv2.NORM_MINMAX)
dst_norm_scaled = cv2.convertScaleAbs(dst_norm)
for i in range(dst_norm.shape[0]):
for j in range(dst_norm.shape[1]):
if dst_norm[i,j] > thresh:
cv2.circle(dst_norm_scaled, (j,i), 5, (0), 2)
cv2.namedWindow("Harris corner detector", cv2.WINDOW_NORMAL)
cv2.imshow("Harris corner detector", dst_norm_scaled)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
该代码使用OpenCV库实现了Harris角点检测算法,对输入的图像进行角点检测,并将结果显示出来。其中,blockSize和apertureSize分别表示Harris算法中的窗口大小和Sobel算子的大小,k是常数值,thresh是阈值。
阅读全文