比较图像以找到差异 [英] Compare images to find differences

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

问题描述

任务:我们在装配线的末端安装了一个相机,
捕获了所生产物品的图像。让我们例如说,我们
产生票(有一些文本和图片上)。所以每个
生成的票被拍摄并保存到磁盘作为图像。现在我
想检查这些保存的图像异常(即比较
他们到一个图像(模板),这是OK)。所以如果在我们的生产线上有一个问题
(缺少图片,污点,...),我的
应用程序应该找到它(因为它的图像与我的
模板)。

Task: I have a camera mounted on the end of our assembly line, which captures images of produced items. Let's for example say, that we produce tickets (with some text and pictures on them). So every produced ticket is photographed and saved to disk as image. Now I would like to check these saved images for anomalies (i.e. compare them to an image (a template), which is OK). So if there is a problem with a ticket on our assembly line (missing picture, a stain,...), my application should find it (because its image differs too much from my template).

问题:比较图片和找到
之间的差别最简单的方法是什么?我需要编写自己的方法,或者我可以
使用现有的方法吗?这将是巨大的,如果我只是设置一个公差值
(即图像可以不同为1%),将两个图像放在一个函数,并获得
a返回值true或false:)

Question: What is the easiest way to compare pictures and find differences between them? Do I need to write my own methods, or can I use existing ones? It would be great if I just set a tolerance value (i.e. images can differ for 1%), put both images in a function and get a return value of true or false :)

工具:C#或VB.NET,Emgu.CV(用于OpenCV的.NET包装器)或类似的东西

Tools: C# or VB.NET, Emgu.CV (.NET wrapper for OpenCV) or something similar

推荐答案

我建议您查看 AForge Imaging library ,因为它有很多

I'd recommend looking at AForge Imaging library as it has a lot of really useful functions in it for this type of work.

有几种方法可以使用:


  1. 简单减法(模板图像 - 当前),并查看有多少像素不同。您可能想要为结果设置阈值,即仅包含10个或更多(例如)不同的像素。

  2. 如果票据可以在视野中移动那么项目1)不会工作,除非您可以首先找到票证。例如,如果票在黑色背景上是白色的,您可以在图片上设置一个阈值,这将为您提供票的位置。

  3. 我使用的另一种技术它之前是模型查找或模式匹配,但我只知道一个商业图书馆 Matrox Imaging Library (或MIL)包含这些函数,因为它们不重要。

  1. Simple subtraction (template image - current) and see how many pixels are different. You'd probably want to threshold the results, i.e. only include pixels that are different by 10 or more (for instance).
  2. If the tickets can move about in the field-of-view then item 1) isn't going to work unless you can locate the ticket first. If for instance the ticket is white on a black background you could do a threshold on the image and that would give you a good idea of where the ticket was.
  3. Another technique I've used it before is "Model Finding" or "Pattern Matching", but I only know of a commercial library Matrox Imaging Library (or MIL) that contains these functions as they aren't trivial.

以确保您知道票的哪些部分更重要。例如,我猜想丢失的标志或水印是一个大问题。但是一些区域可以有可变文本,例如序列号,因此您希望它们不同。基本上,你可能需要区别对待某些区域的图像。

Also you need to make sure you know which parts of the ticket are more important. For instance I guess that a missing logo or watermark is a big problem. But some areas could have variable text, such as a serial number and so you'd expect them to be different. Basically you might need to treat some areas of the image differently from others.

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

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