2011-09-09 238 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); 
    } 
} 

希望这会有所帮助。


打完这个后,我看到了问题的日期,但看到我已经输入了所有的东西,我只是发布它。希望它会对某人有好处。