有没有人有任何使用OpenCV和python进行描述符提取的例子? [英] Does anyone have any examples of using OpenCV with python for descriptor extraction?

查看:251
本文介绍了有没有人有任何使用OpenCV和python进行描述符提取的例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV从图像中提取SURF描述符。我正在使用OpenCV 2.4和Python 2.7,但我很难找到任何提供有关如何使用这些功能的信息的文档。我已经能够使用以下代码来提取功能,但我找不到任何合理的方法来提取描述符:

I'm trying to use OpenCV to extract SURF descriptors from an image. I'm using OpenCV 2.4 and Python 2.7, but am struggling to find any documentation that provides any information about how to use the functions. I've been able to use the following code to extract features, but I can't find any sensible way to extract descriptors:

import cv2

img = cv2.imread("im1.jpg")
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

surf = cv2.FeatureDetector_create('SURF')
detector = cv2.GridAdaptedFeatureDetector(surf, 50) # max number of features
fs = detector.detect(img2)

我尝试提取描述符的代码是:

The code I tried for extracting descriptors is:

import cv2
img = cv2.imread("im3.jpg")
sd = cv2.FeatureDetector_create("SURF")
surf = cv2.DescriptorExtractor_create("SURF")
keypoints = []
fs = surf.compute(img, keypoints) # returns empty result
sd.detect(img) # segmentation faults

有没有人有任何代码可以做这种事情,或指向任何提供样本的文档的指针?

Does anyone have any sample code that does this kind of thing, or pointers to any documentation that provides samples?

推荐答案

下面是我为使用Python 2.7和OpenCV 2.4提取SURF功能而编写的一些代码的示例。

Here's an example of some code I've written for extracting SURF features using Python 2.7 and OpenCV 2.4.

im2 = cv2.imread(imgPath)
im = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY)
surfDetector = cv2.FeatureDetector_create("SURF")
surfDescriptorExtractor = cv2.DescriptorExtractor_create("SURF")
keypoints = surfDetector.detect(im)
(keypoints, descriptors) = surfDescriptorExtractor.compute(im,keypoints)

这适用于并返回一组描述符。
不幸的是,因为cv2.SURF()在2.4中不起作用,所以你必须经历这个繁琐的过程。

This works and returns a set of descriptors. Unfortunately since cv2.SURF() doesn't work in 2.4, you have to go through this tedious process.

这篇关于有没有人有任何使用OpenCV和python进行描述符提取的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆