4

I'm using Python 2.7 and opencv version 2.4.2. I'm having trouble with a segmentation fault. Here is the code I try:

import cv2
img = cv2.imread(img_path)
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
detector = cv2.FeatureDetector_create("SURF") # or "SIFT"
kp  = detector.detect(img2)

the last line causes a segmentation fault and I don't understand why. I realize there is at least another post on the subject, namely : Does anyone have any examples of using OpenCV with python for descriptor extraction? but it doesn't seem to solve my problem.

Any help will be much appreciated! Thanks!

4

2 回答 2

1

我使用的是 Ubuntu 12.04,其中包括 OpenCV 2.3.1。我想要一个更新版本的 OpenCV,所以我找到了一个带有 OpenCV 2.4.5 backport 的 PPA。当我尝试使用 I cv2.FeatureDetector_create("SURF")andcv2.FeatureDetector_create("SIFT")时,我遇到了和你一样的分段错误。我意识到这两种方法都是非免费的,并观察到我的 OpenCV 安装缺少libopencv-nonfree2.4包。我切换到另一个包含它的 PPA,这似乎已经解决了这个问题。

于 2014-01-08T21:01:00.827 回答
0

我很确定cv2.FeatureDetector_create()真的只在 C++ 接口中。你想做这样的事情:

import numpy as np
import cv2

img = cv2.imread(img_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
surf = cv2.SURF()
mask = np.uint8(np.ones(gray.shape))
surf_points = surf.detect(gray, mask)
于 2013-07-16T12:19:07.643 回答