栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

BFMatcher匹配OpenCV中的抛出错误

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

BFMatcher匹配OpenCV中的抛出错误

要在两个图像的描述符之间进行搜索,请 使用:

img1 = cv2.imread('box.png',0)img2 = cv2.imread('box_in_scene.png',0)kp1,des1 = surf.detectAndCompute(img1,None)kp2,des2 = surf.detectAndCompute(img2,None)bf = cv2.BFMatcher(cv2.NORM_L1,crossCheck=False)matches = bf.match(des1,des2)

在多张图像中搜索

add
方法用于添加多个测试图像的描述符。一旦所有描述符都建立索引,就可以运行
train
方法来构建基础的数据结构(示例:KdTree,在FlannbasedMatcher的情况下将用于搜索)。然后,您可以运行
match
以查找哪个测试图像与哪个查询图像更匹配。您可以检查K-d_tree并查看如何将其用于搜索多维矢量(Surf提供64维矢量)。

注意:- 顾名思义,BruteForceMatcher没有内部搜索优化数据结构,因此具有空训练方法。

用于多图像搜索的代码示例

import cv2import numpy as npsurf = cv2.xfeatures2d.SURF_create(400)# Read Imagestrain = cv2.imread('box.png',0)test = cv2.imread('box_in_scene.png',0)# Find Descriptors    kp1,trainDes1 = surf.detectAndCompute(train, None)kp2,testDes2  = surf.detectAndCompute(test, None)# Create BFMatcher and add cluster of training images. One for now.bf = cv2.BFMatcher(cv2.NORM_L1,crossCheck=False) # crossCheck not supported by BFMatcherclusters = np.array([trainDes1])bf.add(clusters)# Train: Does nothing for BruteForceMatcher though.bf.train()matches = bf.match(testDes2)matches = sorted(matches, key = lambda x:x.distance)# Since, we have index of only one training image, # all matches will have imgIdx set to 0.for i in range(len(matches)):    print matches[i].imgIdx

有关bf.match的DMatch输出,请参阅docs。

在此处查看完整示例:Opencv3.0
docs

其他资讯

操作系统:Mac。
的Python:2.7.10。
Opencv:3.0.0-dev [如果没记错,请使用brew安装。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/647178.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号