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


C# BlobCounter.GetBlobsLeftAndRightEdges方法代码示例

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


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

示例1: detectionGlyph

        public double[] detectionGlyph(bool CalculTailleTerrain)
        {
            bool Trouve = false;
            double[] ratio = new double[2] { 0, 0 };
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinHeight = 23;
            blobCounter.MinWidth = 23;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            // 4 - find all stand alone blobs
            blobCounter.ProcessImage(imgContour);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // 5 - check each blob
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> corners = null;

                // Test de la forme selectionnée
                if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                {
                    // Détection des points de coutour
                    List<IntPoint> leftEdgePoints, rightEdgePoints, topEdgePoints, bottomEdgePoints;

                    Line Horizontale = Line.FromPoints(new IntPoint(0,0),new IntPoint(10,0));
                    blobCounter.GetBlobsLeftAndRightEdges(blobs[i], out leftEdgePoints, out rightEdgePoints);
                    blobCounter.GetBlobsTopAndBottomEdges(blobs[i], out topEdgePoints, out bottomEdgePoints);

                    // calculate average difference between pixel values from outside of the
                    // shape and from inside
                    float diff = CalculateAverageEdgesBrightnessDifference(leftEdgePoints, rightEdgePoints, imgNB);
                    // check average difference, which tells how much outside is lighter than
                    // inside on the average
                    if (diff > 20)
                    {
                        // Transformation de l'image reçu en un carré pour la reconnaissance
                        QuadrilateralTransformation quadrilateralTransformation = new QuadrilateralTransformation(corners, 60, 60);
                        UnmanagedImage glyphImage = quadrilateralTransformation.Apply(imgNB);

                        // Filtre de contraste
                        OtsuThreshold otsuThresholdFilter = new OtsuThreshold();
                        otsuThresholdFilter.ApplyInPlace(glyphImage);
                        imgContour = glyphImage;
                        // Reconnaissance du Glyph
                        Glyph Gl = new Glyph(glyphImage, GlyphSize);

                        Gl.ReconnaissanceGlyph(corners, imgNB);

                        // Si le Glyph est valide
                        if (Gl.getIdentifiant() > 0)
                        {
                            if (AutAffichage[0])
                            {
                                // Coloration des contours des zones détectées
                                UnImgReel.SetPixels(leftEdgePoints, Color.Red);
                                UnImgReel.SetPixels(rightEdgePoints, Color.Red);
                                UnImgReel.SetPixels(topEdgePoints, Color.Red);
                                UnImgReel.SetPixels(bottomEdgePoints, Color.Red);
                            }

                            // Détection du milieu
                            Line line = Line.FromPoints(corners[0], corners[2]);
                            Line line2 = Line.FromPoints(corners[1], corners[3]);
                            IntPoint intersection = (IntPoint)line.GetIntersectionWith(line2);
                            if (AutAffichage[1])
                            {
                                dessinePoint(intersection, UnImgReel, 4, Color.Yellow);
                            }

                            // Calcul de la rotation
                            Line ComparasionAngle = Line.FromPoints(corners[0], corners[1]);
                            Double rotation = (int) ComparasionAngle.GetAngleBetweenLines(Horizontale);
                            rotation += 90 * Gl.getNbRotation();
                            Gl.rotation = 360 - rotation;
                            rotation *= (Math.PI / 180.0);

                            // Calcul d'un point en bout de pince
                            float Taille = corners[0].DistanceTo(corners[1]);

                            float taille = (Taille / BibliotequeGlyph.Biblioteque[Gl.getPosition()].taille) * BibliotequeGlyph.Biblioteque[Gl.getPosition()].DistancePince;
                            int x = -(int)(System.Math.Sin(rotation) * taille);
                            int y = -(int)(System.Math.Cos(rotation) * taille);
                            x += (int)intersection.X;
                            y += (int)intersection.Y;
                            Gl.Position = new int[2]{x,y};
                            if (AutAffichage[2])
                            {
                                dessinePoint(new IntPoint(x, y), UnImgReel, 4, Color.Cyan);
                            }
                            imgContour = Gl.getImage();
                            addGlyph(Gl);

                            if (CalculTailleTerrain == true && Trouve == false)
                            {
                                Trouve = true;
                                int tailleglyph = BibliotequeGlyph.Biblioteque[Gl.getPosition()].taille;
//.........这里部分代码省略.........
开发者ID:KiLMaN,项目名称:LPIE_Robot_Color,代码行数:101,代码来源:ImgWebCam.cs

示例2: FindComponentsFunct

        // ==========================================================================================================
        // Components:
        // ==========================================================================================================
        private List<Shapes.Component> FindComponentsFunct(Bitmap bitmap)
        {
            // Locating objects
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.FilterBlobs = true;
            blobCounter.MinHeight = 8;
            blobCounter.MinWidth = 8;
            blobCounter.ProcessImage(bitmap);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // create convex hull searching algorithm
            GrahamConvexHull hullFinder = new GrahamConvexHull();
            ClosePointsMergingOptimizer optimizer1 = new ClosePointsMergingOptimizer();
            FlatAnglesOptimizer optimizer2 = new FlatAnglesOptimizer();

            List<Shapes.Component> Components = new List<Shapes.Component>();

            // process each blob
            foreach (Blob blob in blobs)
            {
                List<IntPoint> leftPoints, rightPoints, edgePoints = new List<IntPoint>();
                if ((blob.Rectangle.Height > 400) && (blob.Rectangle.Width > 600))
                {
                    break;	// The whole image could be a blob, discard that
                }
                // get blob's edge points
                blobCounter.GetBlobsLeftAndRightEdges(blob,
                    out leftPoints, out rightPoints);

                edgePoints.AddRange(leftPoints);
                edgePoints.AddRange(rightPoints);

                // blob's convex hull
                List<IntPoint> Outline = hullFinder.FindHull(edgePoints);
                optimizer1.MaxDistanceToMerge = 4;
                optimizer2.MaxAngleToKeep = 170F;
                Outline = optimizer2.OptimizeShape(Outline);
                Outline = optimizer1.OptimizeShape(Outline);

                // find Longest line segment
                float dist = 0;
                LineSegment Longest = new LineSegment(Outline[0], Outline[1]);
                LineSegment line;
                dist = Longest.Length;
                int LongestInd = 0;
                for (int i = 1; i < Outline.Count; i++)
                {
                    if (i != Outline.Count - 1)
                    {
                        line = new LineSegment(Outline[i], Outline[i + 1]);
                    }
                    else
                    {
                        // last iteration
                        if (Outline[i] == Outline[0])
                        {
                            break;
                        }
                        line = new LineSegment(Outline[i], Outline[0]);
                    }
                    if (line.Length > dist)
                    {
                        Longest = line;
                        dist = line.Length;
                        LongestInd = i;
                    }
                }
                // Get the center point of it
                AForge.Point LongestCenter = new AForge.Point();
                LongestCenter.X = (float)Math.Round((Longest.End.X - Longest.Start.X) / 2.0 + Longest.Start.X);
                LongestCenter.Y = (float)Math.Round((Longest.End.Y - Longest.Start.Y) / 2.0 + Longest.Start.Y);
                AForge.Point NormalStart = new AForge.Point();
                AForge.Point NormalEnd = new AForge.Point();
                // Find normal:
                // start= longest.start rotated +90deg relative to center
                // end= longest.end rotated -90deg and relative to center
                // If you rotate point (px, py) around point (ox, oy) by angle theta you'll get:
                // p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
                // p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy
                // cos90 = 0, sin90= 1 =>
                // p'x= -(py-oy) + ox= oy-py+ox, p'y= (px-ox)+ oy
                NormalStart.X = LongestCenter.Y - Longest.Start.Y + LongestCenter.X;
                NormalStart.Y = (Longest.Start.X - LongestCenter.X) + LongestCenter.Y;
                // cos-90=0, sin-90= -1 =>
                // p'x= (py-oy) + ox
                // p'y= -(px-ox)+oy= ox-px+oy
                NormalEnd.X = (Longest.Start.Y - LongestCenter.Y) + LongestCenter.X;
                NormalEnd.Y = LongestCenter.X - Longest.Start.X + LongestCenter.Y;
                // Make line out of the points
                Line Normal = Line.FromPoints(NormalStart, NormalEnd);

                // Find the furthest intersection to the normal (skip the Longest)
                AForge.Point InterSection = new AForge.Point();
                AForge.Point Furthest = new AForge.Point();
                bool FurhtestAssinged = false;
                LineSegment seg;
                dist = 0;
//.........这里部分代码省略.........
开发者ID:daveframe,项目名称:LitePlacer-DEV,代码行数:101,代码来源:Camera.cs

示例3: GlyphsPotentialsTracking

        /// <summary>
        /// Get rectangle contain glyphs in current frame
        /// </summary>
        /// <param name="image">Frame source</param>
        /// <param name="lists">Rectangles contain glyphs</param>
        public static void GlyphsPotentialsTracking(ref UnmanagedImage image, ref List<Rectangle> lists)
        {
            // 1 - grayscaling
            UnmanagedImage grayImage = null;

            if (image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                grayImage = image;
            }
            else
            {
                grayImage = UnmanagedImage.Create(image.Width, image.Height,
                    PixelFormat.Format8bppIndexed);
                Grayscale.CommonAlgorithms.BT709.Apply(image, grayImage);
            }

            // 2 - Edge detection
            DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector();
            UnmanagedImage edgesImage = edgeDetector.Apply(grayImage);

            // 3 - Threshold edges
            Threshold thresholdFilter = new Threshold(80);
            thresholdFilter.ApplyInPlace(edgesImage);

            //// ---------------- MILESTONE
            //image = edgesImage;
            //return;

            // create and configure blob counter
            BlobCounter blobCounter = new BlobCounter();

            blobCounter.MinHeight = 32;
            blobCounter.MinWidth = 32;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            // 4 - find all stand alone blobs
            blobCounter.ProcessImage(edgesImage);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            List<IntPoint> edgePoints = null;
            List<IntPoint> corners = null;
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

            // 5 - check each blob
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                corners = null;

                // does it look like a quadrilateral ?
                if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                {
                    // get edge points on the left and on the right side
                    List<IntPoint> leftEdgePoints, rightEdgePoints;

                    blobCounter.GetBlobsLeftAndRightEdges(blobs[i],
                        out leftEdgePoints, out rightEdgePoints);

                    // calculate average difference between pixel values from outside of the
                    // shape and from inside
                    float diff = CalculateAverageEdgesBrightnessDifference(
                        leftEdgePoints, rightEdgePoints, grayImage);

                    // check average difference, which tells how much outside is lighter than
                    // inside on the average
                    if (diff > 20)
                    {
                        lists.Add(blobs[i].Rectangle);
                    }
                }
            }
        }
开发者ID:pinkuyt,项目名称:a-pod-project-team-3,代码行数:78,代码来源:ObjectDetector.cs

示例4: ProcessBlobs

        private System.Drawing.Image ProcessBlobs(Bitmap image, Bitmap ProcessedImage, Input input)
        {
            Bitmap ResultImage;                                     // our return image variable
            // Choose which view to overlay our data on
            if (NoFilters)
            {
                ResultImage = (Bitmap)image.Clone();
            }
            else
            {
                ResultImage = new Bitmap(xMax / 2,yMax);
            }

            // Create the blob counter and get the blob info array for further processing
            BlobCounter blobCounter = new BlobCounter();
            // We *COULD* filter blobs here, but as pointed out that blocks the ability to eventually twist the hand/fingers horizontally.
            //blobCounter.FilterBlobs = true;
            //blobCounter.MinHeight = minHeight;
            //blobCounter.MaxWidth = maxWidth;
            blobCounter.ProcessImage(ProcessedImage);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            // create convex hull searching algorithm
            GrahamConvexHull hullFinder = new GrahamConvexHull();

            // Create graphics control to draw in the picture
            Graphics g = Graphics.FromImage(ResultImage);

            // Label the camfeeds just to prove this works right...
            g.DrawString(input.ToString(), new Font("Arial", 16), new SolidBrush(Color.Blue), new PointF(0, 0));

            // process each blob
            foreach (Blob blob in blobs)
            {
                if (CheckBlob(blob))
                {
                    List<IntPoint> leftPoints, rightPoints;
                    List<IntPoint> edgePoints = new List<IntPoint>();

                    // get blob's edge points
                    blobCounter.GetBlobsLeftAndRightEdges(blob,
                        out leftPoints, out rightPoints);

                    edgePoints.AddRange(leftPoints);
                    edgePoints.AddRange(rightPoints);

                    // calculate the blob's convex hull
                    List<IntPoint> hull = hullFinder.FindHull(edgePoints);

                    // Calculate depth
                    int pix = (int)CvInvoke.cvGet2D(disparity, blob.Rectangle.Top, ((blob.Rectangle.Left + blob.Rectangle.Right) / 2)).v0;

                    // Draw the blob hull and id it with the width/height
                    g.DrawPolygon(new Pen(Color.Blue), IntPointsToPointFs(hull.ToArray()));
                    string coord = "";
                    coord += blob.Rectangle.Width.ToString() + ",";         // X
                    coord += blob.Rectangle.Height.ToString() + ",";        // Y
                    coord += pix.ToString();                              // Z
                    g.DrawString(coord, new Font("Arial", 16), new SolidBrush(Color.Blue), new PointF(hull[0].X, hull[0].Y));

                    // This next line is all we should need once done debugging/designing. Toss the image manipulation.
                    hand.AddFinger(new System.Drawing.Point(((blob.Rectangle.Left + blob.Rectangle.Right) / 2), blob.Rectangle.Top), pix, (Hand.Input)input);
                }
            }

            return ResultImage;
        }
开发者ID:oswaldo-grassiotto,项目名称:TouchPlusCMDR,代码行数:67,代码来源:Viewer.cs

示例5: Find

        public static Bitmap Find(Blob blob, BlobCounter blobCounter, FoundColorSpaces colorSpaces)
        {
            List<IntPoint> blobPoints = new List<IntPoint>();
            List<IntPoint> leftPoints, rightPoints;
            blobCounter.GetBlobsLeftAndRightEdges(blob, out leftPoints, out rightPoints);

            Bitmap bmp = new Bitmap(blob.Rectangle.Width, blob.Rectangle.Height, PixelFormat.Format24bppRgb);
            for (int c = 0; c < leftPoints.Count; c++)
            {
                IntPoint startLeft = leftPoints[c];
                IntPoint endRight = rightPoints[c];

                for (int x = startLeft.X; x <= endRight.X; x++)
                {
                    blobPoints.Add(new IntPoint(x - blob.Rectangle.Left, startLeft.Y - blob.Rectangle.Top));
                    bmp.SetPixel(x - blob.Rectangle.Left, startLeft.Y - blob.Rectangle.Top,
                        colorSpaces.OriginalColorSpace.GetPixel(x, startLeft.Y)); 
                }
            }

            double[,] aData = new double[blobPoints.Count, 2];
            double[,] eData = new double[blobPoints.Count, 2];
            double[] bData = new double[blobPoints.Count];

            double centroidX = 0;
            double centroidY = 0;
            double total = 0;
            for (int c = 0; c < blobPoints.Count; c++)
            {
                centroidX += blobPoints[c].X;
                centroidY += blobPoints[c].Y;

                total++;
            }

            centroidX /= total;
            centroidY /= total;

            for (int c = 0; c < blobPoints.Count; c++)
            {
                eData[c, 0] = blobPoints[c].X - centroidX;
                eData[c, 1] = blobPoints[c].Y - centroidY;

                aData[c, 0] = 1;
                aData[c, 1] = blobPoints[c].X;

                bData[c] = blobPoints[c].Y;
            }

            DenseMatrix E = DenseMatrix.OfArray(eData);
            DenseMatrix Eprime = (DenseMatrix)E.TransposeThisAndMultiply(E);
            DenseEvd eigen = new DenseEvd(Eprime);
            Vector<Complex> eigenValues = eigen.EigenValues();
            int maxIndex = 0;
            double max = 0.0;
            for (int c = 0; c < eigenValues.Count; c++)
            {
                double eigenvalue = eigenValues[c].Real;
                if (eigenvalue > max)
                {
                    max = eigenvalue;
                    maxIndex = c;
                }
            }
            Matrix<double> eigenVectors = eigen.EigenVectors();
            Vector<double> maxEigenVector = eigenVectors.Column(maxIndex);
            Matrix<double> xHat = DenseMatrix.OfColumns(2, 1, new List<Vector<double>>(new Vector<double>[] { maxEigenVector }));

            double radians = System.Math.Asin(xHat[0, 0]);
            double degrees = radians * (180 / System.Math.PI); 

            // Why doesn't this work?
            //DenseMatrix A = DenseMatrix.OfArray(aData);
            //DenseVector b = new DenseVector(bData);
            //Matrix<double> xHat = (A.TransposeThisAndMultiply(A).Inverse() * A.Transpose() * b).ToColumnMatrix();

            RotateBicubic rotate = new RotateBicubic(-degrees);
            bmp = rotate.Apply(bmp); 

            return bmp;
        }
开发者ID:kwende,项目名称:SetSpotter,代码行数:81,代码来源:AxisAlignedBlobFinder.cs

示例6: Process

        // Process specified image trying to recognize counter's image
        public void Process( Bitmap image, IImageProcessingLog log )
        {
            log.AddMessage( "Image size: " + image.Width + " x " + image.Height );

            // 1 - Grayscale
            Bitmap grayImage = Grayscale.CommonAlgorithms.BT709.Apply( image );
            log.AddImage( "Grayscale", grayImage );

            // 2 - Edge detection
            DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector( ); 
            Bitmap edges = edgeDetector.Apply( grayImage );
            log.AddImage( "Edges", edges );

            // 3 - Threshold edges
            Threshold thresholdFilter = new Threshold( 40 ); 
            thresholdFilter.ApplyInPlace( edges );
            log.AddImage( "Thresholded Edges", edges );

            // 4 - Blob Counter
            BlobCounter blobCounter = new BlobCounter( );
            blobCounter.MinHeight = 32;
            blobCounter.MinWidth  = 32;
            blobCounter.FilterBlobs  = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            blobCounter.ProcessImage( edges );
            Blob[] blobs = blobCounter.GetObjectsInformation( );

            // create copy of source image, so we could draw on it
            Bitmap imageCopy = AForge.Imaging.Image.Clone( image );

            BitmapData imageData = imageCopy.LockBits( new Rectangle( 0, 0, image.Width, image.Height ),
                ImageLockMode.ReadWrite, imageCopy.PixelFormat );

            // lock grayscale image, so we could access it's pixel values
            BitmapData grayData = grayImage.LockBits( new Rectangle( 0, 0, image.Width, image.Height ),
                ImageLockMode.ReadOnly, grayImage.PixelFormat );
            UnmanagedImage grayUI = new UnmanagedImage( grayData );

            // list of found dark/black quadrilaterals surrounded by white area
            List<List<IntPoint>> foundObjects = new List<List<IntPoint>>( );
            // shape checker for checking quadrilaterals
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker( );

            // 5 - check each blob
            for ( int i = 0, n = blobs.Length; i < n; i++ )
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints( blobs[i] );
                List<IntPoint> corners = null;

                // does it look like a quadrilateral ?
                if ( shapeChecker.IsQuadrilateral( edgePoints, out corners ) )
                {
                    // do some more checks to filter so unacceptable shapes
                    // if ( CheckIfShapeIsAcceptable( corners ) )
                    {
                        log.AddMessage( "Blob size: " + blobs[i].Rectangle.Width + " x " + blobs[i].Rectangle.Height );

                        // get edge points on the left and on the right side
                        List<IntPoint> leftEdgePoints, rightEdgePoints;
                        blobCounter.GetBlobsLeftAndRightEdges( blobs[i], out leftEdgePoints, out rightEdgePoints );

                        // calculate average difference between pixel values from outside of the shape and from inside
                        float diff = CalculateAverageEdgesBrightnessDifference(
                            leftEdgePoints, rightEdgePoints, grayUI );

                        log.AddMessage( "Avg Diff: " + diff );

                        // check average difference, which tells how much outside is lighter than inside on the average
                        if ( diff > 20 )
                        {
                            Drawing.Polygon( imageData, corners, Color.Red );
                            // add the object to the list of interesting objects for further processing
                            foundObjects.Add( corners );
                        }
                    }
                }
            }

            imageCopy.UnlockBits( imageData );
            grayImage.UnlockBits( grayData );

            log.AddImage( "Potential glyps", imageCopy );

            int counter = 1;

            // further processing of each potential glyph
            foreach ( List<IntPoint> corners in foundObjects )
            {
                log.AddMessage( "Glyph #" + counter );
                
                log.AddMessage( string.Format( "Corners: ({0}), ({1}), ({2}), ({3})",
                    corners[0], corners[1], corners[2], corners[3] ) );

                // 6 - do quadrilateral transformation
                QuadrilateralTransformation quadrilateralTransformation =
                    new QuadrilateralTransformation( corners, 250, 250 );

                Bitmap transformed = quadrilateralTransformation.Apply( grayImage );
//.........这里部分代码省略.........
开发者ID:sic2,项目名称:HaptiQ,代码行数:101,代码来源:GlyphRecognizer.cs

示例7: Process


//.........这里部分代码省略.........
        System.Drawing.PointF[] quadrado67 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado68 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado69 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado70 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado71 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado72 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado73 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado74 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado75 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado76 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado77 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado78 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado79 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado80 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado81 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado82 = new System.Drawing.PointF[4];
        System.Drawing.PointF[] quadrado83 = new System.Drawing.PointF[4];
        IntPoint Center = new IntPoint(0, 0);
        const int stepSize = 2;
        for (int i = 0, n = blobs.Length; i < n; i++)
        {
            List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
            List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints);

            System.Drawing.Point[] crn = new System.Drawing.Point[4];
            for (int jj = 0; jj < corners.Count; jj++)
            {
                crn[jj] = new System.Drawing.Point(corners[jj].X, corners[jj].Y);
            }
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
            if (shapeChecker.IsQuadrilateral(edgePoints))
            {
                List<IntPoint> leftEdgePoints, rightEdgePoints;
                blobCounter.GetBlobsLeftAndRightEdges(blobs[i], out leftEdgePoints, out rightEdgePoints);
                List<IntPoint> leftEdgePoints1 = new List<IntPoint>();
                List<IntPoint> leftEdgePoints2 = new List<IntPoint>();
                List<IntPoint> rightEdgePoints1 = new List<IntPoint>();
                List<IntPoint> rightEdgePoints2 = new List<IntPoint>();
                int tx1, tx2, ty;
                int widthM1 = uimage.Width - 1;
                for (int k = 0; k < leftEdgePoints.Count; k++)
                {
                    tx1 = leftEdgePoints[k].X - stepSize;
                    tx2 = leftEdgePoints[k].X + stepSize;
                    ty = leftEdgePoints[k].Y;
                    leftEdgePoints1.Add(new IntPoint((tx1 < 0) ? 0 : tx1, ty));
                    leftEdgePoints2.Add(new IntPoint((tx2 > widthM1) ? widthM1 : tx2, ty));
                    tx1 = rightEdgePoints[k].X - stepSize;
                    tx2 = rightEdgePoints[k].X + stepSize;
                    ty = rightEdgePoints[k].Y;
                    rightEdgePoints1.Add(new IntPoint((tx1 < 0) ? 0 : tx1, ty));
                    rightEdgePoints2.Add(new IntPoint((tx2 > widthM1) ? widthM1 : tx2, ty));
                }
                byte[] leftValues1 = uimage.Collect8bppPixelValues(leftEdgePoints1);
                byte[] leftValues2 = uimage.Collect8bppPixelValues(leftEdgePoints2);
                byte[] rightValues1 = uimage.Collect8bppPixelValues(rightEdgePoints1);
                byte[] rightValues2 = uimage.Collect8bppPixelValues(rightEdgePoints2);
                float diff = 0;
                int pixelCount = 0;
                for (int k = 0; k < leftEdgePoints.Count; k++)
                {
                    if (rightEdgePoints[k].X - leftEdgePoints[k].X > stepSize * 2)
                    {
                        diff += (leftValues1[k] - leftValues2[k]);
                        diff += (rightValues2[k] - rightValues1[k]);
                        pixelCount += 2;
开发者ID:jeffersonpp,项目名称:REPO,代码行数:67,代码来源:ImageProcessor.cs

示例8: findObjects


//.........这里部分代码省略.........
                stopwatch.Stop();
                Console.WriteLine("Blob finding time = " + stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();

                //// create unmanaged copy of source image, so we could draw on it
                //UnmanagedImage imageData = UnmanagedImage.FromManagedImage(image);

                // Get unmanaged copy of grayscale image, so we could access it's pixel values
                grayUI = UnmanagedImage.FromManagedImage(grayImage);

                // list of found dark/black quadrilaterals surrounded by white area
                List<List<IntPoint>> foundObjects = new List<List<IntPoint>>();
                // shape checker for checking quadrilaterals
                SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

                Console.WriteLine("edgePoints");

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

                    List<IntPoint> corners = null;

                    // does it look like a quadrilateral ?
                    if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                    {
                        // do some more checks to filter so unacceptable shapes
                        // if ( CheckIfShapeIsAcceptable( corners ) )
                        {

                            // get edge points on the left and on the right side
                            List<IntPoint> leftEdgePoints, rightEdgePoints;
                            blobCounter.GetBlobsLeftAndRightEdges(blobs[i], out leftEdgePoints, out rightEdgePoints);

                            // calculate average difference between pixel values from outside of the shape and from inside
                            float diff = this.CalculateAverageEdgesBrightnessDifference(
                                leftEdgePoints, rightEdgePoints, grayUI);

                            // check average difference, which tells how much outside is lighter than inside on the average
                            if (diff > 20)
                            {
                                //Drawing.Polygon(imageData, corners, Color.FromArgb(255, 255, 0, 0));
                                // add the object to the list of interesting objects for further processing
                                foundObjects.Add(corners);
                            }
                        }
                    }
                }

                stopwatch.Stop();
                Console.WriteLine("Finding black quadiralateral surrounded by white area = " + stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();


                int recordedTimeForRgbFrame = (int)(videoReader.totalMiliTime * frameNo / (videoReader.frameCount - 1));

                CameraSpacePoint[] csps = new CameraSpacePoint[videoReader.frameWidth * videoReader.frameHeight];
                if (depthReader != null)
                {
                    ushort[] depthValues = depthReader.readFrameAtTime(recordedTimeForRgbFrame);
                    mappingFunction(depthValues, csps);
                }

                stopwatch.Stop();
                Console.WriteLine("Mapping into 3 dimensional = " + stopwatch.ElapsedMilliseconds);
开发者ID:tuandnvn,项目名称:ecat,代码行数:67,代码来源:GlyphBoxObjectRecognition.cs


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