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

c# – How do I compare two images & recognize the pattern in an image? – Stack Overflow

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%)

       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 1024×768 finding in it pciture with the size of 50×50.enter code here

c# WebBrowser开发参考资料 – love_may555的专栏 – 博客频道 – CSDN.NET

其次,如果我们想执行一段Web页面中原本没有的脚本,该怎么做呢?这次.Net的类没有提供,看来还要依靠COM了。IHTMLWindow2可以将任意的字符

串作为脚本代码来执行。

string scriptline01 = @"function ShowPageInfo() {“;

string scriptline02 = @"      var numLinks = document.links.length; “;

string scriptline03 = @"      var numForms = document.forms.length; “;

string scriptline04 = @"      var numImages = document.images.length; “;

string scriptline05 = @"      var numScripts = document.scripts.length; “;

string scriptline06 = @"      alert(‘网页的统计结果:/r/n链接数:’ + numLinks + “;

string scriptline07 = @"         ‘/r/n表单数:’ + numForms + “;

string scriptline08 = @"         ‘/r/n图像数:’ + numImages + “;

string scriptline09 = @"         ‘/r/n脚本数:’ + numScripts);}";

string scriptline10 = @"ShowPageInfo();";

string strScript = scriptline01 + scriptline02 + scriptline03 + scriptline04 + scriptline05 +

                    scriptline06 + scriptline07 + scriptline08 + scriptline09 + scriptline10;

IHTMLWindow2 win = (IHTMLWindow2)webBrowser.Document.Window.DomWindow;

win.execScript(strScript, “Javascript");http://www.xmlasp.net/n1670c13.aspx

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 7 + 14 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)