原理(略)
OpenCV 中 FAST 特征检测器
FAST 算法比其它角点检测算法都快。
但是在噪声很高时不够稳定,这是由阈值决定的。
和其他特征点检测一样我们可以在 OpenCV 中直接使用 FAST特征检测器。如果你愿意的话,你还可以设置阈值,是否进行非最大值抑制,要使用的邻域大小等。
代码示例:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('head.jpg')
# Initiate FAST object with default values
fast = cv2.FastFeatureDetector_create()
# find and draw the keypoints
kp = fast.detect(img,None)
img2 = cv2.drawKeypoints(img,kp,None,color=(255,0,0))
# Print all default params
print ('Threshold:{}'.format(fast.getThreshold()))
print ('nonmaxSuppression:{}'.format(fast.getNonmaxSuppression()))
print ('neighborhood:{}'.format(fast.getType()))
print ('Total Keypoints with nonmaxSuppression:{}'.format(len(kp)))
# Disable nonmaxSuppression
fast.setNonmaxSuppression(0)
kp = fast.detect(img,None)
print ('Total Keypoints without nonmaxSuppression:{}'.format(len(kp)))
img3 = cv2.drawKeypoints(img,kp,None,color=(255,0,0))
plt.subplot(131),plt.imshow(img)
plt.title('src'),plt.xticks([]),plt.yticks([])
plt.subplot(132),plt.imshow(img2)
plt.title('with NMS'),plt.xticks([]),plt.yticks([])
plt.subplot(133),plt.imshow(img3)
plt.title('without NMS'),plt.xticks([]),plt.yticks([])
plt.show()
Threshold:10
nonmaxSuppression:True
neighborhood:2
Total Keypoints with nonmaxSuppression:130
Total Keypoints without nonmaxSuppression:779