比较图像以发现差异

Compare images to find differences(比较图像以发现差异)
本文介绍了比较图像以发现差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务:我在装配线的末端安装了一个摄像头,它捕获生产项目的图像.比方说,我们制作门票(上面有一些文字和图片).所以每生成的票被拍照并作为图像保存到磁盘.现在我想检查这些保存的图像是否有异常(即比较将它们转换为图像(模板),这没关系).所以如果有问题在我们的装配线上有一张票(缺少图片,污点,......),我的应用程序应该找到它(因为它的图像与我的相差太大模板).

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%),将两个图像放在一个函数中并得到返回值为 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库,因为它为这类工作提供了很多非常有用的功能.

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. 我之前使用过的另一种技术是模型查找".或Pattern Matching",但我只知道一个商业库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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)