我正在尝试提取特征以便随后训练一个SVM,这将用于Android应用程序。我使用Python来查找和提取这些特征,因为它易于编写且省时。我的问题是,我得到了太多的特征,而我不知道如何仅获取最佳特征。我发现在OpenCV的C++ API中有一个名为retainBest的方法,但我无法在Python中找到它。你能否给出建议该怎么做?
这是我使用的代码:
这是我使用的代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('./positive_images/1.jpg',cv2.CV_LOAD_IMAGE_GRAYSCALE)
#img = cv2.resize(cv2.imread('./positive_images/3.png',cv2.CV_LOAD_IMAGE_GRAYSCALE), (100, 100))
#th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
ret,th3 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)
cv2.imwrite("result1.jpg", th3)
img = th3
# Initiate FAST object with default values
fast = cv2.FastFeatureDetector()
# find and draw the keypoints
keypoints = fast.detect(img,None)
img2 = cv2.drawKeypoints(img, keypoints, color=(255,0,0))
cv2.imwrite('fast_true.png',img2)
# Disable nonmaxSuppression
fast.setBool('nonmaxSuppression',0)
keypoints = fast.detect(img,None)
print "Total Keypoints without nonmaxSuppression: ", len(keypoints)
img3 = cv2.drawKeypoints(img, keypoints, color=(255,0,0))
cv2.imwrite("result.jpg",img3)
原始图片:
处理后的图片:
我的目标是检测方向盘。