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

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

问题描述

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

比较轮廓的最佳方法是什么?我尝试了几种方法,包括没有轮廓的matchTemplate,但是如果你看一下下面的两个部分,你会发现这两个非常接近,所以matchShapes和matchTemplate无法像我使用的那样区分它们他们.我也不确定如何使用 cvMatchShapes.它仅适用于将图像直接加载到匹配形状中,但结果尚无定论.我认为轮廓是要走的路,我只是不确定如何实施比较阶段.任何帮助都会很棒.

您可以在此处查看模板:.

如果您想了解如何计算倒角距离的更详细版本,请查看 这里.

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.

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.

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

解决方案

You can calculate the chamfer distance between the two contours:

T and E are the set of edges of the template and the image and x is the point of reference where you start to compare the two set of edges. So for each x you get a different value.

DT is the distance transform of an image. Matlab provides the algorithm here.

If you want a more detailed version of how to calculate the chamfer distance, take a look here.

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

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