我正在尝试提取特征,以便稍后训练将在 Android 应用程序中使用的 SVM。我正在使用 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)
原图:
结果图像:
我的目标是检测方向盘。