とにかく、このことをより速くするために?今のところ、sourceImage のサイズは 1024x768、テンプレートは 50x50 で 6 秒くらいです。これは AForge を使用しています。他のより速くて簡単な方法を知っている人は、提出してください。私がやろうとしているタスクは、スクリーンショット内の小さな画像を見つけることです。そして、できれば速い私の限界は1秒です。私が探している画像は赤い四角形の単純な画像で、スクリーンショットはより複雑です。
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);