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
  • Have you tried displaying the img or check that it is read properly? Commented Jul 16, 2013 at 11:31
  • I have, yes, everything is fine up until I try to detect the features. Good point though, sometimes it's that easy :) Commented Jul 16, 2013 at 13:51
  • What happens if you try cv2.Feature2D_create('SURF')? It appears to have the same functionality for me. Commented Jul 16, 2013 at 15:00
  • Unfortunately, Feature2D_create() doesn't seem to be available in this version of opencv (AttributeError...). The more I read the more I figure a lot must have changed inbetween recent versions! Commented Jul 16, 2013 at 15:31

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

SIFT and SURF are patented, nonfree algos. some package managers are really picky about this
0

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)

5 Comments

Thanks for the answer. It turns out that this version of opencv does not have the SURF attribute coded (cv2.SURF() yields : "AttributeError: 'module' object has no attribute 'SURF'"). I wonder if there could be an incompatibility problem between python and opencv versions (resp. 2.7 and 2.4.2) maybe?
I'm running Python 2.7.2 and OpenCV 2.4.5. Does import cv2 followed by cv2.SURF() error in IDLE?
Oh, the docs also have cv2.SURF.detect(image[, mask]) --> key_points, but it might be available to you.
It is not available indeed. However, you might have a point: maybe I should update to 2.4.5, it looks like this could solve my problems (not that I'm eager to do that, I recall quite a hassle when installing :))
If you're on a Windows box, you can get the Unofficial Binaries. The Official Site also has the binaries and the packages for other systems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.