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

フィルタは、名前が示すとおりです。フィルタ([画像]->[プロセス]->[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;
    }

それはあなたが探しているものと正確に一致しないかもしれませんが、多分それは助けになります。

于 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 に答える