2011-09-09 14 views
1

画像上でエッジ検出を実行するためにAforgeを使用していますが、検出されたエッジポイントのx、yはどのように取得されますか?イメージビットマップをループする明白な方法以外AForge.netエッジ検出 - エッジポイントを取得する方法?

これはAforgeサンプルのコードですが、どのようにエッジポイントを取得できますか?エッジのための同様のものがある場合、私は、知らないが、AForgeは、コーナー検出器を持っている(> NEWIMAGE - - >プロセスイメージ)

フィルタ:

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

答えて

5

フィルタは、どのような名前が示しているだけです。私のサンプルはイメージをロードし、コーナー検出器を実行し、すべてのコーナーの周りに小さな赤いボックスを表示します。 ( "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

お返事ありがとうございます。実際、私は角の検出について知っていますが、エッジは私が探していたものです。 – Mikos

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

うまくいけば、これが役に立ちます。


これを入力した後、私は質問の日付を見ましたが、すでにすべてを入力した方法を見て、投稿します。うまくいけば、それは誰かに良い行います。

関連する問題