【翻譯:OpenCV-Python教程】角點檢測的快速(FAST)算法

⚠️由於自己的拖延症,3.4.3翻到一半,OpenCV發佈了4.0.1了正式版,所以接下來是按照4.0.1翻譯的。

⚠️除了版本之外,其他還是照舊,FAST Algorithm for Corner Detection,原文

目標

在本章,

  • 我們將瞭解快速(FAST)算法的基礎知識
  • 我們將使用OpenCV的快速算法函數找到的角點。

理論

我們看到了幾個特徵檢測器,其中很多都非常棒。但是從實時應用程序的角度來看,它們的運算速度還不夠快。一個最好的例子是SLAM(同步定位和映射)移動機器人,它的用於計算的資源非常有限。

作爲一個解決方案,在2006年 (後來在2010年修訂) Edward Rosten 和 Tom Drummond 在他們的論文"Machine learning for high-speed corner detection"裏推薦FAST (Features from Accelerated Segment Test) 算法。A basic summary of the algorithm is presented below. Refer original paper for more details (All the images are taken from original paper).

Feature Detection using FAST

  1. Select a pixel p in the image which is to be identified as an interest point or not. Let its intensity be Ip.
  2. Select appropriate threshold value t.
  3. Consider a circle of 16 pixels around the pixel under test. (See the image below)

    fast_speedtest.jpg

    image

  4. Now the pixel p is a corner if there exists a set of n contiguous pixels in the circle (of 16 pixels) which are all brighter than Ip+t, or all darker than Ip−t. (Shown as white dash lines in the above image). n was chosen to be 12.
  5. A high-speed test was proposed to exclude a large number of non-corners. This test examines only the four pixels at 1, 9, 5 and 13 (First 1 and 9 are tested if they are too brighter or darker. If so, then checks 5 and 13). If p is a corner, then at least three of these must all be brighter than Ip+t or darker than Ip−t. If neither of these is the case, then p cannot be a corner. The full segment test criterion can then be applied to the passed candidates by examining all pixels in the circle. This detector in itself exhibits high performance, but there are several weaknesses:
    • It does not reject as many candidates for n < 12.
    • The choice of pixels is not optimal because its efficiency depends on ordering of the questions and distribution of corner appearances.
    • Results of high-speed tests are thrown away.
    • Multiple features are detected adjacent to one another.

First 3 points are addressed with a machine learning approach. Last one is addressed using non-maximal suppression.

Machine Learning a Corner Detector

  1. Select a set of images for training (preferably from the target application domain)
  2. Run FAST algorithm in every images to find feature points.
  3. For every feature point, store the 16 pixels around it as a vector. Do it for all the images to get feature vector P.
  4. Each pixel (say x) in these 16 pixels can have one of the following three states:

    fast_eqns.jpg

    image

  5. Depending on these states, the feature vector P is subdivided into 3 subsets, Pd, Ps, Pb.
  6. Define a new boolean variable, Kp, which is true if p is a corner and false otherwise.
  7. Use the ID3 algorithm (decision tree classifier) to query each subset using the variable Kp for the knowledge about the true class. It selects the x which yields the most information about whether the candidate pixel is a corner, measured by the entropy of Kp.
  8. This is recursively applied to all the subsets until its entropy is zero.
  9. The decision tree so created is used for fast detection in other images.

Non-maximal Suppression

Detecting multiple interest points in adjacent locations is another problem. It is solved by using Non-maximum Suppression.

  1. Compute a score function, V for all the detected feature points. V is the sum of absolute difference between p and 16 surrounding pixels values.
  2. Consider two adjacent keypoints and compute their V values.
  3. Discard the one with lower V value.

Summary

It is several times faster than other existing corner detectors.

But it is not robust to high levels of noise. It is dependent on a threshold.

FAST Feature Detector in OpenCV

It is called as any other feature detector in OpenCV. If you want, you can specify the threshold, whether non-maximum suppression to be applied or not, the neighborhood to be used etc.

For the neighborhood, three flags are defined, cv.FAST_FEATURE_DETECTOR_TYPE_5_8, cv.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv.FAST_FEATURE_DETECTOR_TYPE_9_16. Below is a simple code on how to detect and draw the FAST feature points.

import numpy as np

import cv2 as cv

from matplotlib import pyplot as plt

img = cv.imread('simple.jpg',0)

# Initiate FAST object with default values

fast = cv.FastFeatureDetector_create()

# find and draw the keypoints

kp = fast.detect(img,None)

img2 = cv.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)) )

cv.imwrite('fast_true.png',img2)

# Disable nonmaxSuppression

fast.setNonmaxSuppression(0)

kp = fast.detect(img,None)

print( "Total Keypoints without nonmaxSuppression: {}".format(len(kp)) )

img3 = cv.drawKeypoints(img, kp, None, color=(255,0,0))

cv.imwrite('fast_false.png',img3)

See the results. First image shows FAST with nonmaxSuppression and second one without nonmaxSuppression:

fast_kp.jpg

image

額外資源

  1. Edward Rosten and Tom Drummond, “Machine learning for high speed corner detection” in 9th European Conference on Computer Vision, vol. 1, 2006, pp. 430–443.
  2. Edward Rosten, Reid Porter, and Tom Drummond, "Faster and better: a machine learning approach to corner detection" in IEEE Trans. Pattern Analysis and Machine Intelligence, 2010, vol 32, pp. 105-119.

練習


上篇:【翻譯:OpenCV-Python教程】SURF (Speeded-Up Robust Features) 介紹

下篇:【翻譯:OpenCV-Python教程】圖像金字塔

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章