1

我正在使用 Aforge 对图像进行边缘检测,如何获得检测到的边缘点的 x,y?除了循环图像位图的明显方式。

这是来自 Aforge 示例的代码,但我怎样才能获得边缘点?

    // On Filters->Sobel edge detector
            private void sobelEdgesFiltersItem_Click( object sender, System.EventArgs e )
            {
                // save original image
                Bitmap originalImage = sourceImage;
                // get grayscale image
                sourceImage = Grayscale.CommonAlgorithms.RMY.Apply( sourceImage );
                // apply edge filter
                ApplyFilter( new SobelEdgeDetector( ) );
                // delete grayscale image and restore original
                sourceImage.Dispose( );
                sourceImage = originalImage;

// this is the part where the source image is now edge detected. How to get the x,y for //each point of the edge? 

                sobelEdgesFiltersItem.Checked = true;
            }
4

2 回答 2

6

过滤器只是顾名思义:过滤器(图像->处理->新图像)

我不知道边缘是否有类似的东西,但 AForge 有一个角检测器。我的示例加载图像,运行角落检测器并在每个角落显示红色小框。(您需要一个名为“pictureBox”的 PictureBox 控件)。

    public void DetectCorners()
    {
        // Load image and create everything you need for drawing
        Bitmap image = new Bitmap(@"myimage.jpg");
        Graphics graphics = Graphics.FromImage(image);
        SolidBrush brush = new SolidBrush(Color.Red);
        Pen pen = new Pen(brush);

        // Create corner detector and have it process the image
        MoravecCornersDetector mcd = new MoravecCornersDetector();
        List<IntPoint> corners = mcd.ProcessImage(image);

        // Visualization: Draw 3x3 boxes around the corners
        foreach (IntPoint corner in corners)
        {
            graphics.DrawRectangle(pen, corner.X - 1, corner.Y - 1, 3, 3);
        }

        // Display
        pictureBox.Image = image;
    }

它可能不是您正在寻找的东西,但它可能会有所帮助。

于 2011-09-09T07:28:08.103 回答
0

您想从某个形状中检测到边缘吗?因为如果是这样,您可以使用 BlobCounter 并推断出形状的坐标是什么。

//Measures and sorts the spots. Adds them to m_Spots
private void measureSpots(ref Bitmap inImage)
{
    //The blobcounter sees white as blob and black as background
    BlobCounter bc = new BlobCounter();
    bc.FilterBlobs = false;
    bc.ObjectsOrder = ObjectsOrder.Area; //Descending order
    try
    {
        bc.ProcessImage(inImage);
        Blob[] blobs = bc.GetObjectsInformation();

        Spot tempspot;
        foreach (Blob b in blobs)
        {
            //The Blob.CenterOfGravity gives back an Aforge.Point. You can't convert this to
            //a System.Drawing.Point, even though they are the same...
            //The location(X and Y location) of the rectangle is the upper left corner of the rectangle.
            //Now I should convert it to the center of the rectangle which should be the center
            //of the dot.
            Point point = new Point((int)(b.Rectangle.X + (0.5 * b.Rectangle.Width)), (int)(b.Rectangle.Y + (0.5 * b.Rectangle.Height)));

            //A spot (self typed class) has an area, coordinates, circularity and a rectangle that defines its region
            tempspot = new Spot(b.Area, point, (float)b.Fullness, b.Rectangle);

            m_Spots.Add(tempspot);
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

希望这会有所帮助。


输入此内容后,我看到了问题的日期,但看到我已经输入了所有内容,我将发布它。希望它会对某人有好处。

于 2013-11-25T11:46:00.657 回答