Where is the FAST algorithm in OpenCV?

KilianK picture KilianK · May 13, 2016 · Viewed 10.1k times · Source

I'm not able to find the FAST corner detector in the Python OpenCV module, I tried this this like described in that link. My OpenCV version is 3.1.0.

I know that feature-description algorithms like SIFT and SURF were shifted to cv2.xfeatures2d, but the FAST algorithm is not located there.

Answer

Yahya Tawil picture Yahya Tawil · Mar 6, 2017

I think the example code in opencv-3.1.0 documentation is not updated. The provided code will not work.

Try this one:

    # Ref: https://github.com/jagracar/OpenCV-python-tests/blob/master/OpenCV-tutorials/featureDetection/fast.py
import numpy as np
import cv2
from matplotlib import pyplot as plt

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

# Initiate FAST object with default values
fast = cv2.FastFeatureDetector_create(threshold=25)

# find and draw the keypoints
kp = fast.detect(img,None)
img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))

print("Threshold: ", fast.getThreshold())
print("nonmaxSuppression: ", fast.getNonmaxSuppression())
print("neighborhood: ", fast.getType())
print("Total Keypoints with nonmaxSuppression: ", len(kp))

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

# Disable nonmaxSuppression
fast.setNonmaxSuppression(0)
kp = fast.detect(img,None)

print "Total Keypoints without nonmaxSuppression: ", len(kp)

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

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