Example #1
0
        public static double GetSimilarity(string image, Bitmap targetImage, string filepath)
        {
            // Load images into bitmaps
            var imageOne     = new Bitmap(image);
            var imageTwo     = targetImage;
            var overlayImage = ChangePixelFormat(new Bitmap(imageOne));
            var template     = ChangePixelFormat(new Bitmap(imageOne));
            var templFile    = ChangePixelFormat(new Bitmap(imageTwo));

            var df = new ThresholdedDifference(90)
            {
                OverlayImage = overlayImage
            };

            var savedTemplate = SaveBitmapToFile(df.Apply(template), filepath, image, BitMapExtension);
            var savedTempFile = SaveBitmapToFile(
                df.Apply(templFile),
                filepath,
                Path.Combine(filepath, "temp.bmp"),
                BitMapExtension);

            // Setup the AForge library
            var tm = new ExhaustiveTemplateMatching(0);

            // Process the images
            var results = tm.ProcessImage(savedTemplate, savedTempFile);

            // Compare the results, 0 indicates no match so return false
            return(results.Length <= 0 ? 0 : results[0].Similarity);
        }
Example #2
0
        public MovementHandler(IInterceptor interceptor = null)
        {
//TODO: configurate it.
            const int difference       = 60;
            const int reportDifference = 5000;

            _differenceFilter = new ThresholdedDifference(difference);
            _reportDifference = reportDifference;
            _threshold        = difference;
            _interceptor      = interceptor ?? new NullInterceptor();
        }
Example #3
0
        /// Image Process

        public Bitmap diff(Bitmap frame, Bitmap background)
        {
            // create filter


            ThresholdedDifference filter = new ThresholdedDifference(60);

            // apply the filter
            filter.OverlayImage = background;
            return(filter.Apply(frame));
        }
        public mDifferenceThreshold(Bitmap UnderlayBitmap, Bitmap OverlayBitmap, int ThresholdValue)
        {
            Threshold = ThresholdValue;

            BitmapUnder = new mSetFormat(UnderlayBitmap, mFilter.BitmapTypes.Rgb24bpp).ModifiedBitmap;
            BitmapOver  = new mSetFormat(OverlayBitmap, mFilter.BitmapTypes.Rgb24bpp).ModifiedBitmap;

            ModifiedBitmap = UnderlayBitmap;

            Effect = new ThresholdedDifference(Threshold);

            Effect.OverlayImage = BitmapOver;

            ModifiedBitmap = Effect.Apply(BitmapUnder);
        }
Example #5
0
        public DiffContainer GetDiffsAforge(Bitmap newFrame)
        {
            if (prevousFrame == null)
            {
                prevousFrame = UnmanagedImage.FromManagedImage(new Bitmap(@"d:\1.png"));
            }

            List <Bitmap>         bitmaps = new List <Bitmap>();
            ThresholdedDifference filter  = new ThresholdedDifference(20);

            filter.OverlayImage = newFrame;

            var res = filter.Apply(prevousFrame);

            bc.ProcessImage(res);

            Rectangle[] rects = bc.GetObjectsRectangles();



            foreach (Rectangle rect in rects)
            {
                if (rect.Width > 4 || rect.Height > 4)
                {
                    Crop crop = new Crop(rect);

                    bitmaps.Add(crop.Apply(prevousFrame).ToManagedImage());
                }
                //    Drawing.Rectangle(prevousFrame, rect, Color.Red);
            }


            //Parallel.ForEach(rects, rect =>
            //{
            //    if (rect.Width > 2 && rect.Height > 2)
            //    {
            //        Crop crop = new Crop(rect);

            //        bitmaps.Add(crop.Apply(prevousFrame));
            //    }
            //    //  Drawing.Rectangle(prevousFrame, rect, Color.Red);
            //}
            //);

            return(new DiffContainer());// { temp = prevousFrame.ToManagedImage() };
        }
Example #6
0
        public static Bitmap CreateImageDiff(Bitmap a, Bitmap b, IReadOnlyList <BlindRegion> globalBlindRegions)
        {
            var unified = UnifiImagesDimensions(a, b);
            var filter  = new ThresholdedDifference(0)
            {
                OverlayImage = unified.Item1
            };
            var imageDiff = filter.Apply(unified.Item2);

            DilatationFilter.ApplyInPlace(imageDiff);
            var fixedBitmap = CloneBitmapFormat(imageDiff);

            MarkBlindRegions(fixedBitmap, globalBlindRegions);
            var result = CloneBitmapFormat(unified.Item2);

            DrawBounds(fixedBitmap, result);
            return(result);
        }
Example #7
0
        public async Task Image_Acquisition()
        {
            while (detection == 1)
            {
                OK = 0;

                // Previous Frame
                prev = newFrame;

                //Delay of 0.1 second
                await Task.Delay(300);

                //Current Frame
                curr = newFrame;

                //Find the difference between the prev and curr
                ThresholdedDifference threshold = new ThresholdedDifference(28)
                {
                    OverlayImage = prev
                };

                //Resulted Binary Image
                curr = threshold.Apply(curr);

                //If there is a noticeable change, start detection
                nonblack = threshold.WhitePixelsCount;
                if (nonblack >= (curr.Width * curr.Height / 8))
                {
                    OK = 1;
                }
                if (OK == 1)
                {
                    Detection();
                }

                //Delay of 0.1 seconds
                await Task.Delay(300);
            }
        }