1

I tried this example from the OpenCV website:

import numpy as np
import cv2
from matplotlib import pyplot as plt

# changed the image names from box* since the sample images were not given on the site
img1 = cv2.imread('burger.jpg',0)          # queryImage
img2 = cv2.imread('burger.jpg',0) # trainImage

# Initiate SIFT detector
sift = cv2.SIFT()

# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)

# FLANN parameters
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50)   # or pass empty dictionary

flann = cv2.FlannBasedMatcher(index_params,search_params)

matches = flann.knnMatch(des1,des2,k=2)

# Need to draw only good matches, so create a mask
matchesMask = [[0,0] for i in xrange(len(matches))]

# ratio test as per Lowe's paper
for i,(m,n) in enumerate(matches):
    if m.distance < 0.7*n.distance:
        matchesMask[i]=[1,0]

draw_params = dict(matchColor = (0,255,0),
                   singlePointColor = (255,0,0),
                   matchesMask = matchesMask,
                   flags = 0)

img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,**draw_params)

plt.imshow(img3,),plt.show()

Executing the example, viz. python test.py, gives the following error:

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    sift = cv2.SIFT()
AttributeError: 'module' object has no attribute 'SIFT'

I had installed OpenCV from source, building manually. All modules were built by make, if I recall correctly.

This question suggested that I install opencv-contrib from its GitHub repository. I did, and I still get this error.

My system is Ubuntu 15.04 64-bit.

Simon Kuang
  • 3,870
  • 4
  • 27
  • 53

1 Answers1

0

I'm not entirely sure if this is applicable, but at some point they stopped supporting SIFT in the later versions of opencv I believe due to the fact that it is patented or something related (source?), however an alternate is to use ORB which will have a similar effect.

You could try something like this:

from cv2 import ORB as SIFT

However in the event that you get an import error this also might work for you:

SIFT = cv2.ORB_create

If you insert those near the top of your file, then likely you can leave "SIFT" as it is throughout the file (well more or less, you get the idea, basically replace the cv2.Sift() with sift = SIFT() and you should be in better shape.)

onaclov2000
  • 5,741
  • 9
  • 40
  • 54