参考资料:Harris和Shi-tomasi角点检测笔记(详细推导)_harris焦点检测_亦枫Leonlew的博客-CSDN博客
cv.goodFeaturesToTrack:Shi-Tomasi角点检测-OpenCV-python_独憩的博客-CSDN博客
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread("../SampleImages/armcore.jpg", cv.IMREAD_COLOR)
plt.imshow(img[:,:,::-1])
#转换为灰度图像
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
plt.imshow(img_gray, plt.cm.gray)
#Shi-Tomasi角点检测
#corners = cv.goodFeaturesToTrack( image, maxCorners, qualityLevel, minDistance[, corners[, mask[, blockSize[, useHarrisDetector[, k]]]]] )
# image:8位或32位浮点型输入图像,单通道
# maxCorners:角点数目最大值,如果实际检测的角点超过此值,则只返回前maxCorners个强角点
# qualityLevel:角点的品质因子,0-1中的数字
# minDistance:对于初选出的角点而言,如果在其周围minDistance范围内存在其他更强角点,则将此角点删除
# _mask:指定感兴趣区,如不需在整幅图上寻找角点,则用此参数指定ROI
# blockSize:计算协方差矩阵时的窗口大小
# useHarrisDetector:指示是否使用Harris角点检测,如不指定,则计算shi-tomasi角点
# harrisK:Harris角点检测需要的k值
# 一般来说,可以只输入image maxCorners, qualityLevel, minDistanc
#参考资料:https://blog.csdn.net/qq_54517101/article/details/121762965
corners = cv.goodFeaturesToTrack(img_gray, 800, 0.09, 5)
#绘制角点
for corner in corners:
x,y = corner.ravel()
cv.circle(img, (int(x),int(y)), 2, (0,255,0), -1)
plt.imshow(img[:,:,::-1])