Пример #1
0
        private void OnDetect(object sender, RoutedEventArgs e)
        {
            DebugView.Children.Clear();
            BitmapSource src = ImageContent.Source as BitmapSource;

            if (src != null)
            {
                float min           = float.Parse(Min.Text);
                float max           = float.Parse(Max.Text);
                int   minEdgeLength = int.Parse(EdgeLength.Text);

                DetectButton.IsEnabled = false;
                CannyEdgeDetector canny = new CannyEdgeDetector(src, max, min, minEdgeLength);
                canny.EdgeDetected += OnEdgeDetected;

                Task.Run(new Action(() =>
                {
                    canny.DetectEdges();
                    canny.EdgeDetected -= OnEdgeDetected;
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        DetectButton.IsEnabled = true;
                    }));
                }));

                //ShowImage(canny.ToImage<int>(canny.FilteredImage), "Filtered");
                //ShowImage(canny.ToImage<float>(canny.DerivativeX), "DerivativeX");
                //ShowImage(canny.ToImage<float>(canny.NonMax), "NonMax");
                //ShowImage(canny.ToImage<float>(canny.Gradient), "Gradient");
                //ShowImage(canny.ToImage<int>(canny.HorizontalEdges), "HorizontalEdges");
                //ShowImage(canny.ToImage<int>(canny.VerticalEdges), "VerticalEdges");
                //ShowImage(canny.ToImage<int>(canny.EdgeMap), "EdgeMap");
            }
        }
Пример #2
0
        private void AutoCrop(AttachmentDialogImageItem img)
        {
            CannyEdgeDetector edgeDetector = new CannyEdgeDetector(img.Bitmap, 20, 80, 30);

            edgeDetector.DetectEdges();
            Rect bounds = edgeDetector.EdgeBounds;

            AddResizer(img, bounds);
            SetDirty();
        }