templatematchcv

Finds a template within an image and returns the handle to an output image highlighting the match and the position of the match.

Syntax

[R, pos] = templatematchcv(src, tpl, method, color)

[R, pos] = templatematchcv(src, tpl, method, color, thickness)

Inputs

handle
Handle of an image.
Type: integer
tpl
Handle of the template to match. The size of the template image must be lesser than src.
Type: integer
method
Method used for template matching. Valid values are:
0
Open cv value cv::TM_SQDIFF.
1
Open cv value cv::TM_SQDIFF_NORMED.
2
Open cv value cv::TM_CCORR.
3
Open cv value cv::TM_CCORR_NORMED.
4
Open cv value cv::TM_CCOEFF.
5
Open cv value cv::TM_CCOEFF_NORMED.
Type: integer
color
Three-element vector of integers representing red, green, blue (RGB) colors used on R.
Type: vector
thickness
Optional parameter specifying the thickness of the rectangle drawn. Default value of thickness is 1.
Type: integer

Outputs

R
Handle of the output image showing the match.
Type: integer
pos
Two-element vector representing the x,y coordinates of the match.
Type: vector

Example

Show an output image with the matched template:

src = imreadcv('cv1.jpg');
tpl = cropcv(src, [100 200 300 500]);
[R, pos] = templatematchcv(src, tpl, 0, [0, 0, 135], 4);


Figure 1. Input image


Figure 2. Output image
Identify the position of the Altair logo in the Altair website snippet:
src = imreadcv('AltairWebsite.png');
tpl = imreadcv('AltairLogo.png');
[R, pos] = templatematchcv(src, tpl, 0, [0, 0, 135], 4);
imshowcv(R);


Figure 3. Altair website snippet


Figure 4. Altair logo


Figure 5. Output of template matchin