本文介绍了OpenCV BFMatcher match()始终返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在训练带有4个描述符的BFMatcher:

I'm training a BFMatcher with 4 descriptors:

bf = cv2.BFMatcher()

bf.clear()
bf.add(des1)
bf.add(des2)
bf.add(des3)
bf.add(des4)
bf.train()

bf.match(des1)

代码bf.match(des1)引发此错误:

error: ..\..\..\..\opencv\modules\core\src\stat.cpp:2473: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function cv::batchDistance

这可能是什么原因?描述符是ORB描述符.

What could be the cause of this ? The descriptors are ORB descriptors.

推荐答案

是的,您可以在列表中添加描述符,但只能与单个描述符匹配,因此,遍历整个des1数组并与每个单个描述符匹配,将匹配项保存在一个列表中,或者如果您不希望重复这些匹配项,则将其保存在一个集合中!

You are right, you can add descriptors in lists but you can only match with single descriptors, so, go over the whole des1 array and match every single descriptor and save the matches in a list, or a set if you don't want them to be repeated!

matches = set()
for desc in desc1:
    matches_img = bf.knnMatch(desc,k=2)
    for match in matches_img:
        matches.add(match)

这篇关于OpenCV BFMatcher match()始终返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:14