2011-09-09 286 views
1

我正在使用Aforge在圖像上運行邊緣檢測,如何獲取檢測到的邊緣點的x,y?除了循環顯示圖像位圖的明顯方式之外。AForge.net邊緣檢測 - 如何獲得邊緣點?

這是來自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; 
      } 

回答

5

過濾器僅僅是什麼顧名思義:過濾器(圖片 - >流程 - > 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

感謝您的回覆。事實上,我知道角落探測,但是我正在尋找邊緣。 – 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); 
    } 
} 

希望這會有所幫助。


打完這個後,我看到了問題的日期,但看到我已經輸入了所有的東西,我只是發佈它。希望它會對某人有好處。