简体   繁体   English

OpenCV Python绑定中的特征检测

[英]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). 我已经梳理了网络,寻找一种方法来获取OpenCV 2.3.1a特征提取/描述符绑定,以吐出任何风格的图像特征/描述符(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: 我很清楚OpenCV有一个名为“goodFeaturesToTrack的方法。这对我没有帮助,因为没有功能描述符(这是我真正需要的)。我已按照此处列出的文档:

http://opencv.itseez.com/modules/features2d/doc/feature_detection_and_description.html 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). 我尝试使用单通道和多通道图像(即彩色和黑白)和多种图像格式(8位和32位)。 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. 大多数方法导致“unknown not a numpy array”错误。 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. 值得注意的是,我使用SimpleCV加载图像,但方法_getGrayscaleBitmap()返回OpenCV使用的灰色8位IPL图像。 I am sure this works as I use it with hundred of other OpenCV methods without incidence. 我确信这是有效的,因为我使用它与其他数百种OpenCV方法无关。

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. d在关键点列表中应具有相同的长度。

I have this example in the OpenCV chapter here: http://www.maths.lth.se/matematiklth/personal/solem/book.html 我在这里的OpenCV章节中有这个例子: http//www.maths.lth.se/matematiklth/personal/solem/book.html

Looks like you have a PIL image. 看起来你有一个PIL图像。 Try converting to a numpy image: npImage = np.array(img) 尝试转换为numpy图像:npImage = np.array(img)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM