1

我正在尝试编写一个程序,当您将它放在网络摄像头前时检测一个圆圈。我知道圆形检测如何用于图像,但我不知道如何使用以下代码使其与网络摄像头流一起使用:

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,但是当我尝试运行它时程序只是冻结了,所以我注释掉了那个特定的部分。谁能告诉我如何使用网络摄像头实现圆圈检测?

4

1 回答 1

0

您可以使用HoughCircleMethod 进行圆形检测


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

于 2012-09-24T05:38:43.330 回答