gpt4 book ai didi

python - OpenCV 不附带 "external"库

转载 作者:行者123 更新时间:2023-12-02 16:39:04 24 4
gpt4 key购买 nike

我试过this example来自 OpenCV 网站:

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 ,给出以下错误:
Traceback (most recent call last):
File "test.py", line 10, in <module>
sift = cv2.SIFT()
AttributeError: 'module' object has no attribute 'SIFT'

我已经从源代码安装了 OpenCV,手动构建。所有模块均由 make 构建,如果我没记错的话。

This question建议我安装 opencv-contrib来自其 GitHub 存储库。我做到了,我仍然得到这个错误。

我的系统是 Ubuntu 15.04 64 位。

最佳答案

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

你可以尝试这样的事情:

from cv2 import ORB as SIFT

但是,如果您收到导入错误,这也可能对您有用:
SIFT = cv2.ORB_create

如果您在文件顶部附近插入那些,那么您可能可以在整个文件中保留“SIFT”(或多或少,您明白了,基本上将 cv2.Sift() 替换为 sift = SIFT()你应该 body 更好。)

关于python - OpenCV 不附带 "external"库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31257576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com