Откриване на 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 в най-вътрешния цикъл, но програмата просто замръзва, когато се опитам да я стартирам, така че коментирах тази конкретна част. Може ли някой да ми каже как да внедря откриване на кръг с помощта на уеб камера?


person user1683526    schedule 19.09.2012    source източник


Отговори (1)


Можете да използвате метода 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

person Nikson Kanti Paul    schedule 24.09.2012