1. 角点检测
Harris角点检测
import cv2
import numpy as np
from matplotlib import pyplot as plt
img=cv2.imread('timg.jpg') #原图为彩色图,可将第二个参数变为0,为灰度图
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# 输入图像必须是float32, 最后一个参数[0.04,0.06]
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04) #输入图像的数据类型必须为float32,
dst = cv2.dilate(dst,None) #放大标记角点,利于显示
img[dst>0.01*dst.max()]=[0,0,255]#最佳值的阈值选用0.01*dst.max(),可能会根据图像而有所不同。
cv2.imshow('dst',img)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
cv2.imwrite('test.png',img)
Shi-Tomasi角点检测
import numpy as np