我正在尝试提取功能,以便稍后我可以训练将在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)
原始图片:
结果图片:
我的目标是检测方向盘。
答案 0 :(得分:4)
如果查看the documentation,您会发现可以为FAST检测器设置阈值:
FastFeatureDetector( int threshold=1, bool nonmaxSuppression=true, type=FastFeatureDetector::TYPE_9_16 );
此处,默认threshold
设置为1.在您的代码中,尝试将其设置为40,并查看结果,如下所示:
fast = cv2.FastFeatureDetector(40)
您可以找到有关阈值here含义的详细信息: