Exemple #1
0
 public override void Show(object value)
 {
     centroidData = (CentroidData)value;
     if (centroidData != null)
     {
         if (imageViewer.SelectedImageViewer == nameof(centroidData.BackgroundSubtractedImage) && centroidData.BackgroundSubtractedImage != null)
         {
             imageViewer.Update(centroidData.BackgroundSubtractedImage);
         }
         else if (imageViewer.SelectedImageViewer == nameof(centroidData.ThresholdImage) && centroidData.ThresholdImage != null)
         {
             imageViewer.Update(centroidData.ThresholdImage);
         }
         else if (imageViewer.SelectedImageViewer == nameof(centroidData.LargestContour) && centroidData.ThresholdImage != null)
         {
             IplImage contourImage = new IplImage(centroidData.ThresholdImage.Size, centroidData.ThresholdImage.Depth, 3);
             contourImage.SetZero();
             if (centroidData.LargestContour != null)
             {
                 CV.DrawContours(contourImage, centroidData.LargestContour.Contour, Scalar.All(255), Scalar.All(0), 0, -1);
                 CV.DrawContours(contourImage, centroidData.LargestContour.Contour, new Scalar(0, 0, 255), Scalar.All(0), 0, 1 * VisualizerCanvas.Height / 640);
             }
             imageViewer.Update(contourImage);
         }
         else
         {
             if (imageViewer.SelectedImageIndex != 0)
             {
                 imageViewer.SelectImageIndex(0);
             }
             imageViewer.Update(centroidData.Image);
         }
     }
 }
        public override void Show(object value)
        {
            var contours = (Contours)value;
            var image    = visualizer.VisualizerImage;

            if (image != null && contours.FirstContour != null)
            {
                CV.DrawContours(image, contours.FirstContour, Scalar.All(255), Scalar.All(128), 2);
            }
        }
Exemple #3
0
 public IObservable<IplImage> Process(IObservable<Contour> source)
 {
     return source.Select(input =>
     {
         var rect = input.Rect;
         var output = new IplImage(new Size(rect.Width, rect.Height), IplDepth.U8, 1);
         output.SetZero();
         CV.DrawContours(output, input, Scalar.All(255), Scalar.All(0), MaxLevel, Thickness, LineFlags.Connected8, new Point(-rect.X, -rect.Y));
         return output;
     });
 }
        public override void Show(object value)
        {
            var image = visualizer.VisualizerImage;
            var contourConvexity = (ContourConvexity)value;
            var contour = contourConvexity.Contour;

            if (image != null && contour != null)
            {
                CV.DrawContours(image, contourConvexity.ConvexHull, Scalar.Rgb(0, 255, 0), Scalar.All(0), 0);
                DrawingHelper.DrawConvexityDefects(image, contourConvexity.ConvexityDefects, Scalar.Rgb(204, 0, 204));
            }
        }
Exemple #5
0
        public override void Show(object value)
        {
            var contours = (Contours)value;
            var output   = new IplImage(contours.ImageSize, IplDepth.U8, 1);

            output.SetZero();

            if (contours.FirstContour != null)
            {
                CV.DrawContours(output, contours.FirstContour, Scalar.All(255), Scalar.All(128), 2, thickness);
            }

            base.Show(output);
        }
        public override IObservable <IplImage> Process(IObservable <ConnectedComponentCollection> source)
        {
            return(source.Select(input =>
            {
                var output = new IplImage(input.ImageSize, IplDepth.U8, 1);
                output.SetZero();

                foreach (var component in input)
                {
                    CV.DrawContours(output, component.Contour, Scalar.All(255), Scalar.All(0), 0, -1);
                }

                return output;
            }));
        }
Exemple #7
0
        public override IObservable<IplImage> Process(IObservable<Contours> source)
        {
            return source.Select(input =>
            {
                var output = new IplImage(input.ImageSize, IplDepth.U8, 1);
                output.SetZero();

                if (input.FirstContour != null)
                {
                    CV.DrawContours(output, input.FirstContour, Scalar.All(255), Scalar.All(0), MaxLevel, Thickness);
                }

                return output;
            });
        }
Exemple #8
0
        protected override Action <IplImage> GetRenderer()
        {
            var contour       = Contour;
            var externalColor = ExternalColor;
            var holeColor     = HoleColor;
            var maxLevel      = MaxLevel;
            var thickness     = Thickness;
            var lineType      = LineType;

            return(image =>
            {
                if (contour != null)
                {
                    CV.DrawContours(image, contour, externalColor, holeColor, maxLevel, thickness, lineType);
                }
            });
        }
Exemple #9
0
        public override void Show(object value)
        {
            var contourConvexity = (ContourConvexity)value;
            var contour          = contourConvexity.Contour;
            var boundingBox      = contour != null ? contour.Rect : new Rect(0, 0, 1, 1);
            var output           = new IplImage(new Size(boundingBox.Width, boundingBox.Height), IplDepth.U8, 3);

            output.SetZero();

            if (contour != null)
            {
                var offset = new Point2f(-boundingBox.X, -boundingBox.Y);
                CV.DrawContours(output, contour, Scalar.Rgb(0, 255, 0), Scalar.All(0), 0, -1, LineFlags.Connected8, new Point(offset));
                CV.DrawContours(output, contourConvexity.ConvexHull, Scalar.Rgb(0, 255, 0), Scalar.All(0), 0, 1, LineFlags.Connected8, new Point(offset));
                DrawingHelper.DrawConvexityDefects(output, contourConvexity.ConvexityDefects, Scalar.Rgb(204, 0, 204), 1, new Point(offset));
            }
            base.Show(output);
        }
Exemple #10
0
        public static void DrawConnectedComponent(IplImage image, ConnectedComponent component, Point2f offset)
        {
            if (component.Area <= 0)
            {
                return;
            }
            var centroid             = component.Centroid + offset;
            var orientation          = component.Orientation;
            var minorAxisOrientation = orientation + Math.PI / 2.0;
            var halfMajorAxis        = component.MajorAxisLength * 0.5;
            var halfMinorAxis        = component.MinorAxisLength * 0.5;
            var major1 = new Point((int)(centroid.X + halfMajorAxis * Math.Cos(orientation)), (int)(centroid.Y + halfMajorAxis * Math.Sin(orientation)));
            var major2 = new Point((int)(centroid.X - halfMajorAxis * Math.Cos(orientation)), (int)(centroid.Y - halfMajorAxis * Math.Sin(orientation)));
            var minor1 = new Point((int)(centroid.X + halfMinorAxis * Math.Cos(minorAxisOrientation)), (int)(centroid.Y + halfMinorAxis * Math.Sin(minorAxisOrientation)));
            var minor2 = new Point((int)(centroid.X - halfMinorAxis * Math.Cos(minorAxisOrientation)), (int)(centroid.Y - halfMinorAxis * Math.Sin(minorAxisOrientation)));

            if (component.Patch != null)
            {
                var target = image;
                var patch  = component.Patch;
                var mask   = patch.Channels == 1 ? patch : null;
                try
                {
                    if (component.Contour != null)
                    {
                        var rect = component.Contour.Rect;
                        mask = new IplImage(patch.Size, patch.Depth, 1);
                        mask.SetZero();
                        CV.DrawContours(mask, component.Contour, Scalar.All(255), Scalar.All(0), 0, -1, LineFlags.Connected8, new Point(-rect.X, -rect.Y));
                        if (image.Width != rect.Width || image.Height != rect.Height)
                        {
                            target = image.GetSubRect(component.Contour.Rect);
                        }
                    }

                    if (patch.Channels != target.Channels)
                    {
                        var conversion = patch.Channels > image.Channels
                            ? ColorConversion.Bgr2Gray
                            : ColorConversion.Gray2Bgr;
                        patch = new IplImage(patch.Size, patch.Depth, image.Channels);
                        CV.CvtColor(component.Patch, patch, conversion);
                    }

                    CV.Copy(patch, target, mask);
                }
                finally
                {
                    if (patch != component.Patch)
                    {
                        patch.Dispose();
                    }
                    if (mask != component.Patch)
                    {
                        mask.Dispose();
                    }
                    if (target != image)
                    {
                        target.Dispose();
                    }
                }
            }
            else if (component.Contour != null)
            {
                CV.DrawContours(image, component.Contour, Scalar.All(255), Scalar.All(0), 0, -1, LineFlags.Connected8, new Point(offset));
            }

            if (component.Contour != null)
            {
                CV.DrawContours(image, component.Contour, Scalar.Rgb(255, 0, 0), Scalar.Rgb(0, 0, 255), 0, 1, LineFlags.Connected8, new Point(offset));
            }
            CV.Line(image, major1, major2, Scalar.Rgb(0, 0, 255));
            CV.Line(image, minor1, minor2, Scalar.Rgb(255, 0, 0));
            CV.Circle(image, new Point(centroid), 2, Scalar.Rgb(255, 0, 0), -1);
        }