OpenCV Python 绑定中的特征检测

发布于 2025-01-01 17:18:10 字数 1379 浏览 1 评论 0原文

我梳理了网络,寻找一种方法来获取 OpenCV 2.3.1a 特征提取/描述符绑定,以吐出任何风格的图像特征/描述符(STAR/SURF/ORB/SIFT/FAST)。我很清楚 OpenCV 有一个名为“goodFeaturesToTrack”的方法。这对我没有帮助,因为没有特征描述符(这是我真正需要的)。我已遵循此处列出的文档:

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

我已经尝试了所有类型的描述符/功能。尝试使用单通道和多通道图像(即彩色和黑白)和多种图像格式(8位和32f)我已经使用了当前的发行版并从源存储库构建了绑定。导致出现“unknown is not a numpy array”错误。这是一个示例:

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>

值得注意的是,我使用 SimpleCV 加载图像,但方法 _getGrayscaleBitmap() 返回 OpenCV 使用的灰色 8 位 IPL 图像。确保这有效,因为我将它与数百种其他 OpenCV 方法一起使用而没有发生任何情况。

那么任何人都可以向我指出该代码在网络上的有效示例吗?我梳理了几十个例子,但没有发现任何有效的例子。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗼ふ静 2025-01-08 17:18:10

凯特,这对我有用:

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

我可以绘制关键点和所有内容。要获取描述符,您可以尝试这个

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

d 在关键点列表中应该具有相同的长度。

我在 OpenCV 章节中有这个例子:
http://www.maths.lth.se/matematiklth/personal/solem/book.html< /a>

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

那些过往 2025-01-08 17:18:10

看起来你有一个 PIL 图像。尝试转换为 numpy 图像:
npImage = np.array(img)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文