public static class imageCompare { public static string[] Compare(Bitmap bitmap) { string[] mis = Directory.GetFiles("C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\Bura\\kartebi\\Kartebi", "*.png"); string[] add = new string[mis.Length]; Bitmap[] bpp = new Bitmap[36]; Bitmap[] bitfor = new Bitmap[36]; // for (int i = 0; i < bitfor.Length; i++) { bpp[i] = (Bitmap)System.Drawing.Image.FromFile(mis[i]); bitfor[i] = Form1.ConvertToFormat(bpp[i], System.Drawing.Imaging.PixelFormat.Format24bppRgb); } for (int i = 0; i < bitfor.Length; i++) { if (Matching.bp2(bitmap, bitfor[i])) add[i] = mis[i]; else add[i] = null; } return add; } } public static class Matching { public static bool bp2(this Bitmap template, Bitmap bmp) { const int divisor = 4; const int epsilon = 10; ExhaustiveTemplateMatching etm = new ExhaustiveTemplateMatching(0.9f); TemplateMatch[] tm = etm.ProcessImage(new ResizeNearestNeighbor(template.Width / divisor, template.Height / divisor).Apply(template), new ResizeNearestNeighbor(bmp.Width / divisor, bmp.Height / divisor).Apply(bmp)); if (tm.Length == 1) { Rectangle tempRect = tm[0].Rectangle; if (Math.Abs(bmp.Width / divisor - tempRect.Width) < epsilon && Math.Abs(bmp.Height / divisor - tempRect.Height) < epsilon) { return true; } } return false; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)