-1

I want to use SIFT. I've already tried this code:

  import cv2
  import numpy as np
  img = cv2.imread('1.jpg')
  gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  sift = cv2.xfeatures2d.SIFT_create()
  kp = sift.detect(gray,None)
  img=cv2.drawKeypoints(gray,kp,img)
  cv2.imwrite('sift_keypoints.jpg',img)

But I get this error:

./sifttt.py: line 3: syntax error near unexpected token `('

./sifttt.py: line 3: `img = cv2.imread('1.jpg')'

I don't know if I need to install something or if I need to do something else?

Dev
  • 125
  • 2
  • 15

1 Answers1

1

There is a problem in your code at line number 5. You are using opencv 2.4 version but opencv 2.4 does not have xfeature2d module this module is found in openv 3 in up check this out. So to use Sift in opencv 2.4 use this and this tutorials.

Yirga
  • 881
  • 1
  • 12
  • 31