Ejemplo n.º 1
0
        public static ConnectedComponent FromMoments(Moments moments)
        {
            var component = new ConnectedComponent();

            component.Area = moments.M00;

            // Cemtral moments can only be computed for components with non-zero area
            if (moments.M00 > 0)
            {
                // Compute centroid components
                var x = moments.M10 / moments.M00;
                var y = moments.M01 / moments.M00;
                component.Centroid = new Point2f((float)x, (float)y);

                // Compute second-order central moments
                var miu20 = moments.M20 / moments.M00 - x * x;
                var miu02 = moments.M02 / moments.M00 - y * y;
                var miu11 = moments.M11 / moments.M00 - x * y;

                // Compute orientation and major/minor axis length
                var b = 2 * miu11;
                component.Orientation = 0.5 * Math.Atan2(b, miu20 - miu02);
                var deviation = Math.Sqrt(b * b + Math.Pow(miu20 - miu02, 2));
                component.MajorAxisLength = Math.Sqrt(6 * (miu20 + miu02 + deviation));
                component.MinorAxisLength = Math.Sqrt(6 * (miu20 + miu02 - deviation));
            }
            else
            {
                component.Centroid    = new Point2f(float.NaN, float.NaN);
                component.Orientation = double.NaN;
            }

            return(component);
        }
Ejemplo n.º 2
0
        public override IObservable <ConnectedComponentCollection> Process(IObservable <Contours> source)
        {
            return(source.Select(input =>
            {
                var currentContour = input.FirstContour;
                var output = new ConnectedComponentCollection(input.ImageSize);

                while (currentContour != null)
                {
                    var component = ConnectedComponent.FromContour(currentContour);
                    currentContour = currentContour.HNext;
                    output.Add(component);
                }

                return output;
            }));
        }
Ejemplo n.º 3
0
        public IObservable <ConnectedComponentCollection> Process(IObservable <Tuple <Contours, IplImage> > source)
        {
            return(source.Select(input =>
            {
                var image = input.Item2;
                var contours = input.Item1;
                var currentContour = contours.FirstContour;
                var output = new ConnectedComponentCollection(image.Size);

                while (currentContour != null)
                {
                    var component = ConnectedComponent.FromContour(currentContour);
                    component.Patch = image.GetSubRect(component.Contour.Rect);
                    currentContour = currentContour.HNext;
                    output.Add(component);
                }

                return output;
            }));
        }
Ejemplo n.º 4
0
 public IObservable <ConnectedComponent> Process(IObservable <Seq> source)
 {
     return(source.Select(input => ConnectedComponent.FromContour(input)));
 }
Ejemplo n.º 5
0
 public IObservable <ConnectedComponent> Process(IObservable <IplImage> source)
 {
     return(source.Select(input => ConnectedComponent.FromImage(input, binary: true)));
 }