OpenCV' SIFT'属性错误

时间:2014-03-22 09:17:03

标签: python opencv sift

我写了这个函数来比较视频帧的关键点。

def match_images(img1, img2):
    """Given two images, returns the matches"""
       detector = cv2.SIFT(100)
       matcher = cv2.BFMatcher(cv2.NORM_L2)

       kp1, desc1 = detector.detectAndCompute(img1, None)
       kp2, desc2 = detector.detectAndCompute(img2, None)

       raw_matches = matcher.knnMatch(desc1, trainDescriptors = desc2, k = 2) 
       kp_pairs = filter_matches(kp1, kp2, raw_matches)
       return kp_pairs

我收到了这个错误

Traceback (most recent call last):
  File "test.py", line 173, in <module>
    kp_pairs = match_images(img1, img2)
  File "test.py", line 18, in match_images
    detector = cv2.SIFT(100)
   AttributeError: 'module' object has no attribute 'SIFT'

1 个答案:

答案 0 :(得分:0)

因此,现在您已经使用opencv_contrib软件包安装了OpenCV 3,您应该可以从OpenCV 2.4.X访问原始的SIFT和SURF实现,只有这一次它们才可以通过cv2进入xfeatures2d子模块中。 SIFT_create和cv2.SURF_create函数。

python3
>>> import cv2
>>> image = cv2.imread("test_image.jpg")
>>> gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
>>> sift = cv2.xfeatures2d.SIFT_create()
>>> ...