Question

I have a program that should do template matching on an image and a template, here is the code :

 int main()
{
   IplImage* imgOriginal = cvLoadImage("image.jpg", 0);
   IplImage* imgTemplate = cvLoadImage("template.jpg", 0);
   IplImage* imgResult = cvCreateImage(cvSize(imgOriginal->width-imgTemplate->width+1, imgOriginal->height-imgTemplate->height+1), IPL_DEPTH_32F, 1);
   cvZero(imgResult);
   cvMatchTemplate(imgOriginal, imgTemplate, imgResult, CV_TM_CCORR_NORMED);
   double min_val=0, max_val=0;
   CvPoint min_loc, max_loc;
   cvMinMaxLoc(imgResult, &min_val, &max_val, &min_loc, &max_loc);
   cvRectangle(imgOriginal, max_loc, cvPoint(max_loc.x+imgTemplate->width, max_loc.y+imgTemplate->height), cvScalar(0), 1);
   printf("%f", max_val);
   cvNamedWindow("result");
       cvShowImage("result", imgOriginal);
       cvWaitKey(0);
       return 0;
}

include files :

    #include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include "stdio.h"

using namespace cv;
using namespace std;

When I run the code, I get this error :

templateMatching.cpp:16:75: error: ‘cvMatchTemplate’ was not declared in this scope

Any idea what the problem is? Thanks in advance, Matt

Was it helpful?

Solution

You need include

#include "opencv2/imgproc/imgproc_c.h"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top