2012-09-19 1 views
1

웹캠 앞에서 원을 감지하면 해당 원을 감지하는 프로그램을 작성하려고합니다. 나는 원 감지 이미지 작동 방법을 알고,하지만 난 다음 코드를 사용하여 웹캠 스트림과 작동하도록하는 방법을 알아낼 수 없습니다 : 당신은 내가 사용하려고했습니다 볼 수 있듯이웹캠을 사용한 Emgu circle 검색

static class Program 
{ 
    /// <summary> 
    /// The main entry point for the application. 
    /// </summary> 
    [STAThread] 
    static void Main() 
    { 
     ImageViewer viewer = new ImageViewer(); //create an image viewer 
     Capture capture = new Capture(); //create a camera capture 
     Application.Idle += new EventHandler(delegate(object sender, EventArgs e) 
     { //run this until application closed (close button click on image viewer) 
      Image<Bgr, Byte> image = capture.QueryFrame(); 
      //MemStorage storage = new MemStorage(); 
      //Contour<Point> contours = image.FindContours(); 
      //Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage); 
      viewer.Image = image; //draw the image obtained from camera 
     }); 
     viewer.ShowDialog(); //show the image viewer 
} 

을 가장 안쪽 루프에서 FindContours를 실행하지만 프로그램을 실행하면 프로그램이 멈추어 특정 부분을 주석 처리했습니다. 누구든지 웹캠을 사용하여 원 감지 기능을 구현하는 방법을 알려 줄 수 있습니까?

당신은 원 검출 HoughCircle 방법을 사용할 수 있습니다

답변

0


Image gray = img.Convert().PyrDown().PyrUp(); 

Gray cannyThreshold = new Gray(180); 
Gray cannyThresholdLinking = new Gray(120); 
Gray circleAccumulatorThreshold = new Gray(120); 

CircleF[] circles = gray.HoughCircles(
    cannyThreshold, 
    circleAccumulatorThreshold, 
    5.0, //Resolution of the accumulator used to detect centers of the circles 
    10.0, //min distance 
    5, //min radius 
    0 //max radius 
    )[0]; //Get the circles from the first channel 

참조 방법 HoughCircle