Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You have to create a grabbing loop where to call your offline function for each frame:

#include "opencv2/opencv.hpp"
using namespace cv;


//  If your code changes the frame you have to remove const specs
void YourOfflineTemplateMatching(const Mat & frame)
{
   your code here
}


int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
    {
        printf("\nUnable to open the default camera\n");
        return -1;
    }

    namedWindow("Video",1);
    //the grab loop
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        imshow("Video", frame);

        YourOfflineTemplateMatching(frame);  // call your code for each frame

        if(waitKey(30) >= 0) break;   //press a key to stop the loop
    }

    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}