使用网络摄像头检测 Emgu 圆圈



>我正在尝试编写一个程序,当您将圆圈放在网络摄像头前时,它会检测到圆圈。我知道圆形检测如何对图像工作,但我无法弄清楚如何使用以下代码使其与网络摄像头流一起工作:

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方法进行圆检测


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

最新更新