Beispiel #1
0
        private void UpdateImage()
        {
            const int iterations = 1;

            if (MainImage == null)
            {
                return;
            }

            Image <Gray, Byte> testImage;

            using (Image <Gray, Byte> dilate1 = MainImage.Dilate(iterations))
                using (Image <Gray, Byte> erode1 = dilate1.Erode(iterations))
                    using (Image <Gray, Byte> dilate2 = erode1.Dilate(iterations))
                        using (Image <Gray, Byte> erode2 = dilate2.Erode(iterations))
                            using (Image <Gray, Byte> dilate3 = erode2.Dilate(iterations))
                                using (Image <Gray, Byte> erode3 = dilate3.Erode(iterations))
                                {
                                    testImage    = erode3.Clone();
                                    DisplayImage = ImageService.ToBitmapSource(testImage);
                                    //DisplayImage2 = ImageService.ToBitmapSource(MainImage);
                                }

            LineSegment2D[] lines = CvInvoke.HoughLinesP(testImage,
                                                         DistanceResolution,        //Distance resolution in pixel-related units
                                                         Math.PI / AngleResolution, //Angle resolution measured in radians.
                                                         Threshold,                 //threshold
                                                         MinLineWidth,              //min Line width
                                                         GapBetweenLines);          //gap between lines

            FindSpine(lines, RotatedRect.Empty, testImage);
            using (Image <Bgr, Byte> moddedImage = testImage.Convert <Bgr, Byte>())
            {
                SaveImage = new Image <Gray, byte>(moddedImage.Width, moddedImage.Height, new Gray(0));
                foreach (var line in lines)
                {
                    moddedImage.Draw(line, new Bgr(Color.Aqua), 2);
                    SaveImage.Draw(line, new Gray(255), 1);
                }

                DisplayImage2 = ImageService.ToBitmapSource(moddedImage);
            }
        }