话不多说,上代码,看结果。
import cv2 # 导入库
img = cv2.imread('38.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
'''
cv2.cornerHarris(src, blockSize, ksize, k, dst, borderType)
# src: 输入原图, 需为8位单通道或浮点类型图像
# dst: Harris角点检测结果, 类型为CV_32FC1, 大小和原图一样
# blockSize: 邻域大小
# ksize: 表示Sobel()算子孔径大小
# k: Harris检测常量参数, 通常情况取值为0.04~0.06
# borderType: 图像像素的边界模式,一般采用默认值
'''
dst = cv2.cornerHarris(gray, 2, 3, 0.04)
ret, thresh = cv2.threshold(dst, 0.01, 255, cv2.THRESH_BINARY)
cv2.imshow('thresh', thresh)
for i in range(0, img.shape[0]):
for j in range(0, img.shape[1]):
if dst[i, j] > 0.01:
cv2.circle(img, (j, i), 5, (0, 255, 0), 2, cv2.LINE_AA)
cv2.imshow('result', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
结果如下图。
就先这样,遇到别的再补充。