6

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.

1
  • For what it is worth I submitted this ticket to Willow Garage, but I would love to find a solution ASAP. code.ros.org/trac/opencv/ticket/1582 Commented Feb 3, 2012 at 16:45

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

4 Comments

Still getting the error. Can you do me a favor and tell me the type of the gray image? it looks like a numpy array. Do the cvMat and IPL Image types not work?
Okay from SimpleCV this looks like it will work: gray = uint8(np.array(cv.GetMat(img._getGrayscaleBitmap())).transpose()) It will take me a day or so to do a proof of concept.
Yeah, it is a uint8 numpy array. The cv2 python bindings need some work, most of the features don't seem to be implemented yet.
I also came across this problem, although it could be the bindings may have been busted: tech.groups.yahoo.com/group/OpenCV/message/85320 I was about to reference your python book using VLFeat (although the python wrappers are outdated). :)
0

Looks like you have a PIL image. Try converting to a numpy image: npImage = np.array(img)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.