private void button1_Click(object sender, EventArgs e)
        {
            if (resultImageBox.Image != null)
            {
                resultImageBox.Image.Dispose();
            }

            Bitmap img1 = (Bitmap)sourceImageBox1.Image.Clone();
            Bitmap img2 = (Bitmap)sourceImageBox2.Image.Clone();

            double ValidatePercent = 1 - (double)(percentageAccuracyNumericUpDown.Value / 100);

            Bitmap result            = Differencer.GetDifferenceColoredBitmap(img1, img2, ValidatePercent);
            long   DifferenceCounter = Differencer.CountPixelDifferences(img1, img2, ValidatePercent);

            label1.Text          = "Difference: " + ((double)DifferenceCounter / (result.Width * result.Height) * 100).ToString("0.00") + "%";
            resultImageBox.Image = ((Bitmap)result.Clone());
            resultImageBox.Refresh();
        }
Beispiel #2
0
        public static long CountPixelDifferences(Bitmap frst, Bitmap scnd, double RequiredToPass)
        {
            if (frst.Width != scnd.Width || frst.Height != scnd.Height)
            {
                throw new Exception("Not matching size!");
            }

            Bitmap result = ImageWorks.PaintOn32bpp((Bitmap)frst.Clone());
            Bitmap img1   = ImageWorks.PaintOn32bpp((Bitmap)frst.Clone());
            Bitmap img2   = ImageWorks.PaintOn32bpp((Bitmap)scnd.Clone());

            FastBitmap res = new FastBitmap(result);
            FastBitmap bm1 = new FastBitmap(img1);
            FastBitmap bm2 = new FastBitmap(img2);

            double ValidatePercent   = RequiredToPass;
            long   DifferenceCounter = 0;

            res.Lock();
            bm1.Lock();
            bm2.Lock();

            for (int i = 0; i < result.Width; i++)
            {
                for (int j = 0; j < result.Height; j++)
                {
                    Color c1 = bm1.GetPixel(i, j);
                    Color c2 = bm2.GetPixel(i, j);

                    if (!Differencer.ValidateRGBDIfferencePercent(c1, c2, ValidatePercent))
                    {
                        DifferenceCounter++;
                    }
                }
            }

            res.Unlock();
            bm1.Unlock();
            bm2.Unlock();
            CollectGarbage();

            return(DifferenceCounter);
        }
Beispiel #3
0
        public static void FindImage(Bitmap Base, Bitmap LookFor, double requiredToPass, out List <KeyValuePair <Point, Point> > Lpoint)
        {
            Bitmap b = ImageWorks.PaintOn32bpp((Bitmap)Base.Clone());
            Bitmap l = ImageWorks.PaintOn32bpp((Bitmap)LookFor.Clone());

            FastBitmap bs = new FastBitmap(b);
            FastBitmap lf = new FastBitmap(l);

            Lpoint = new List <KeyValuePair <Point, Point> >();

            bs.Lock();
            lf.Lock();

            for (int i = 0; i < Base.Width; i++)
            {
                for (int j = 0; j < Base.Height; j++)
                {
                    int g = i;
                    int t = j;

                    int r = 0;
                    int e = 0;

                    bool preBreaked   = false;
                    long comparedGood = 0;

                    while (Differencer.WiseRGBDifferencePercent(bs.GetPixel(g, t), lf.GetPixel(r, e), requiredToPass))
                    {
                        if (g + 1 == Base.Width || t + 1 == Base.Height || t - j + 1 == lf.Height)
                        {
                            preBreaked = true;
                            break;
                        }
                        comparedGood++;

                        g++;
                        r++;

                        if (g - i == lf.Width)
                        {
                            g = i;
                            t++;
                        }

                        if (r == lf.Width)
                        {
                            r = 0;
                            e++;
                        }
                    }

                    if (!preBreaked)
                    {
                        if ((double)comparedGood >= lf.Width * lf.Height / 100)
                        {
                            Lpoint.Add(new KeyValuePair <Point, Point>(new Point(i, j), new Point(i + lf.Width, j + lf.Height)));
                        }
                    }
                }
            }

            bs.Unlock();
            lf.Unlock();
        }