Shi-Tomasi 角点检测和追踪的良好特征
Shi-Tomasi 角落探测器,使用到函数:cv.goodFeaturesToTrack()
它通过 Shi-Tomasi 方法(或 Harris 角点检测,如果你指定它)在图像中找到 N 个最佳的角点。像往常一样,图像应该是灰度图像。然后指定要查找的角点数量。然后指定质量等级,该等级是 0-1 之间的值,所有低于这个质量等级的角点都将被忽略。最后设置检测到的两个角点之间的最小欧氏距离。
该函数选定质量等级最高的角点(即排序后的第一个角点),忽略该角点最小距离范围内的其余角点,以此类推最后返回 N 个最佳的角点。
1 import numpy as np 2 import cv2 as cv 3 from matplotlib import pyplot as plt 4 5 img = cv.imread(r'C:\Users\19225\PycharmProjects\test\src\user\static\9.png') 6 gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) 7 corners = cv.goodFeaturesToTrack(gray, 25, 0.01, 10) 8 corners = np.int0(corners) 9 for i in corners: 10 x, y = i.ravel() 11 cv.circle(img, (x, y), 3, 255, -1) 12 plt.imshow(img), plt.show()
OpenCV 中的 FAST 特征点检测器
它可以像 OpenCV 中的任何其他特征点检测器一样调用。如果需要,您可以指定阈值,是否应用非最大值抑制,要使用的邻域等。
对于邻域,定义了三个标志,cv.FAST_FEATURE_DETECTOR_TYPE_5_8,cv.FAST_FEATURE_DETECTOR_TYPE_7_12 和 cv.FAST_FEATURE_DETECTOR_TYPE_9_16。
1 import numpy as np 2 import cv2 as cv 3 from matplotlib import pyplot as plt 4 5 img = cv.imread(r'C:\Users\19225\PycharmProjects\test\src\user\static\9.png', 0) 6 # Initiate FAST object with default values 7 fast = cv.FastFeatureDetector_create() 8 # find and draw the keypoints 9 kp = fast.detect(img, None) 10 img2 = cv.drawKeypoints(img, kp, None, color=(255, 0, 0)) 11 # Print all default params 12 print("Threshold: {}".format(fast.getThreshold())) 13 print("nonmaxSuppression:{}".format(fast.getNonmaxSuppression())) 14 print("neighborhood: {}".format(fast.getType())) 15 print("Total Keypoints with nonmaxSuppression: {}".format(len(kp))) 16 cv.imwrite('fast_true.png', img2) 17 # Disable nonmaxSuppression 18 fast.setNonmaxSuppression(0) 19 kp = fast.detect(img, None) 20 print("Total Keypoints without nonmaxSuppression: {}".format(len(kp))) 21 img3 = cv.drawKeypoints(img, kp, None, color=(255, 0, 0)) 22 cv.imwrite(r'C:\Users\19225\PycharmProjects\test\src\user\static\2.jpg', img3) 23 cv.imshow('fast_false.png', img3) 24 cv.imshow('fast_true.png', img2) 25 cv.waitKey(0)