cenna75
cenna75

Reputation: 539

Python opencv feature detector causes segmentation fault

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!

Upvotes: 4

Views: 4252

Answers (2)

David G.
David G.

Reputation: 371

I'm using Ubuntu 12.04, which includes OpenCV 2.3.1. I wanted a newer version of OpenCV, so I found a PPA with an OpenCV 2.4.5 backport. When I tried to use I cv2.FeatureDetector_create("SURF") and cv2.FeatureDetector_create("SIFT"), I encountered the segmentation fault just as you did. I realized that both of these methods are nonfree, and observed that my OpenCV install was missing the libopencv-nonfree2.4 package. I switched to another PPA that includes it and this seems to have solved the problem.

Upvotes: 1

Eric Workman
Eric Workman

Reputation: 1445

I'm pretty sure cv2.FeatureDetector_create() is really only in the C++ interface. You want to do something like this:

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)

Upvotes: 0

Related Questions