Shi-Tomasi 角點(diǎn)檢測(cè)和追蹤的良好特征
Shi-Tomasi 角落探測(cè)器,使用到函數(shù):cv.goodFeaturesToTrack()
它通過(guò) Shi-Tomasi 方法(或 Harris 角點(diǎn)檢測(cè),如果你指定它)在圖像中找到 N 個(gè)最佳的角點(diǎn)。像往常一樣,圖像應(yīng)該是灰度圖像。然后指定要查找的角點(diǎn)數(shù)量。然后指定質(zhì)量等級(jí),該等級(jí)是 0-1 之間的值,所有低于這個(gè)質(zhì)量等級(jí)的角點(diǎn)都將被忽略。最后設(shè)置檢測(cè)到的兩個(gè)角點(diǎn)之間的最小歐氏距離。
該函數(shù)選定質(zhì)量等級(jí)最高的角點(diǎn)(即排序后的第一個(gè)角點(diǎn)),忽略該角點(diǎn)最小距離范圍內(nèi)的其余角點(diǎn),以此類推最后返回 N 個(gè)最佳的角點(diǎ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 特征點(diǎn)檢測(cè)器
它可以像 OpenCV 中的任何其他特征點(diǎn)檢測(cè)器一樣調(diào)用。如果需要,您可以指定閾值,是否應(yīng)用非最大值抑制,要使用的鄰域等。
對(duì)于鄰域,定義了三個(gè)標(biāo)志,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)

浙公網(wǎng)安備 33010602011771號(hào)