本文介绍了如何知道 matchTemplate 是否找到了对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了这个答案并编写了自己的程序,但我有一个特定的问题.

I used this answer and wrote my own program, but I have a specific problem.

如果图像没有对象,matchTemplate 不会抛出错误,我不知道有什么方法可以检查 matchTemplate 是否找到对象, 谁能给我建议,或者给我一个检查这个的函数名.

If the image does not have the object, matchTemplate does not throw an error, and I do not know of any method to check if matchTemplate found the object or not, can anyone give me advice, or give me a function name which checks this.

推荐答案

matchTemplate() 返回一个矩阵,其值表示您的对象以该像素为中心的概率.如果您知道对象(并且只有一个对象)在那里,您所要做的就是寻找最大值的位置.

matchTemplate() returns a matrix whose values indicate the probability that your object is centered in that pixel. If you know the object (and only one object) is there, all you have to do is look for the location of the maximum value.

如果你不知道,你必须找到最大值,如果它高于某个阈值,你的对象应该在那里.

If you don't know, you have to find the max value, and if it is above a certain threshold, your object should be there.

现在,该阈值的选择很棘手 - 由您来为您的应用找到合适的阈值.当然,你会有一些误报(当没有对象,但最大值大于阈值时)和一些漏报(你的对象没有创建足够大的峰值)

Now, selection of that threshold is tricky - it's up to you to find the good threshold specifically for your app. And of course you'll have some false positives (when there is no object, but the max is bigger than threshold), and some false negatives (your object does not create a big enough peak)

选择阈值的方法是收集一个相当大的图像数据库,里面有和没有你的物体,并统计物体在里面时的峰值有多大,没有时有多大,并选择最能区分两类的阈值

The way to choose the threshold is to collect a fairly large database of images with and without your object inside, and make a statistic of how big is the peak when object is inside, and how big is when it isn't, and choose the threshold that best separates the two classes

这篇关于如何知道 matchTemplate 是否找到了对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:33