C# 如何比较两个图像并识别图像中的图案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/304384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 22:26:20  来源:igfitidea点击:

How do I compare two images & recognize the pattern in an image?

c#image-processingcomputer-visionpattern-recognitionfeature-extraction

提问by

How do I compare two images & recognize the pattern in an image irrespective of its size and pattern size, and using .Net C#? Also, which algorithms are used for doing so from Image Processing?

如何比较两个图像并识别图像中的图案,而不管其大小和图案大小,并使用 .Net C#?另外,图像处理中使用了哪些算法?

回答by Eugene Yokota

See Scale-invariant feature transform, template matching, and Hough transform. A quick and inaccurate guess may be to make a histogram of color and compare it. If the image is complicated enough, you might be able to distinguish between several sets of images.

请参阅比例不变特征变换模板匹配霍夫变换。快速且不准确的猜测可能是制作颜色直方图并进行比较。如果图像足够复杂,您也许能够区分多组图像。

To make the matter simple, assume we have three buckets for R, G, and B. A completely white image would have (100%, 100%, 100%) for (R, G, B). A completely red image would have (100%, 0%, 0%). A complicated image might have something like (23%, 53%, 34%). If you take the distance between the points in that (R, G, B) space, you can compare which one is "closer".

为简单起见,假设我们有 R、G 和 B 的三个桶。完全白色的图像将有 (100%, 100%, 100%) 的 (R, G, B)。完全红色的图像将具有 (100%, 0%, 0%)。复杂的图像可能具有类似 (23%, 53%, 34%) 的内容。如果你取那个 (R, G, B) 空间中点之间的距离,你可以比较哪个“更近”。

回答by BCS

look up pattern recognition. I known very little about it other than the name.

查找模式识别。除了名字,我对它知之甚少。

Warning:If that is what you want, it is one of the hardest "real world" programming problems known.

警告:如果这就是您想要的,它是已知的最难的“现实世界”编程问题之一。

回答by Adam Rosenfield

Scale-invariant feature transform (SIFT)might be what you're looking for. It's not simple to understand or implement, however.

尺度不变特征变换 (SIFT)可能是您正在寻找的。然而,理解或实施并不简单。

回答by reshefm

I am no expert in image recognition by I once stummbeled upon the AForgelibrary which is written in C# and does image recognition. Maybe it can help...

我不是图像识别方面的专家,因为我曾经偶然发现了用 C# 编写并进行图像识别的AForge库。也许它可以帮助...

回答by reshefm

Techniques for image matching and image recognition can be very different. For the first task, you may make use of SIFT or hand craft your own distance function, based on RGB or otherwise. For recognition, there a vast amount of machine learning techniques that you can use, more popular techniques involves Adaboost, SVM and other hybrid neural networks method. There are no lack of related research papers in this field. Google is your friend.

图像匹配和图像识别的技术可能非常不同。对于第一个任务,您可以使用 SIFT 或基于 RGB 或其他方式手工制作您自己的距离函数。对于识别,你可以使用大量的机器学习技术,更流行的技术包括 Adaboost、SVM 和其他混合神经网络方法。该领域不乏相关研究论文。谷歌是你的朋友。

回答by simon

Jinmala, you've asked a question here that is extremely broad. There are literally thousands of papers in the literature about these topics. There is no correct answer, and there are many unsolved issues in the comparison of images, so you really probably can't hope for a simple solution that just works (unless your situation is quite simple and constrained)

Jinmala,你在这里问了一个非常广泛的问题。关于这些主题的文献中有数以千计的论文。没有正确的答案,而且在图像对比中还有很多未解决的问题,所以你可能真的不能指望一个简单的解决方案就行了(除非你的情况非常简单和受限)

If you narrow things down, I might be able to help.

如果您缩小范围,我可能会提供帮助。

回答by Mandah Mr.

You might be looking for this

你可能正在寻找这个

System.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\1.jpg"); System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\2.jpg"); // create template matching algorithm's instance // (set similarity threshold to 92.5%)

System.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\1.jpg"); System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\2.jpg"); // 创建模板匹配算法的实例 // (设置相似度阈值为 92.5%)

       ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.921f);
            // find all matchings with specified above similarity

            TemplateMatch[] matchings = tm.ProcessImage(sourceImage, template);
            // highlight found matchings

       BitmapData data = sourceImage.LockBits(
            new Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
            ImageLockMode.ReadWrite, sourceImage.PixelFormat);
        foreach (TemplateMatch m in matchings)
        {

                Drawing.Rectangle(data, m.Rectangle, Color.White);

            MessageBox.Show(m.Rectangle.Location.ToString());
            // do something else with matching
        }
        sourceImage.UnlockBits(data);

I warn you it is quite slow takes around 6 seconds to process image of 1024x768 finding in it pciture with the size of 50x50.enter code here

我警告你,处理 1024x768 的图像需要大约 6 秒的时间才能找到它的大小为 50x50 的图像。enter code here

回答by Marc MAURICE

ImageMagick has an interesting article on this: http://www.imagemagick.org/Usage/compare/#sub-image

ImageMagick 对此有一篇有趣的文章:http: //www.imagemagick.org/Usage/compare/#sub-image

回答by IntellectualChestnut

template matching, you can do this with EmguCV ,OpendotnetCV,Aforge.net

模板匹配,你可以用 EmguCV ,OpendotnetCV,Aforge.net 来做到这一点