OpenCV不附带“外部"功能.图书馆 [英] OpenCV doesn't come with "external" libraries

查看:107
本文介绍了OpenCV不附带“外部"功能.图书馆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了此示例在OpenCV网站上:

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()

执行示例,即. python test.py,出现以下错误:

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'

我从源代码安装了OpenCV,是手动构建的.如果我没记错的话,所有模块都是由make构建的.

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

这个问题建议我从其GitHub存储库中安装opencv-contrib .我做到了,但仍然出现此错误.

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

我的系统是Ubuntu 15.04 64位.

My system is Ubuntu 15.04 64-bit.

推荐答案

我不确定这是否适用,但是在某些时候,他们停止在更高版本的opencv中支持SIFT,我相信这是因为已获得专利或与之相关的某些东西(来源?),但是另一种方法是使用ORB,它会产生类似的效果.

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

如果在文件顶部附近插入那些,则可能您可以在整个文件中保留"SIFT"(或多或少,您会明白的,基本上是替换cv2 .sift()的sift = SIFT(),您的状态应该会更好.)

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.)

这篇关于OpenCV不附带“外部"功能.图书馆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆