janonespe
janonespe

Reputation: 140

cv2.FeatureDetector_create('SIFT') causes segmentation fault

I am using opencv 2.4.11 and python 2.7 for a computer vision project. I am trying to obtain the SIFT descriptors:

ima = cv2.imread('image.jpg')
gray = cv2.cvtColor(ima,cv2.COLOR_BGR2GRAY)

detector = cv2.FeatureDetector_create('SIFT') # or 'SURF' for that matter
descriptor = cv2.DescriptorExtractor_create('SIFT')

kpts = detector.detect(gray)

When calling the last instruction it throws an ugly segmentation fault. I have to use a 2.4.x version, so uploading to the 3.x version of opencv to use SIFT or SURF methods is not an option. I have downgraded from 3.1 previously using sudo make uninstall and installed from 0 the actual opencv version.

Does anyone have an idea why this happens?

Upvotes: 2

Views: 6456

Answers (3)

Palanikrishnan
Palanikrishnan

Reputation: 1

Install opencv_contrib using

pip install opencv-contrib-python

Then your code will work.

Upvotes: -1

xavysp
xavysp

Reputation: 73

currently I am beginner in Computer Science so apologize for my short explanation. I have OpenCV 3 and Python 2.7.11 Before all I downloaded no no it's better that you read this site after all you can write this code (It's almost the same of your code ).

import cv2
import numpy as np

img = cv2.imread('lenna.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

sift = cv2.xfeatures2d.SIFT_create()
detector = sift.detect(gray, None)

kpts, des = sift.compute(gray, detector)
# kpts,des=descriptor.compute(gray,kpts)
im_with_keypoints = cv2.drawKeypoints(gray, kpts, np.array([]), color=255, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey()

Regards!

Upvotes: 0

Dragos Stanciu
Dragos Stanciu

Reputation: 320

Try:

import cv2

ima = cv2.imread('image.jpg')
gray = cv2.cvtColor(ima, cv2.COLOR_BGR2GRAY)

detector = cv2.SIFT()

kp1, des1 = detector.detectAndCompute(gray, None)

detector = cv2.FeatureDetector_create('SIFT') should also work for creating the SIFT object.

Upvotes: 2

Related Questions