I'm trying to extract features so I can later train a SVM which will be used in Android app. I'm using python to find and extract the features because it is easy to write and saves time. My problem is that I get too many features and I don't know how to get the best features only. I found that there is a method retainBest in the C++ API of OpenCV but I couldn't find it for python. Can you give an advise what to do?
This is the code I use:
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)
The original image:
And the result image:
My goal is to detect a steering wheel.
If you look at the documentation, you will see that you can set a threshold for your FAST detector:
FastFeatureDetector( int threshold=1, bool nonmaxSuppression=true, type=FastFeatureDetector::TYPE_9_16 );
Here, the default threshold
is set to 1. In your code, try to set it to 40, and see the results, as follows:
fast = cv2.FastFeatureDetector(40)
You will find details about the meaning of the threshold here: