原始版本:
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() # 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)
修改版本:
import numpy as np import cv2 from matplotlib import pyplot as plt img = cv2.imread('../data/empire.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, None, color=(255,0,0)) # Print all default params # 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) #this is different 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)
版本问题,将流传的一部分代码修改即可运行~
附上document:http://docs.opencv.org/3.2.0/df/d0c/tutorial_py_fast.html
OpenCv3.2.0+python
最新推荐文章于 2021-02-08 21:04:29 发布