如何比较二进制模式图像的两个轮廓? [英] How to compare two contours of a binary pattern image?

查看:267
本文介绍了如何比较二进制模式图像的两个轮廓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C中创建零件扫描器,将扫描零件的所有可能性作为目录中的图像。我的代码当前从该目录获取所有图像,并将其转储到一个向量。然后我为所有的图像产生轮廓组。然后程序进入while循环,在那里它不断地从网络摄像头抓取图像,并为这些也生成轮廓。我已经设置了一个夹具让零件搁置,因此方向和大小不是一个问题,但我不想校准机器,所以模板图像和拍摄的零件图像之间可能有移动。

I'm creating a part scanner in C that pulls all possibilities for scanned parts as images in a directory. My code currently fetches all images from that directory and dumps them into a vector. I then produce groups of contours for all the images. The program then falls into a while loop where it constantly grabs images from a webcam, and generates contours for those as well. I have set up a jig for the part to rest on, so orientation and size are not a concern, however I don't want to have to calibrate the machine, so there may be movement between the template images and the part images taken.

比较轮廓的最佳方法是什么?我已经尝试了几种方法,包括matchTemplate没有轮廓,但如果你看看下面的两个部分,你可以看到,这两个是非常接近对方,所以matchShapes和matchTemplate不能区分他们的方式,我使用他们。我也不知道如何使用cvMatchShapes。它只是将图像直接加载到匹配形状,但结果是不确定的。我认为轮廓是要走的路,我只是不知道如何去实施比较阶段。任何帮助将是巨大的。

What is the best way to compare the contours? I have tried several methods including matchTemplate without contours, but if you take a look at the two parts below, you can see that these two are very close to each other, so matchShapes and matchTemplate can't distinguish between them the way I was using them. I'm also not sure how to use cvMatchShapes. It works with just loading the images directly into match shapes, but the results are inconclusive. I think that contours is the way to go, I'm just not sure of how to go about implementing the comparison phase. Any help would be great.

您可以在这里查看模板: http://www.cryogendesign.com/partDetection.html

You can view the templates here: http://www.cryogendesign.com/partDetection.html"

推荐答案

对于自己动手,一种方法可以是计算距离图像(将每个像素的最小欧几里德距离分配给作为参考的轮廓)。参见 http://en.wikipedia.org/wiki/Distance_transform

If you are ready for do-it-yourself, one approach could be to compute a "distance image" (assign every pixel the smallest Euclidean distance to the contour taken as the reference). See http://en.wikipedia.org/wiki/Distance_transform.

使用此距离图片可以快速计算新轮廓与参考轮廓的平均距离(对于每个轮廓像素,获得与距离图像的距离)。平均距离给您指示拟合优度,并让您找到最佳匹配一组参考模板。

Using this distance image, you can quickly compute the average distance of a new contour to the reference one (for every contour pixel, get the distance from the distance image). The average distance gives you an indication of the goodness-of-fit and will let you find the best match to a set of reference templates.

如果零件有一些移动自由度,情况有点困难:在计算平均距离之前,必须适合新轮廓到参考一个。您将需要应用适当的变换(平移,旋转,可能缩放),并找到将最小化平均距离的参数。

If the parts have some moving freedom, the situation is a bit harder: before computing the average distance, you must fit the new contour to the reference one. You will need to apply a suitable transform (translation, rotation, possibly scaling), and find the parameters that will minimize... the average distance.

这篇关于如何比较二进制模式图像的两个轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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