public IplImage BlobContourImage(IplImage src)
        {
            blobcontour = new IplImage(src.Size, BitDepth.U8, 3);
            bin         = this.Binary(src, 50);

            CvBlobs blobs = new CvBlobs();

            blobs.Label(bin);

            foreach (KeyValuePair <int, CvBlob> item in blobs)
            {
                CvBlob b = item.Value;

                CvContourChainCode cc = b.Contour;
                cc.Render(blobcontour);

                CvContourPolygon ex_polygon = cc.ConvertToPolygon();
                foreach (CvPoint p in ex_polygon)
                {
                    Cv.DrawCircle(blobcontour, p, 1, CvColor.Blue, -1);
                }

                for (int i = 0; i < b.InternalContours.Count; i++)
                {
                    CvContourPolygon in_polygon = b.InternalContours[i].ConvertToPolygon();
                    foreach (CvPoint p in in_polygon)
                    {
                        Cv.DrawCircle(blobcontour, p, 1, CvColor.Red, -1);
                    }
                }
            }
            return(blobcontour);
        }
Exemple #2
0
        public Blob()
        {
            using (var imgSrc = new IplImage(FilePath.Image.Shapes, LoadMode.Color))
                using (var imgBinary = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                    using (var imgRender = new IplImage(imgSrc.Size, BitDepth.U8, 3))
                        using (var imgContour = new IplImage(imgSrc.Size, BitDepth.U8, 3))
                            using (var imgPolygon = new IplImage(imgSrc.Size, BitDepth.U8, 3))
                            {
                                Cv.CvtColor(imgSrc, imgBinary, ColorConversion.BgrToGray);
                                Cv.Threshold(imgBinary, imgBinary, 100, 255, ThresholdType.Binary);

                                CvBlobs blobs = new CvBlobs();
                                blobs.Label(imgBinary);

                                foreach (KeyValuePair <int, CvBlob> item in blobs)
                                {
                                    CvBlob b = item.Value;
                                    Console.WriteLine("{0} | Centroid:{1} Area:{2}", item.Key, b.Centroid, b.Area);

                                    CvContourChainCode cc = b.Contour;
                                    cc.Render(imgContour);

                                    CvContourPolygon polygon = cc.ConvertToPolygon();
                                    foreach (CvPoint p in polygon)
                                    {
                                        imgPolygon.Circle(p, 1, CvColor.Red, -1);
                                    }

                                    /*
                                     * CvPoint2D32f circleCenter;
                                     * float circleRadius;
                                     * GetEnclosingCircle(polygon, out circleCenter, out circleRadius);
                                     * imgPolygon.Circle(circleCenter, (int) circleRadius, CvColor.Green, 2);
                                     */
                                }

                                blobs.RenderBlobs(imgSrc, imgRender);

                                using (new CvWindow("render", imgRender))
                                    using (new CvWindow("contour", imgContour))
                                        using (new CvWindow("polygon vertices", imgPolygon))
                                        {
                                            Cv.WaitKey(0);
                                        }
                            }
        }
Exemple #3
0
        public Blob()
        {
            using (IplImage imgSrc = new IplImage(Const.ImageShapes, LoadMode.Color))
                using (IplImage imgBinary = new IplImage(imgSrc.Size, BitDepth.U8, 1))
                    using (IplImage imgLabel = new IplImage(imgSrc.Size, BitDepth.F32, 1))
                        using (IplImage imgRender = new IplImage(imgSrc.Size, BitDepth.U8, 3))
                            using (IplImage imgContour = new IplImage(imgSrc.Size, BitDepth.U8, 3))
                                using (IplImage imgPolygon = new IplImage(imgSrc.Size, BitDepth.U8, 3))
                                {
                                    Cv.CvtColor(imgSrc, imgBinary, ColorConversion.BgrToGray);
                                    Cv.Threshold(imgBinary, imgBinary, 100, 255, ThresholdType.Binary);

                                    CvBlobs blobs = new CvBlobs();
                                    blobs.Label(imgBinary);

                                    foreach (KeyValuePair <int, CvBlob> item in blobs)
                                    {
                                        CvBlob b = item.Value;
                                        Console.WriteLine("{0} | Centroid:{1} Area:{2}", item.Key, b.Centroid, b.Area);

                                        CvContourChainCode cc = b.Contour;
                                        cc.Render(imgContour);

                                        CvContourPolygon polygon = cc.ConvertToPolygon();
                                        foreach (CvPoint p in polygon)
                                        {
                                            imgPolygon.Circle(p, 1, CvColor.Red, -1);
                                        }
                                    }

                                    blobs.RenderBlobs(imgSrc, imgRender);

                                    using (new CvWindow("render", imgRender))
                                        using (new CvWindow("contour", imgContour))
                                            using (new CvWindow("polygon vertices", imgPolygon))
                                            {
                                                Cv.WaitKey(0);
                                            }
                                }
        }