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 (ie 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.
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
Looks like you have a PIL image. Try converting to a numpy image: npImage = np.array(img)
链接地址: http://www.djcxy.com/p/89734.html