4

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:

enter image description here

And the result image:

enter image description here

My goal is to detect a steering wheel.

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
dephinera
  • 3,703
  • 11
  • 41
  • 75
  • keypoints have a 'response' member. you could simply try to filter out the weakest ones. – berak Dec 27 '14 at 13:05
  • Thank you for your help. I'll look at that (I hope I'll have better results). – dephinera Dec 27 '14 at 13:30
  • still remember, that the whole keypoint/feature detection thing will find *exactly this specific model*. (you probably can't detect *arbitrary* wheels this way. – berak Dec 27 '14 at 13:37
  • well that's why I'm going to train an SVM and also I wont use only this picture. – dephinera Dec 27 '14 at 19:44
  • Steering wheels don't have features that jump out as much as their overall outline does. –  Mar 23 '15 at 19:41

1 Answers1

4

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:

  1. Select a pixel p in the image which is to be identified as an interest point or not. Let its intensity be I_p
  2. ...
  3. ...
  4. Now the pixel p is a corner if there exists a set of n contiguous pixels in the circle (of 16 pixels) which are all brighter than I_p + t, or all darker than I_p − t. (Shown as white dash lines in the above image). n was chosen to be 12.
JonasVautherin
  • 7,297
  • 6
  • 49
  • 95