OpenCV does not come with "external" libraries

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 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 an example, namely: 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 installed OpenCV from the source code, manually creating it. All modules were built by make , if I remember correctly.

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

My system is Ubuntu 15.04 64-bit.

+1
source share
1 answer

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

You can try something like this:

 from cv2 import ORB as SIFT 

However, if you get an import error, this may also work for you:

 SIFT = cv2.ORB_create 

If you paste the ones next to your file, you can probably leave "SIFT" as it is throughout the file (more or less, you get the idea, basically replace cv2.Sift () with sift = SIFT () and you should be in better shape.)

0
source

All Articles