Hough circles method detection on a videoFrame

asked 2013-08-17 15:03:59 -0500

william13200 gravatar image

Hi everyone, my different codes to detect circles do work well on single images but for my application i would need to apply it to a video frame (image extracted from a videoCapture). Basicly what i do is to get the video frame and simply place it where i used to have my source from a simple "imread(..)". But what happens is that after all the filtering and processing,imshow returns the normal capture, and i would like the circles to be drawn.

this is my code:

VideoCapture video(0);
Mat videoFrame;
Mat cannyOutput,imgBW;
vector<Vec4i> hierarchy;
vector<vector<Point> > contours;
vector<Moments> muCercle;
vector<Point2f> mcCercle;

if (video.isOpened() == false ){
    std::cout<<"Erreur ouverture video"<<std::endl;

while(! ( (cv::waitKey(1)) ==  'q' ) ){

    //recupere la videoFrame
    video >> videoFrame;
    /// Convert it to gray
    cvtColor( videoFrame, imgBW, CV_BGR2GRAY );
    /// Reduce the noise so we avoid false circle detection
    GaussianBlur(imgBW, imgBW, Size(9, 9), 2, 2 );

    vector<Vec3f> circles;
    /// Apply the Hough Transform to find the circles
    HoughCircles(imgBW, circles, CV_HOUGH_GRADIENT, 1, imgBW.rows/8, 200, 100, 0, 0 );

    /// Draw the circles detected
    for( size_t i = 0; i < circles.size(); i++ )
        Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
        int radius = cvRound(circles[i][2]);
        // circle center
        circle( videoFrame, center, 3, Scalar(0,255,0), -1, 8, 0 );
        // circle outline
        circle( videoFrame, center, radius, Scalar(0,0,255), 3, 8, 0 );

     /// Show your results
     namedWindow("w", CV_WINDOW_AUTOSIZE );
     imshow("w", videoFrame );
 }//tant que non stop

I tried to use more delay but it didn't change anything, it doesn't seem to be a processing problem. I also tried to put the "video >> videoFrame" (acquire the image extracted from the video) out of the infinite loop so i get a simple image and just treat it, didn't fix it either. I think i'm doing something wrong with probably: a Mat or Array being output-input in one of all these functions or probably video >> videoFrame is doing something wrong.

Any ideas?

edit retag flag offensive close merge delete