OpenCV中的快速特征檢測——FAST(Features from Accelerated Segment Test)
- 1. 效果圖
- 2. 原始碼
- 參考
- OpenCV中的尺度不變特征變換(SIFT Scale-Invariant Feature Transform)
- OpenCV中的SURF(Speeded-Up Robust Features 加速魯棒特征)
這篇博客將延續上倆篇博客,介紹OpenCV中的快速檢測特征——角點檢測的快速演算法,SURF相比SIFT速度有所提升,但從實時應用程式的角度來看,速度還不夠快, 一個最好的例子是SLAM(Simultaneous Localization and Mapping 同步定位和映射)移動機器人,它的計算資源有限,于是有了本文的快速演算法,
FAST (Features from Accelerated Segment Test) 加速段測驗的特征
FAST用于角點的高速檢測,更快更好,
FAST比其他現有的角點探測器快幾倍,但它對高水平的噪音不穩定,這取決于閾值,
1. 效果圖
原始圖如下:

FAST效果圖如下:
左圖顯示帶非極大值抑制的FAST(關鍵點846個),右圖顯示不帶非極大值抑制的FAST(關鍵點2426個);

2. 原始碼
# 快速特征檢測——FAST(Features from Accelerated Segment Test) 加速段測驗的特征
# FAST用于角點的高速檢測,更快更好,
# 快速演算法比其他現有的角點探測器快幾倍,但它對高水平的噪音不穩定,這取決于閾值,
import cv2
origin = cv2.imread('images/simple.jpg')
cv2.imshow("origin", origin)
gray = cv2.cvtColor(origin, cv2.COLOR_BGR2GRAY)
# 使用默認引數初始化快速特征檢測器
# fast = cv2.FastFeatureDetector() # opencv2
fast = cv2.FastFeatureDetector_create() # opencv3
print(fast)
# 尋找和繪制關鍵點
kp = fast.detect(gray, None)
img2 = cv2.drawKeypoints(gray, kp, outImage=gray, color=(255, 0, 0))
print('defaultParameter res keypoints: ', len(kp))
# 不支持列印所有的引數
# print("Threshold: ", fast.getThreshold('threshold'))
# print("nonmaxSuppression: ", fast.getNonmaxSuppression('nonmaxSuppression'))
# print("neighborhood: ", fast.getType('type'))
# print("Total Keypoints with nonmaxSuppression: ", len(kp))
cv2.imshow("default res", img2)
cv2.imwrite('fast_true.png', img2)
# 抑制極大值抑制 Disable nonmaxSuppression
fast.setNonmaxSuppression(0)
kp = fast.detect(gray, None)
print("Total Keypoints without nonmaxSuppression: ", len(kp))
img3 = cv2.drawKeypoints(gray, kp, gray, color=(255, 0, 0))
cv2.imshow("nonmaxSuppression res", img3)
cv2.waitKey(0)
cv2.imwrite('fast_false.png', img3)
參考
- https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_fast/py_fast.html#fast
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/291591.html
標籤:其他
