AForge.net обнаружение краев - как получить краевые точки? - PullRequest
1 голос
/ 09 сентября 2011

Я использую 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;
            }

Ответы [ 2 ]

6 голосов
/ 09 сентября 2011

Фильтры - это просто то, что предлагает название: Фильтры (Изображение -> Процесс -> 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;
    }

Возможно, это не совсем то, что вы ищете, но, возможно, это поможет.

0 голосов
/ 25 ноября 2013

Являются ли края, которые вы хотите обнаружить по определенной форме?Потому что, если это так, вы можете использовать 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);
    }
}

Надеюсь, это поможет.


После ввода этого я видел вопросы "дата, но видя, как я уже все набрал, я просто опубликую.Надеюсь, это будет кому-то полезно.

...