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.
您可以使用几种方法:
- 简单的减法(模板图像 - 当前),看看有多少像素不同.您可能希望对结果进行阈值处理,即仅包括相差 10 或更多的像素(例如).
- 如果票证可以在视野中移动,那么第 1) 项将不起作用,除非您先找到票证.例如,如果门票是黑色背景上的白色,您可以在图像上设置一个阈值,这样您就可以很好地了解门票的位置.
- 我之前使用过的另一种技术是模型查找".或Pattern Matching",但我只知道一个商业库Matrox Imaging Library(或 MIL)包含这些功能,因为它们不是微不足道的.
- 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).
- 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.
- 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.
这篇关于比较图像以发现差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:比较图像以发现差异
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01