AForge.net 边缘检测 - 如何获取边缘点?

发布于 2024-12-04 00:24:41 字数 913 浏览 2 评论 0原文

我正在使用 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;
            }

I am using Aforge to run edge detection on an image, how would I get the x,y for the detected edge(s) points? Other than the obvious way of looping through the image bitmaps.

This is the code from the Aforge samples, but how can I get the edge points?

    // 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;
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身软味 2024-12-11 00:24:41

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

我不知道是否有类似的边缘,但 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;
    }

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

The filters are merely what the name suggests: Filters (Image -> Process -> NewImage)

I don't know, if there is something similar for edges, but AForge has a corner detector. My sample loads an image, runs the corner detector and displays little red boxes around every corner. (You'll need a PictureBox control named "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;
    }

It might not be exactly what you're looking for, but maybe it helps.

和我恋爱吧 2024-12-11 00:24:41

您想要检测特定形状的边缘吗?因为如果是这样,您可以使用 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);
    }
}

希望这有帮助。


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

Are the edges you want to detect from a certain shape? Because if so, you can use a BlobCounter and reason out what the coordinates of the shape are.

//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);
    }
}

Hopefully this helps.


After typing this I saw the questions' date, but seeing as how I've already typed everything I'll just post it. Hopefully it will do good to someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文