我正在尝试编写一个程序,当您将其保持在网络摄像头前时检测到该圆圈。我知道圆形检测如何用于图像,但我无法弄清楚如何使用以下代码使其与网络摄像头流一起使用:
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但程序只是在我尝试运行时冻结,所以我评论了特定的部分。谁能告诉我如何使用网络摄像头实现圆圈检测?
答案 0 :(得分:0)
您可以使用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