OpenCV:比较简单图像,差异不大 [英] OpenCV: comparing simple images with small difference

查看:130
本文介绍了OpenCV:比较简单图像,差异不大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆简单"的图像,如果它们相似,我想比较一下.我使用模板匹配(cv::matchTemplate)将它们相互比较,结果相当不错.

I have a bunch of "simple" images and I want to compare if they are similar together. I compare them to each other using template matching (cv::matchTemplate) and results are quite good.

现在,我想微调程序,但遇到了问题.例如,我有两个看起来非常相似的图像.他们唯一的区别是另一条线较粗,并且数字的前数字不同.当两个图像都较小时,在进行模板匹配时,线宽的一个像素差异会导致较大的结果差异.当线宽相同且唯一的区别是前数字时,匹配成功时,我会得到模板匹配结果,例如0.98CV_TM_CCORR_NORMED.当线宽不同时,匹配结果约为0.95.

Now I want to fine tune my program and I face a problem. For example I have two images which look very much alike. Only differences they have is that another one has thicker line and the digit front of item is different. When both images are small, one pixell difference in line thickness makes big result differences when doing template matching. When line thicknesses are same and only difference is the front digit, I get template matching result something like 0.98 with CV_TM_CCORR_NORMED when match successful. When line thickness is different matching result is something like 0.95.

我无法将阈值降低到0.98以下,因为其他一些相似的图像具有相同的线宽.

I cannot decrease my threshold value below 0.98 because some other similar images have same line thickness.

以下是示例图片:

那我有什么选择?

我尝试过:

  • 扩大原件和模板
  • 同时腐蚀两者
  • morphology同时兼有
  • 计算关键点并进行比较
  • 寻找角落

但是还没有大的成功.这些图像太简单了,以至于很难检测好的特征"吗?

But no big success yet. Are those images too simple that detecting "good features" is hard?

任何帮助都是很好的帮助.

Any help is very wellcome.

谢谢!

这是其他一些示例图像.我的程序认为相似的内容放在相同的zip文件夹中. 邮政编码

Here are some other example images. What my program consider as similar are put in same zip-folder. ZIP

推荐答案

一种可行的方法可能是细化两个图像,以使每行具有一个像素宽度,因为不同的粗细会导致您出现相似性的主要问题.

A possible way might be thinning the two images, so that every line is of one pixel width, since the differing thickness is causing you the main problem with similarity.

过程将是首先对图像进行二值化/阈值处理,然后对两个图像进行细化操作,因此两个图像现在都具有相同的1 px厚度.然后使用以前使用的常规模板匹配,效果会很好.

The procedure would be to first binarize/threshold the images, then apply a thinning operation on both images, so both are now having the same thickness of 1 px. Then use the usual template matching that you used before with good results.

如果您想了解有关二进制映像的细化/骨架化的更多详细信息,请在各种讨论论坛和OpenCV小组​​中发布一些OpenCV实现:

In case you'd like more details on the thinning/skeletonization of binary images here are a few OpenCV implementations posted on various discussion forums and OpenCV groups:

  1. 使用OpenCV的JR Parker实现
  2. 可能更高效的代码细化的简要概述,以防万一您有兴趣.
  1. OpenCV code for thinning (Guo and Hall algo, works with CvMat inputs)
  2. The JR Parker implementation using OpenCV
  3. Possibly more efficient code here (uses OpenCV optimized access methods a lot, however most of the page is in Japanese!)
  4. And lastly a brief overview of thinning in case you're interested.

这篇关于OpenCV:比较简单图像,差异不大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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