Ask Your Question

Revision history [back]

Instead of finding it on a single image, you have to find the contours on all the frames on the video. What you're in main() in the second program has to be done in a loop. This will be the main function:

int main()
{
    VideoCapture cap(*path to your video file or 0/1 for webcam video*);

    for(;;)
    {
        /// Load source image and convert it to gray
        cap >> src;

        /// Convert image to gray and blur it
        cvtColor(src, src_gray, CV_BGR2GRAY);
        blur(src_gray, src_gray, Size(3, 3));

        /// Create Window
        char* source_window = "Source";
        namedWindow(source_window, CV_WINDOW_AUTOSIZE);
        imshow(source_window, src);

        createTrackbar(" Threshold:", "Source", &thresh, max_thresh, thresh_callback);
        thresh_callback(0, 0);

        if (waitKey(27) >= 0)
            break;
    }
    return(0);
}

Instead of finding it on a single image, you have to find the contours on all the frames on the video. What you're you've done in main() in the second program has to be done in a loop. This will be the main function:

int main()
{
    VideoCapture cap(*path to your video file or 0/1 for webcam video*);

    for(;;)
    {
        /// Load source image and convert it to gray
        cap >> src;

        /// Convert image to gray and blur it
        cvtColor(src, src_gray, CV_BGR2GRAY);
        blur(src_gray, src_gray, Size(3, 3));

        /// Create Window
        char* source_window = "Source";
        namedWindow(source_window, CV_WINDOW_AUTOSIZE);
        imshow(source_window, src);

        createTrackbar(" Threshold:", "Source", &thresh, max_thresh, thresh_callback);
        thresh_callback(0, 0);

        if (waitKey(27) >= 0)
            break;
    }
    return(0);
}