Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature Detection in OpenCV Python Bindings

I've combed the web looking for a way to get the OpenCV 2.3.1a feature extraction/descriptor bindings to spit out any flavor of image features/descriptors(STAR/SURF/ORB/SIFT/FAST). I am well aware that OpenCV has a method called "goodFeaturesToTrack. This doesn't help me as there are no feature descriptors (which is what I really need). I have followed the documentation as listed here:

http://opencv.itseez.com/modules/features2d/doc/feature_detection_and_description.html

Nothing seems to work. I've tried all of the flavors of descriptors/features. I've tried using single and multiple channel images (i.e. color and black and white) and multiple image formats (8bit and 32f). I have worked with the current distribution and building the bindings from the source repo. Most of the methods result in a "unknown is not a numpy array" error. Here is an example:

SimpleCV:1>import cv2
SimpleCV:2>img = Image("aerospace.jpg")
SimpleCV:3>bwimg = img._getGrayscaleBitmap()
SimpleCV:4>bwimg
SimpleCV:4><iplimage(nChannels=1 width=600 height=400 widthStep=600 )>
SimpleCV:5>surfer = cv2.SURF(0.5,4,2,False,False)
SimpleCV:6>points = surfer.detect(bwimg,None)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Library/Python/2.6/site-packages/SimpleCV-1.2-py2.6.egg/SimpleCV/Shell/Shell.pyc in <module>()
-

TypeError: <unknown> is not a numpy array
SimpleCV:7>

It is worth noting that I am using SimpleCV to load the image, but the method _getGrayscaleBitmap() returns the gray 8bit IPL image used by OpenCV. I am sure this works as I use it with hundred of other OpenCV methods without incidence.

So can anyone point me to a WORKING example of this code on the web. I have combed through dozens of examples and found nothing that works.

like image 580
kscottz Avatar asked Feb 03 '12 15:02

kscottz


People also ask

Which algorithm is used for feature detection?

3.1 Feature detection evaluation The selected algorithms are SIFT, SURF, FAST, BRISK, and ORB. Selected detectors are applied to three images for locating keypoints. Each image contains a single objects.

Is OpenCV good for object detection?

It is also playing an important role in real-time operation. With the help of the OpenCV library, we can easily process the images as well as videos to identify the objects, faces or even handwriting of a human present in the file. We will only focus to object detection from images using OpenCV in this tutorial.


1 Answers

Kat, this works for me:

s = cv2.SURF()
mask = uint8(ones(gray.shape))
keypoints = s.detect(gray,mask)

I can plot the key points and all. To get the descriptors you can try this

k,d = s.detect(gray,mask,False)
d = d.reshape((-1,128))
print d.shape, len(k)

d should have the same length at the list of key points.

I have this example in the OpenCV chapter here: http://www.maths.lth.se/matematiklth/personal/solem/book.html

like image 143
Jan Erik Solem Avatar answered Sep 21 '22 02:09

Jan Erik Solem