harris角点检测python示例
时间: 2023-09-20 18:14:20 浏览: 98
Sure, here is an example code for Harris corner detection in Python:
```
import cv2
import numpy as np
# Load image
img = cv2.imread('image.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Set parameters for Harris corner detection
block_size = 2
ksize = 3
k = 0.04
threshold = 0.01
# Compute corners using Harris corner detection
dst = cv2.cornerHarris(gray, block_size, ksize, k)
dst_norm = np.empty_like(dst)
cv2.normalize(dst, dst_norm, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)
dst_norm_scaled = cv2.convertScaleAbs(dst_norm)
# Draw circles around corners
for i in range(dst_norm.shape[0]):
for j in range(dst_norm.shape[1]):
if int(dst_norm[i,j]) > threshold:
cv2.circle(img, (j,i), 5, (0,255,0), 2)
# Display image with detected corners
cv2.imshow('Harris Corner Detection', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
This code loads an image, converts it to grayscale, and applies Harris corner detection to find the corners in the image. It then draws circles around the detected corners and displays the resulting image. The parameters for Harris corner detection (block size, kernel size, and k value) can be adjusted to change the sensitivity and accuracy of the algorithm.
阅读全文