2016-05-13 78 views
2

我無法在Python OpenCV模塊中找到FAST角點檢測器, 我試過this,就像link中所述。我的OpenCV版本是3.1.0。OpenCV中的FAST算法在哪裏?

我知道像SIFT和SURF這樣的特徵描述算法已經轉移到了cv2.xfeatures2d,但是FAST算法並不在那裏。

回答

1

根據opencv-3.1.0 documentation您可以在Python跑得快是這樣的:

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

我想的OpenCV-3.1.0文檔中的示例代碼不會被更新。提供的代碼將不起作用。

試試這個:

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