Ask Your Question
0

Template Matching - Need to match a template image with the source image where source image input is from webcam

asked 2015-06-23 03:26:43 -0600

Manimaran gravatar image

updated 2015-06-26 12:14:17 -0600

pklab gravatar image

Hi, I am new to OpenCV. I am working on Image processing task where I need to match template image with the source image where source image is the input from webcam. I have written code for offline template matching and I dont know to proceed for online scenario. Could someone please help me to complete this task.

Thanks, Manimaran

edit retag flag offensive close merge delete

Comments

1
thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-06-23 03:35:35 -0600 )edit

Hi, with the help of the link you posted ,I have written code for offline scenario. Currently I am working on Online scenarios which means I'm getting input from the webcam for the source image and matching with the template image which is offline one. Please help me on this.Thanks

Manimaran gravatar imageManimaran ( 2015-06-23 03:44:21 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-06-26 12:13:16 -0600

pklab gravatar image

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;
}
edit flag offensive delete link more

Comments

1

if you draw something to frame

for(;;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera

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

    imshow("Video", frame); 
    if(waitKey(30) >= 0) break;   //press a key to stop the loop
}
sturkmen gravatar imagesturkmen ( 2015-06-26 12:42:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-23 03:26:43 -0600

Seen: 1,046 times

Last updated: Jun 26 '15