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

잘하면이 도움이됩니다.


이 질문을 입력 한 후에 나는 질문의 날짜를 보았지만 이미 입력 한 모든 내용을 입력 한 것처럼 보입니다. 바라건대 누군가에게 도움이되기를 바랍니다.

관련 문제