Ejemplo n.º 1
0
 public static Bitmap Blur(Bitmap bmp)
 {
     // create filter
     Blur filter = new Blur();
     // apply the filter
     filter.ApplyInPlace(bmp);
     return bmp;
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Bitmap image = viewCam.GetCurrentVideoFrame();
            ImageStatistics statistics = new ImageStatistics(ObjectExtractorDialog.Value);

            // create filter
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            // set center colol and radius
            filter.CenterColor = new RGB((byte)statistics.Red.Median, (byte)statistics.Green.Median, (byte)statistics.Blue.Median);
            filter.Radius = 20;
            // apply the filter
            filter.ApplyInPlace(image);

            image = Grayscale.CommonAlgorithms.BT709.Apply(image);

            Blur blur = new Blur();
            blur.ApplyInPlace(image);

            OtsuThreshold otsu = new OtsuThreshold();
            otsu.ApplyInPlace(image);
            
            //DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector();
            //edgeDetector.ApplyInPlace(image);
            //ColorFiltering colorFilter = new ColorFiltering(
            //    new IntRange(2, 255),
            //    new IntRange(0, 60), 
            //    new IntRange(0, 60));
            //colorFilter.ApplyInPlace(image);

            //// create filter
            //Threshold threshold = new Threshold(100);
            //// apply the filter
            //threshold.ApplyInPlace(image);


            using (image)
            {
                BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    image.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());

                //imgtest.Source = bitmapSource;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        public GameLogic ScrapeBoardFromImage(Bitmap img)
        {
            // filter board's color to better identify tiles
            Blur blur = new Blur();
            blur.Threshold = 1;
            blur.ApplyInPlace(img);
            BrightnessCorrection brightness_filter = new BrightnessCorrection(-30);
            brightness_filter.ApplyInPlace(img);
            HSLFiltering luminance_filter = new HSLFiltering();
            luminance_filter.Luminance = new Range(0.50f, 1);
            luminance_filter.ApplyInPlace(img);
            img.Save("c:\\users\\breiche\\pictures\\filtered.bmp", ImageFormat.Bmp);

            DetectBlobsInImage(img);
            img.Save("c:\\users\\breiche\\pictures\\blobs.bmp", ImageFormat.Bmp);

            return new GameLogic(0, 0);
        }
Ejemplo n.º 4
0
        public void Detect(CameraImage cameraImage)
        {
            var partial = cameraConverter.ToImage(cameraImage);
            var sourceBitmap = converter.ToBitmap(partial);

            var blur = new Blur();
            blur.ApplyInPlace(sourceBitmap);

            var points = harris.ProcessImage(sourceBitmap);
            var featurePoints = points.Select(t => new CornerFeaturePoint(t)).Cast<IFeaturePoint>().ToList();
            if (featurePoints.Count > 0 && oldPoints.Count > 0)
            {
                try
                {
                    var matches = matcher.Match(featurePoints, oldPoints);

                    using (var g = Graphics.FromImage(sourceBitmap))
                    {
                        for (var i = 0; i < matches[0].Length; i++)
                        {
                            g.DrawRectangle(Pens.Blue, matches[0][i].X, matches[0][i].Y, 3, 3);
                            g.DrawRectangle(Pens.Red, matches[1][i].X, matches[1][i].Y, 3, 3);
                            g.DrawLine(Pens.Red, matches[0][i].X + 1, matches[0][i].Y + 1, matches[1][i].X + 1,
                                matches[1][i].Y + 1);
                        }
                    }

                    var resultImage = imageFactory.Create(sourceBitmap);
                    Image = cameraConverter.Convert(resultImage);

                    oldPoints.Clear();
                    oldPoints.AddRange(featurePoints.AsReadOnly());
                }
                finally
                {
                    sourceBitmap.Dispose();
                }
            }
            else
            {
                oldPoints.Clear();
                oldPoints.AddRange(featurePoints.AsReadOnly());
            }
        }