当前位置: 首页>>代码示例>>C#>>正文


C# BlobCounter.GetBlobsEdgePoints方法代码示例

本文整理汇总了C#中AForge.Imaging.BlobCounter.GetBlobsEdgePoints方法的典型用法代码示例。如果您正苦于以下问题:C# BlobCounter.GetBlobsEdgePoints方法的具体用法?C# BlobCounter.GetBlobsEdgePoints怎么用?C# BlobCounter.GetBlobsEdgePoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AForge.Imaging.BlobCounter的用法示例。


在下文中一共展示了BlobCounter.GetBlobsEdgePoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: calcDescriptorInfo

        public override void calcDescriptorInfo(Bitmap inImage)
        {
            shapeCount = new int[6];

            originalImage = image;
            image = imgProcessor.preProcessImage(inImage);

            g = Graphics.FromImage(originalImage);

            BlobCounter bCounter = new BlobCounter();
            bCounter.ProcessImage(image);
            Blob[] blobs = bCounter.GetObjectsInformation();

            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

            for (int i = 0; i < blobs.Length; i++)
            {
                if (blobs[i].Area < 100)
                {
                    continue;
                }
                List<IntPoint> edgePts = bCounter.GetBlobsEdgePoints(blobs[i]);
                checkShape(shapeChecker, edgePts);

            }

            g.Dispose();
        }
开发者ID:Buddhima,项目名称:MPEG7-FeatureExtractor,代码行数:28,代码来源:BlobHandler.cs

示例2: Rectangle

        public static void Rectangle(WriteableBitmap bitmap, DrawingContext dc)
        {
            // locating objects
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.FilterBlobs = true;
            blobCounter.MaxHeight = 375;
            blobCounter.MaxWidth = 375;
            System.Drawing.Bitmap image;
            using (var stream = new MemoryStream())
            {
                var encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitmap));
                encoder.Save(stream);
                image = new System.Drawing.Bitmap(stream);
            }
            blobCounter.ProcessImage(image);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // check for rectangles
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

            foreach (var blob in blobs)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);
                List<IntPoint> cornerPoints;

                // use the shape checker to extract the corner points
                if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
                {
                    // only do things if the corners form a rectangle
                    if (shapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
                    {
                        // here i use the graphics class to draw an overlay, but you
                        // could also just use the cornerPoints list to calculate your
                        // x, y, width, height values.
                        List<AForge.Point> Points = new List<AForge.Point>();
                        foreach (var point in cornerPoints)
                        {
                            Points.Add(new AForge.Point(point.X, point.Y));
                        }
                        var path = new PathFigure(new System.Windows.Point(Points.First().X, Points.First().Y), Points.Select(row => new System.Windows.Media.LineSegment(new System.Windows.Point(row.X, row.Y), false)), true);

                        dc.DrawGeometry(Brushes.Red, null, new PathGeometry(new PathFigure[] { path }));
                    }
                }
            }
        }
开发者ID:virrkharia,项目名称:dynamight,代码行数:47,代码来源:ImageProc.cs

示例3: ProcessFrame

        public Bitmap ProcessFrame(Bitmap inputBitmap, int x, int y)
        {
            // Create an image for AForge to process
            Bitmap workingImage = new Bitmap(inputBitmap.Width, inputBitmap.Height);
            workingImage = AForge.Imaging.Image.Clone(inputBitmap, PixelFormat.Format24bppRgb);

            // Create a mask for ROI selection
            Rectangle roi = new Rectangle(x - 30, y-30, 80, 80);

            Crop roicrop = new Crop(roi);
            Bitmap outimage = roicrop.Apply(workingImage);

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.ObjectsOrder = ObjectsOrder.Area;

            Blob[] blobs;

            // Find the blobs
            blobCounter.ProcessImage(outimage);
            blobs = blobCounter.GetObjectsInformation();
            List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[0]);

            GrahamConvexHull grahamScan = new GrahamConvexHull();
            List<IntPoint> hullPoints = grahamScan.FindHull(edgePoints);

            Graphics g = Graphics.FromImage(outimage);
            Pen redPen = new Pen(Color.Red, 2);

            g.DrawPolygon(redPen, ToPointsArray(hullPoints));

            //g.Clear(Color.Black);
            //g.DrawImage(handImage, x, y);
            //g.DrawRectangle(redPen, roi);
            //g.DrawEllipse(redPen, x, y, 20, 20);

            ResizeNearestNeighbor resizeFilter = new ResizeNearestNeighbor(160, 160);
            Bitmap resizedImage = resizeFilter.Apply(outimage);

            return resizedImage;
        }
开发者ID:pvishal,项目名称:kinect-hands,代码行数:40,代码来源:ImageProcessor.cs

示例4: DrawRectanglesFunct

        // =========================================================
        private Bitmap DrawRectanglesFunct(Bitmap image)
        {
            // step 1 - turn background to black (done)

            // step 2 - locating objects
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = 3;
            blobCounter.MinWidth = 3;
            blobCounter.ProcessImage(image);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // step 3 - check objects' type and do what you do:
            Graphics g = Graphics.FromImage(image);
            Pen pen = new Pen(Color.DarkOrange, 2);

            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                SimpleShapeChecker ShapeChecker = new SimpleShapeChecker();
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> cornerPoints;

                // fine tune ShapeChecker
                ShapeChecker.AngleError = 15;  // default 7
                ShapeChecker.LengthError = 0.3F;  // default 0.1 (10%)
                ShapeChecker.MinAcceptableDistortion = 0.9F;  // in pixels, default 0.5
                ShapeChecker.RelativeDistortionLimit = 0.2F;  // default 0.03 (3%)

                // use the Outline checker to extract the corner points
                if (ShapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
                {
                    // only do things if the corners form a rectangle
                    if (ShapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
                    {
                        List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints);
                        g.DrawPolygon(pen, ToPointsArray(corners));
                    }
                }
            }
            return (image);
        }
开发者ID:daveframe,项目名称:LitePlacer-DEV,代码行数:42,代码来源:Camera.cs

示例5: Quadrilaterals

        public static List<List<IntPoint>> Quadrilaterals(Bitmap img, int minWidth, int minHeight)
        {
            Bitmap thresholdedImg = FilterCombinations.AdaptiveThreshold(img);

            //Use blob recognition on the image to find all blobs meeting the specified minimum width & height
            BlobCounter blobCounter = new BlobCounter();

            //Filter out small blobs
            blobCounter.MinWidth = minWidth;
            blobCounter.MinHeight = minHeight;
            blobCounter.FilterBlobs = true;

            //Order the blobs by size (desc), as since we're looking for quads of a minimum size, it's likely we'll be more interested in the laregr ones
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            //Check if each blob is approximately a quadriateral, and if so store the 4 corners
            List<List<IntPoint>> foundQuads = new List<List<IntPoint>>();
            //Shape checker to be used to test if a blob is a quadrilateral
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

            //Find the blobs
            blobCounter.ProcessImage(thresholdedImg);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            foreach(Blob b in blobs)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(b);
                List<IntPoint> corners = null;

                //Is this blob approximately a quadrilateral?
                if(shapeChecker.IsQuadrilateral(edgePoints, out corners))
                {
                    //Store the Quad's corners
                    foundQuads.Add(corners);
                }
            }

            return foundQuads;
        }
开发者ID:JoshKeegan,项目名称:CVWS.NET,代码行数:39,代码来源:ShapeFinder.cs

示例6: GetSquares

        /// <summary>
        /// Gets the squares in the image
        /// </summary>
        /// <param name="cubeFace">Image to get the squares</param>
        /// <param name="minWidth">Minimum square width</param>
        /// <param name="minHeight">Minimum square height</param>
        /// <returns>Returns the list with the squares.</returns>
        public List<Rectangle> GetSquares(System.Drawing.Image cubeFace, int minWidth, int minHeight)
        {
            Squares = new List<Rectangle>();
            Bitmap bitmap = new Bitmap(cubeFace);
            // lock image
            System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);

            // step 1 - turn background to black
            ColorFiltering colorFilter = new ColorFiltering();

            colorFilter.Red = new AForge.IntRange(0, 64);
            colorFilter.Green = new AForge.IntRange(0, 64);
            colorFilter.Blue = new AForge.IntRange(0, 64);
            colorFilter.FillOutsideRange = false;

            colorFilter.ApplyInPlace(bitmapData);

            // step 2 - locating objects
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = minHeight;
            blobCounter.MinWidth = minWidth;

            blobCounter.ProcessImage(bitmapData);
            AForge.Imaging.Blob[] blobs = blobCounter.GetObjectsInformation();
            bitmap.UnlockBits(bitmapData);

            // step 3 - check objects' type and highlight
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> corners;
                // is triangle or quadrilateral
                if (shapeChecker.IsConvexPolygon(edgePoints, out corners) && corners.Count == 4)
                {
                    Squares.Add(blobs[i].Rectangle);
                }
            }
            return Squares;
        }
开发者ID:petcomputacaoufrgs,项目名称:roborubik,代码行数:51,代码来源:ImageAnalyser.cs

示例7: blob_detect

        public void blob_detect ()
        {
            Bitmap image = this.scanned_image;
            BlobCounter blob = new BlobCounter();
            blob.FilterBlobs = false;
            
            int blob_ht_width = 30;
            blob.MinHeight = blob_ht_width;
            blob.MinWidth = blob_ht_width;
            blob.ProcessImage(image);
            
            Blob[] b = blob.GetObjectsInformation();
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
            /*blob_counter.Text = b.Length.ToString();
            Graphics g = Graphics.FromImage(image2);
            Pen yellowPen = new Pen(Color.Yellow, 5);
            Pen redPen = new Pen(Color.Red, 5);
            Pen greenPen = new Pen(Color.Green, 5);
            int b_counter = 0;
             */
            for (int i = 0, n = b.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blob.GetBlobsEdgePoints(b[i]);
                List<IntPoint> edges = new List<IntPoint>();
                AForge.Point center;
                float radius;

                if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                {
                
                    if (b[i].Fullness * 100 >= 40 && b[i].Fullness * 100 < 100 && radius > 10)
                    {
                        Coordinate coor = new Coordinate(center.X, center.Y);
                        BLOB blb = new BLOB(coor, radius);
                        useful.Add(blb);
                    }   
                }    
            }
            
        }
开发者ID:SevaSoluation,项目名称:OMR-Scanner,代码行数:40,代码来源:OMRSoft.cs

示例8: ProcessImage


//.........这里部分代码省略.........
            //// apply the filter
            filter.ApplyInPlace(bitmapData);

            ////invert

            //edge

            //CannyEdgeDetector edge_filter = new CannyEdgeDetector();
            //// apply the filter
            //edge_filter.ApplyInPlace(bitmapData);

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = blob_size * 3;
            blobCounter.MinWidth = blob_size * 4;

            blobCounter.ProcessImage(bitmapData);
            Blob[] blobs = blobCounter.GetObjectsInformation();
            bitmap.UnlockBits(bitmapData);

            // step 3 - check objects' type and highlight
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
            Graphics g = Graphics.FromImage(bitmap);
            Pen yellowPen = new Pen(Color.Yellow, 2); // circles
            Pen redPen = new Pen(Color.Red, 2);       // quadrilateral
            Pen brownPen = new Pen(Color.Brown, 2);   // quadrilateral with known sub-type
            Pen greenPen = new Pen(Color.Green, 2);   // known triangle
            Pen bluePen = new Pen(Color.Blue, 2);     // triangle
            double curdist = 0;
            double leastdist = 100;
            //List<IntPoint> bestcorn;//promoted to super
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> corners; // the list of x,y coordinates.  corners(list)->corner(intpoint)->[x,y]

                // is triangle or quadrilateral

                if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
                {
                    cornide = corners;
                    // get sub-type

                    PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);
                    Pen pen;
                    if (subType == PolygonSubType.Rectangle || subType == PolygonSubType.Trapezoid || subType == PolygonSubType.Parallelogram || subType == PolygonSubType.Rhombus || subType == PolygonSubType.Square || subType == PolygonSubType.Unknown)
                    {

                        if (corners.Count == 4)
                        {
                            pen = redPen;
                            IntPoint[] array_of_corners = corners.ToArray();//array_of_corners is now an array of corners
                            if (((732 / avdisty(array_of_corners)) + .222) < ((989 / avdistx(array_of_corners)) + 3.37))
                            {
                                curdist = ((732 / avdisty(array_of_corners)) + .222);//from our graph
                            }
                            else
                            {
                                curdist = ((989 / avdistx(array_of_corners)) + 3.37);//from our graph
                            }

                            //if (Worker.selected_square == 1)
                            //{
                            //    Console.WriteLine("called\n");
                            //    IntPoint one = array_of_corners[0];
                            //    IntPoint two = array_of_corners[3];
开发者ID:ArrowheadRobotics,项目名称:2012VisionFramework,代码行数:67,代码来源:MainForm.cs

示例9: ParseImage

        private void ParseImage(int imageId)
        {
            DateTime startTime = DateTime.Now;
            labelDetection.Text = "";

            string difImagePath = "";

            if(imageId >= 0) difImagePath = DifBoardImages[imageId];

            Bitmap orig;
            Bitmap dif;

            try
            {
                orig = (Bitmap)Bitmap.FromFile(OriginalBoardImage);

                if (imageId >= 0)
                    dif = (Bitmap)Bitmap.FromFile(difImagePath);
                else
                    dif = (Bitmap)pictureBoxGenerated.Image;
            }
            catch {
                // kill any exception due to missing files
                return;
            }

            pictureBoxOrig.Image = dif;

            Difference filter = new Difference(orig);
            dif = filter.Apply(dif);

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.ProcessImage(dif);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // create Graphics object to draw on the image and a pen
            Graphics g = Graphics.FromImage(dif);
            Pen redPen = new Pen(Color.Red, 3);
            Pen bluePen = new Pen(Color.Blue, 1);
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
            // check each object and draw circle around objects, which
            // are recognized as circles
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);

                labelDetection.Text = string.Format("{0} points", edgePoints.Count);

                if (edgePoints.Count <= 1)
                    continue;

                List<IntPoint> points = new List<IntPoint>();

                if (shapeChecker.IsQuadrilateral(edgePoints))
                    labelDetection.Text += ", quadrilateral";
                else if (shapeChecker.IsConvexPolygon(edgePoints, out points))
                    labelDetection.Text += ", convex poligon";
                else if (shapeChecker.IsTriangle(edgePoints, out points))
                    labelDetection.Text += ", triangle";

                Pen usePen = shapeChecker.IsQuadrilateral(edgePoints) ? redPen : bluePen;

                int centerX = edgePoints[0].X;
                int centerY = edgePoints[0].Y;
                int minX = centerX;
                int minY = centerY;
                int maxX = centerX;
                int maxY = centerY;
                for (int j = 0; j < edgePoints.Count - 1; j++)
                {
                    centerX += edgePoints[j + 1].X;
                    centerY += edgePoints[j + 1].Y;

                    if (edgePoints[j + 1].X < minX) minX = edgePoints[j + 1].X;
                    if (edgePoints[j + 1].Y < minY) minY = edgePoints[j + 1].Y;
                    if (edgePoints[j + 1].X > maxX) maxX = edgePoints[j + 1].X;
                    if (edgePoints[j + 1].Y > maxX) maxX = edgePoints[j + 1].Y;

                    g.DrawLine(usePen, edgePoints[j].X, edgePoints[j].Y, edgePoints[j + 1].X, edgePoints[j + 1].Y);
                }

                g.DrawLine(usePen
                    , edgePoints[0].X, edgePoints[0].Y
                    , edgePoints[edgePoints.Count - 1].X, edgePoints[edgePoints.Count - 1].Y);

                labelDetectedPosition.Text = string.Format("{0}, {1}"
                    , new object[] {
                        (centerX / edgePoints.Count), (centerY / edgePoints.Count)
                        //, maxX - minX, maxY - minY
                    });
                labelDetectionOffset.Text = string.Format("{0}, {1}"
                    , Grigore.Position.X - (centerX / edgePoints.Count)
                    , Grigore.Position.Y - (centerY / edgePoints.Count)
                );
            }

            redPen.Dispose();
            bluePen.Dispose();
            g.Dispose();

//.........这里部分代码省略.........
开发者ID:strofos,项目名称:grigore,代码行数:101,代码来源:Form1.cs

示例10: detectPersonBlob

        //returns a bitmapsource object that can be layered to display where people are
        public BitmapSource detectPersonBlob(short[] depthArray, int dist, int width, int height)
        {
            BlobCounter bc = new BlobCounter();
            using (Bitmap arg = RenderPersonBlobMap(depthArray, dist, width, height))
            {
                BitmapData bmpd = arg.LockBits(new System.Drawing.Rectangle(0, 0, arg.Width, arg.Height), ImageLockMode.ReadWrite, arg.PixelFormat);
                bc.FilterBlobs = true;
                bc.MinHeight = 5;
                bc.MinWidth = 5;
                bc.ProcessImage(bmpd);
                arg.UnlockBits(bmpd);
            }
            this.t++;

            Blob[] blobs = bc.GetObjectsInformation();

            Frame fb = new Frame(t);
            foreach (Blob b in blobs)
            {
                List<IntPoint> edgepoints = bc.GetBlobsEdgePoints(b);
                if (b.Area > 4000)
                {
                    this.positions.Enqueue(new PointF(b.CenterOfGravity.X, b.CenterOfGravity.Y));
                    fb.addBlob(new personBlob(b.CenterOfGravity.X, b.CenterOfGravity.Y, b.Area));
                }

            }
            if (blobs.Length != 0)
            {
                using (Bitmap blobPositions = new Bitmap(640, 480))
                {

                    using (Graphics g = Graphics.FromImage(blobPositions))
                    {
                        List<PointF> points = this.positions.getList();
                        //foreach (personBlob b in fb.blobs)
                        foreach (PointF b in points)
                        {

                            g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Color.Blue), b.X, b.Y, 5, 5);
                        }
                    }
                    this.blobFrames.Add(fb);

                   return this.noise_remover.BitmapSourceFromBitmap(blobPositions);

                }
            }
            else
            {
                using (Bitmap blank = new Bitmap(640, 480))
                {
                    return this.noise_remover.BitmapSourceFromBitmap(blank);
                }
            }
        }
开发者ID:kuninagakura,项目名称:FlowMap,代码行数:57,代码来源:Map.cs

示例11: detectSpaceBlobs

        public BitmapSource detectSpaceBlobs(short[] depthArray, int dist, int width, int height)
        {
            BlobCounter bc = new BlobCounter();

            using (Bitmap arg = RenderSpaceDetectorMap(depthArray, dist, width, height))
            {
                BitmapData bmpd = arg.LockBits(new System.Drawing.Rectangle(0, 0, arg.Width, arg.Height), ImageLockMode.ReadWrite, arg.PixelFormat);
                bc.FilterBlobs = true;
                bc.MinHeight = 5;
                bc.MinWidth = 5;
                bc.ProcessImage(bmpd);
                arg.UnlockBits(bmpd);
            }

            Blob[] blobs = bc.GetObjectsInformation();
            Bitmap blank = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(blank);

            System.Drawing.Pen bluePen = new System.Drawing.Pen(System.Drawing.Color.Blue);
            foreach (Blob b in blobs)
            {
                List<IntPoint> edgepoints = bc.GetBlobsEdgePoints(b);
                PointF[] renderpoints = new PointF[edgepoints.Count];
                // List<PointF> renderpoints = new List<PointF>();
                if (b.Area > 200)
                {
                    foreach (IntPoint p in edgepoints)
                    {
                        g.DrawEllipse(bluePen, p.X, p.Y, 1, 1);
                    }
                }

            }
            bluePen.Dispose();
            g.Dispose();
            return this.noise_remover.BitmapSourceFromBitmap(blank);
        }
开发者ID:kuninagakura,项目名称:FlowMap,代码行数:37,代码来源:Map.cs

示例12: detectQuads

        private void detectQuads(Bitmap bitmap)
        {
            // Greyscale
            filteredBitmap = Grayscale.CommonAlgorithms.BT709.Apply(bitmap);

            // edge filter
            SobelEdgeDetector edgeFilter = new SobelEdgeDetector();
            edgeFilter.ApplyInPlace(filteredBitmap);

            // Threshhold filter
            Threshold threshholdFilter = new Threshold(190);
            threshholdFilter.ApplyInPlace(filteredBitmap);

            BitmapData bitmapData = filteredBitmap.LockBits(
                new Rectangle(0, 0, filteredBitmap.Width, filteredBitmap.Height),
                ImageLockMode.ReadWrite, filteredBitmap.PixelFormat);

            BlobCounter blobCounter = new BlobCounter();

            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = 125;
            blobCounter.MinWidth = 125;

            blobCounter.ProcessImage(bitmapData);
            Blob[] blobs = blobCounter.GetObjectsInformation();
            filteredBitmap.UnlockBits(bitmapData);

            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

            Bitmap bm = new Bitmap(filteredBitmap.Width, filteredBitmap.Height, PixelFormat.Format24bppRgb);

            Graphics g = Graphics.FromImage(bm);
            g.DrawImage(filteredBitmap, 0, 0);

            Pen pen = new Pen(Color.Red, 5);
            List<IntPoint> cardPositions = new List<IntPoint>();

            // Loop through detected shapes
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> corners;
                bool sameCard = false;

                // is triangle or quadrilateral
                if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
                {
                    // get sub-type
                    PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);

                    // Only return 4 corner rectanges
                    if ((subType == PolygonSubType.Parallelogram || subType == PolygonSubType.Rectangle) &&  corners.Count == 4)
                    {
                        // Check if its sideways, if so rearrange the corners so it's veritcal
                        rearrangeCorners(corners);

                        // Prevent it from detecting the same card twice
                        foreach (IntPoint point in cardPositions)
                        {
                            if (corners[0].DistanceTo(point) < 40)
                                sameCard = true;
                        }

                        if (sameCard)
                            continue;

                        // Hack to prevent it from detecting smaller sections of the card instead of the whole card
                        if (GetArea(corners) < 20000)
                            continue;

                        cardPositions.Add(corners[0]);

                        g.DrawPolygon(pen, ToPointsArray(corners));

                        // Extract the card bitmap
                        QuadrilateralTransformation transformFilter = new QuadrilateralTransformation(corners, 211, 298);
                        cardBitmap = transformFilter.Apply(cameraBitmap);

                        List<IntPoint> artCorners = new List<IntPoint>();
                        artCorners.Add(new IntPoint(14, 35));
                        artCorners.Add(new IntPoint(193, 35));
                        artCorners.Add(new IntPoint(193, 168));
                        artCorners.Add(new IntPoint(14, 168));

                        // Extract the art bitmap
                        QuadrilateralTransformation cartArtFilter = new QuadrilateralTransformation(artCorners, 183, 133);
                        cardArtBitmap = cartArtFilter.Apply(cardBitmap);

                        MagicCard card = new MagicCard();
                        card.corners = corners;
                        card.cardBitmap = cardBitmap;
                        card.cardArtBitmap = cardArtBitmap;

                        magicCards.Add(card);
                    }
                }
            }

            pen.Dispose();
            g.Dispose();
//.........这里部分代码省略.........
开发者ID:niugm,项目名称:Magic-Vision,代码行数:101,代码来源:Form1.cs

示例13: ProcessImage

        // Process image
        private void ProcessImage( Bitmap bitmap )
        {
            // lock image
            BitmapData bitmapData = bitmap.LockBits(
                new Rectangle( 0, 0, bitmap.Width, bitmap.Height ),
                ImageLockMode.ReadWrite, bitmap.PixelFormat );

            // step 1 - turn background to black
            ColorFiltering colorFilter = new ColorFiltering( );

            colorFilter.Red   = new IntRange( 0, 64 );
            colorFilter.Green = new IntRange( 0, 64 );
            colorFilter.Blue  = new IntRange( 0, 64 );
            colorFilter.FillOutsideRange = false;

            colorFilter.ApplyInPlace( bitmapData );

            // step 2 - locating objects
            BlobCounter blobCounter = new BlobCounter( );

            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = 5;
            blobCounter.MinWidth = 5;

            blobCounter.ProcessImage( bitmapData );
            Blob[] blobs = blobCounter.GetObjectsInformation( );
            bitmap.UnlockBits( bitmapData );

            // step 3 - check objects' type and highlight
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker( );

            Graphics g = Graphics.FromImage( bitmap );
            Pen yellowPen = new Pen( Color.Yellow, 2 ); // circles
            Pen redPen = new Pen( Color.Red, 2 );       // quadrilateral
            Pen brownPen = new Pen( Color.Brown, 2 );   // quadrilateral with known sub-type
            Pen greenPen = new Pen( Color.Green, 2 );   // known triangle
            Pen bluePen = new Pen( Color.Blue, 2 );     // triangle

            for ( int i = 0, n = blobs.Length; i < n; i++ )
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints( blobs[i] );

                AForge.Point center;
                float radius;

                // is circle ?
                if ( shapeChecker.IsCircle( edgePoints, out center, out radius ) )
                {
                    g.DrawEllipse( yellowPen,
                        (float) ( center.X - radius ), (float) ( center.Y - radius ),
                        (float) ( radius * 2 ), (float) ( radius * 2 ) );
                }
                else
                {
                    List<IntPoint> corners;

                    // is triangle or quadrilateral
                    if ( shapeChecker.IsConvexPolygon( edgePoints, out corners ) )
                    {
                        // get sub-type
                        PolygonSubType subType = shapeChecker.CheckPolygonSubType( corners );

                        Pen pen;

                        if ( subType == PolygonSubType.Unknown )
                        {
                            pen = ( corners.Count == 4 ) ? redPen : bluePen;
                        }
                        else
                        {
                            pen = ( corners.Count == 4 ) ? brownPen : greenPen;
                        }

                        g.DrawPolygon( pen, ToPointsArray( corners ) );
                    }
                }
            }

            yellowPen.Dispose( );
            redPen.Dispose( );
            greenPen.Dispose( );
            bluePen.Dispose( );
            brownPen.Dispose( );
            g.Dispose( );

            // put new image to clipboard
            Clipboard.SetDataObject( bitmap );
            // and to picture box
            pictureBox.Image = bitmap;

            UpdatePictureBoxPosition( );
        }
开发者ID:legendvijay,项目名称:AForge.NET,代码行数:93,代码来源:MainForm.cs

示例14: DetectBlobsInImage

        // todo: implement this
        //public IBlobsFilter BlobsFilter
        /// <summary>
        /// uses AForge to detect square (or rectangular, if tile is obscured) tiles in the image
        /// </summary>
        /// <param name="img"></param>
        public void DetectBlobsInImage(Bitmap img)
        {
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.ProcessImage(img);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            Graphics g = Graphics.FromImage(img);
            System.Drawing.Pen bluePen = new System.Drawing.Pen(System.Drawing.Color.Blue, 10);

            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                try
                {
                    List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                    List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints);

                    SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
                    PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);
                    if (subType == PolygonSubType.Square)
                    {
                        g.DrawPolygon(bluePen, PointsListToArray(corners));
                    }
                }
                catch (Exception) { }
            }

            bluePen.Dispose();
            g.Dispose();
        }
开发者ID:bridgette,项目名称:Minesweeper-AI,代码行数:35,代码来源:UIAutomation.cs

示例15: DetectQuads

        public void DetectQuads()
        {
            // Greyscale
            FilteredBitmap = Grayscale.CommonAlgorithms.BT709.Apply(CameraBitmap);

            // edge filter
            var edgeFilter = new SobelEdgeDetector();
            edgeFilter.ApplyInPlace(FilteredBitmap);

            // Threshhold filter
            var threshholdFilter = new Threshold(190);
            threshholdFilter.ApplyInPlace(FilteredBitmap);

            var bitmapData = FilteredBitmap.LockBits(
                new Rectangle(0, 0, FilteredBitmap.Width, FilteredBitmap.Height),
                ImageLockMode.ReadWrite, FilteredBitmap.PixelFormat);

            var blobCounter = new BlobCounter
            {
                FilterBlobs = true,
                MinHeight = 125,
                MinWidth = 125
            };

            blobCounter.ProcessImage(bitmapData);
            var blobs = blobCounter.GetObjectsInformation();
            FilteredBitmap.UnlockBits(bitmapData);

            var shapeChecker = new SimpleShapeChecker();

            var bm = new Bitmap(FilteredBitmap.Width, FilteredBitmap.Height, PixelFormat.Format24bppRgb);

            var g = Graphics.FromImage(bm);
            g.DrawImage(FilteredBitmap, 0, 0);

            var pen = new Pen((Color)new ColorConverter().ConvertFromString(Application.Current.Resources["AccentColor"].ToString()), 5);
            var cardPositions = new List<IntPoint>();

            // Loop through detected shapes
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                var edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> corners;
                var sameCard = false;

                // is triangle or quadrilateral
                if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                {
                    if (!corners.Any())
                        return;
                    // get sub-type
                    var subType = shapeChecker.CheckPolygonSubType(corners);

                    // Only return 4 corner rectanges
                    if ((subType != PolygonSubType.Parallelogram && subType != PolygonSubType.Rectangle) || corners.Count != 4)
                        continue;

                    // Check if its sideways, if so rearrange the corners so it's veritcal
                    RearrangeCorners(corners);

                    // Prevent it from detecting the same card twice
                    foreach (var point in cardPositions)
                    {
                        var distance = corners[0].DistanceTo(point);
                        if (corners[0].DistanceTo(point) < 40)
                            sameCard = true;
                    }

                    if (sameCard)
                        continue;

                    // Hack to prevent it from detecting smaller sections of the card instead of the whole card
                    var area = GetArea(corners);

                    if (area < 20000)// || area > 35000)
                        continue;

                    cardPositions.Add(corners[0]);

                    g.DrawPolygon(pen, ToPointsArray(corners));

                    // Extract the card bitmap
                    var transformFilter = new QuadrilateralTransformation(corners, 225, 325);
                    CardBitmap = transformFilter.Apply(CameraBitmap);
                    TmpCard = new MagicCard
                    {
                        Corners = corners,
                        CardBitmap = CardBitmap
                    };
                }
            }

            pen.Dispose();
            g.Dispose();

            FilteredBitmap = bm;
        }
开发者ID:RejectKid,项目名称:MTG-Scanner,代码行数:97,代码来源:WebcamController.cs


注:本文中的AForge.Imaging.BlobCounter.GetBlobsEdgePoints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。