frame coherence in feature detection

asked 2014-03-22 20:18:00 -0500

koshy george gravatar image

updated 2014-03-22 22:04:01 -0500

Summary:

Given an input video steam, how to we solve the problem of features not getting detected intermittently. One can possibly do a more robust feature detection. But if the input video stream is noisy or ill-illuminated, then even robust feature detection can cause intermittent failures in feature detection from frame to frame. Is there a general method where by we use the previous frame's features if detection fails for a frame? Could somebody please point me to the general direction (theory and practice) of solving this?

Specific case:

We are trying to detect a big circular object in the video stream using the code below. We employ HoughCircle-s. The code is given below. The output green circle flickers from frame to frame.

image description

   int main(int argc, char **argv) {
       VideoCapture cap(0);
       namedWindow( "video");
       bool firstWrite = true;
       for(;;) {
           Mat frame;
           cap >> frame;
           if( frame.empty() )
               break;
           Mat image, tempImage, grayImage;
           cvtColor(frame, tempImage, CV_BGR2GRAY);
           pyrDown(tempImage, grayImage, Size(frame.cols/2, frame.rows/2));
           pyrDown(frame, image, Size(frame.cols/2, frame.rows/2));
           vector<Vec3f> circles;
           HoughCircles(
               grayImage,        //input image
               circles,               //output circles
               CV_HOUGH_GRADIENT,
               1,                      //
               grayImage.rows/8,  //
               250,                        //upperThresholdForInternalCannyEdgeDetect
               50,                          //thresholdForCenterDetect
               0,                          //minRadius
               100                           //maxRadius, 
           );
           if(circles.size()>0) {
               //draw only the first circle
               Point circlePoint(  round(circles[0][0]), round(circles[0][1]));
               double circleRadius = circles[0][2];
               circle( image, circlePoint, circleRadius,  Scalar(0, 255, 0), -1, 8, 0);
               if(firstWrite) {
                   //write only one-time
                   imwrite(
                    "detected.jpg",
                    image
                   );
                   firstWrite = false;
               }
           }
           imshow("video", image);
       }
 }
edit retag flag offensive close merge delete