Template matching is a technique for finding small parts of an image which match a template image. It slids the template from the top left to the bottom right of the image, and compare for the best match with template. The template dimension should be equal or smaller than the reference image.
Template matching is used in various applications. Some are:
OpenCV has functions to perform template matching with several methods. I have made an example on how to perform template matching with OpenCV. Download it by clicking the download link above. The program loads a reference image and a template, find subimage in reference image that match the template, then display both images.
Send suggestion, comments and bug reports to me [at] nashruddin.com
Learning OpenCV: Computer Vision with the OpenCV Library
By: Gary Bradski, Adrian Kaehler
This book is the "de facto" OpenCV User's Manual. It provides a practical, pragmatic, accessible book on computer vision, with algorithmic explanation and concrete example code snippets. Written by the creators of OpenCV, no doubt you should obtain a copy.
Nash on Jan 28, 2009:
make to compile your project.Mahmoud on May 21, 2009:
Nash on May 22, 2009:
Mahmoud on May 23, 2009:
Madan on Jun 2, 2009:
Mahmoud on Jun 3, 2009:
Dan on Jun 15, 2009:
Steve on Jun 23, 2009:
ali on Jul 6, 2009:
Nash on Jul 7, 2009:
gcc template_matching.c -o template_matching -I"C:\OpenCV\cxcore\include" -I"C:\OpenCV\cv\include" -I"C:\OpenCV\otherlibs\highgui" -L"C:\OpenCV\lib" -lcxcore -lcv -lhighguiC:\OpenCV with the directory where you installed OpenCV. ali on Jul 7, 2009:
ali on Jul 7, 2009:
Nash on Jul 9, 2009:
vimal on Jul 14, 2009:
Paddy on Aug 6, 2009:
Nash on Aug 6, 2009:
Tõnu Samuel on Aug 7, 2009:
vinit on Aug 15, 2009:
Onkar on Aug 23, 2009:
Nash on Aug 24, 2009:
Mahmoud on Aug 28, 2009:
Nash on Aug 29, 2009:
Mahmoud on Aug 31, 2009:
Alfonso on Feb 4, 2010:
Amar Deo on Feb 26, 2010:
An on Mar 9, 2010:
imgprocess on Apr 20, 2010:
Prashant on Apr 28, 2010:
Nash on Apr 29, 2010:
Doug on May 11, 2010:
Nash on May 13, 2010:
cvMinMaxLoc(res, &minval, &maxval, &minloc, &maxloc, 0);
if (minval < THRESHOLD_VAL) {
printf("Best match found at (%d, %d)", minloc.x, minloc.y);
} else {
printf("Not found.");
} Doug on May 18, 2010:
forestman on May 21, 2010:
sneixum on Jun 3, 2010:
cvMinMaxLoc(res, &minval, &maxval, &minloc, &maxloc, 0);
if (minval < THRESHOLD_VAL) {
printf("Best match found at (%d, %d)", minloc.x, minloc.y);
} else {
printf("Not found.");
}Nash on Jun 4, 2010:
#define THRESHOLD_VAL 0.1
int main(int argc, char** argv)
{
/* ... the rest of the code ... */
} amir on Jun 5, 2010:
ProstoHam on Jun 8, 2010:
Syam on Jul 2, 2010:
| Tel. | +62 31 8662872 +62 856 338 6017 |
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |
dyana on Jan 28, 2009: