2016-05-13 1 views
2

Je ne suis pas en mesure de trouver le détecteur de coin FAST dans le module Python OpenCV, J'ai essayé ce this comme décrit dans ce link. Ma version OpenCV est 3.1.0.Où est l'algorithme FAST dans OpenCV?

Je sais que les algorithmes de description de caractéristiques comme SIFT et SURF ont été déplacés vers cv2.xfeatures2d, mais l'algorithme FAST ne s'y trouve pas.

Répondre

1

Selon opencv-3.1.0 documentation Vous pouvez exécuter FAST en python ainsi:

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() 

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

# Print all default params 
print "Threshold: ", fast.getInt('threshold') 
print "nonmaxSuppression: ", fast.getBool('nonmaxSuppression') 
print "neighborhood: ", fast.getInt('type') 
print "Total Keypoints with nonmaxSuppression: ", len(kp) 

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

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

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

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

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

Je pense que l'exemple de code dans la documentation OpenCV-3.1.0 est pas mis à jour. Le code fourni ne fonctionnera pas.

Essayez celui-ci:

# 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)