示例#1
0
        public static bool ValidateRGBDIfferencePercent(Color c1, Color c2, double RequiredToPass)
        {
            int frst = ImageWorks.RGBToGreyScale(c1);
            int scnd = ImageWorks.RGBToGreyScale(c2);

            return(DifferencePercent(frst, scnd) <= RequiredToPass);
        }
示例#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);
        }
        private void button3_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);

            var f = FragmentFinder.FastFinder(img1, img2, ValidatePercent);

            ImageWorks.DrawRectangles(img1, f);
            ImageWorks.NameRectangles(img1, f, fragmentNameTextBox.Text);

            resultImageBox.Image = ((Bitmap)img1.Clone());
            resultImageBox.Refresh();
        }
        public static Bitmap ToGrayScale(this Bitmap bm)
        {
            Bitmap     res = ImageWorks.PaintOn32bpp((Bitmap)bm.Clone());
            FastBitmap fbm = new FastBitmap(res);

            fbm.Lock();

            for (int i = 0; i < fbm.Width; i++)
            {
                for (int j = 0; j < fbm.Height; j++)
                {
                    Color c       = fbm.GetPixel(i, j);
                    int   greyVal = RGBToGreyScale(c);
                    fbm.SetPixel(i, j, Color.FromArgb(greyVal, greyVal, greyVal));
                }
            }

            fbm.Unlock();
            return(res);
        }
        private void button2_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);

            List <KeyValuePair <Point, Point> > Lpoint;

            FragmentFinder.FindImage(img1, img2, ValidatePercent, out Lpoint);

            ImageWorks.DrawRectangles(img1, Lpoint);
            ImageWorks.NameRectangles(img1, Lpoint, fragmentNameTextBox.Text);

            resultImageBox.Image = ((Bitmap)img1.Clone());
            resultImageBox.Refresh();
        }
示例#6
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();
        }