Template matching is used in order to find a smaller image (called template) in a bigger image. The tag must be used only for queries related to such tasks.
Questions tagged [matchtemplate]
53 questions
14
votes
3 answers
Using opencv matchtemplate for blister pack inspection
I am doing a project in which I have to inspect pharmaceutical blister pack for missing tablets.
I am trying to use opencv's matchTemplate function. Let me show the code and then some results.
int match(string filename, string templatename)
{
…

vuanhtung2004
- 171
- 1
- 1
- 7
12
votes
2 answers
emgu finding image a in image b
I'm new to emgu and would like some advice on where to start.
I've looked through the shape detection but its far too complex for what i need .. i think.. and my surfexample isn't working. I get this error:
Cannot get SURF example in EMGU.CV to…

user2078674
- 165
- 2
- 2
- 14
10
votes
3 answers
How to interpret matchtemplate output? (openCV, Python)
After reading the docs and searching all over the internet I still do not understand how to interpret the output of the matchTemplate function from openCV.
What I understand:
result = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
I…

DonDonald
- 101
- 1
- 5
10
votes
1 answer
Explaing Cross Correlation and Normalization for openCV's Match Template
My boss and I disagree as to what is going on with the CV_TM_CCORR_NORMED method for matchTemplate(); in openCV.
Can you please explain what is happening here especially the square root aspect of this equation.

JoeCodeCreations
- 660
- 2
- 6
- 19
8
votes
1 answer
How to know if matchTemplate found an object or not?
I used this answer and wrote my own program, but I have a specific problem.
If the image does not have the object, matchTemplate does not throw an error, and I do not know of any method to check if matchTemplate found the object or not, can anyone…

haykart
- 957
- 5
- 14
- 34
7
votes
4 answers
python opencv cv2 matchTemplate with transparency
OpenCV 3.0.0 added the ability to specify a mask while performing templateMatch. When I specify a mask I get this error: error: (-215) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function…

jaredrada
- 1,130
- 3
- 12
- 25
5
votes
1 answer
What method is used in opencv matchtemplate source code to process color images?
The documentation of opencv matchtemplate says that
In case of a color image, template summation in the numerator and each sum in the denominator is done over all of the channels and separate mean values are used for each channel. That is, the…

sunyy5
- 53
- 5
4
votes
0 answers
python OpenCV matchtemplate for same shapes different colors
I tried to matchtemplate using OpenCV2.
This is the template and the screen I'm searching in:
This is the code i used to match template:
import cv2
import numpy as np
img_bgr = cv2.imread("screen.png")
img_gray =…

Khaled AlSufyani
- 41
- 2
3
votes
2 answers
OpenCV template Matching result is black
I got the following code to find the template in the source image:
private void button1_Click(object sender, EventArgs e)
{
toggleStatus();
using (Mat template = CvInvoke.Imread("C:\\Users\\Hendr\\Desktop\\temp.png",…

0x45
- 779
- 3
- 7
- 26
3
votes
2 answers
Java implementation of Opencv (3.0.0) template matching
I want to match a template (small image) in a given picture using Opencv.
I found the following code from this port: OpenCV Template Matching example in Android
The problem is starting openvc 3.0.0, highgui is broken down into new videoio and…

kartik
- 293
- 4
- 9
3
votes
1 answer
Opencv matchTemplate not matching
I'm using OpenCV 3.0.0 to locate an image into another image. A priori the function matchTemplate is what i need to use, but seeing the results i am not sure anymore.
The problem is that depending on the input images, the result is perfectly…

Miguel Cantó Bataller
- 480
- 2
- 10
- 25
3
votes
1 answer
OpenCV GPU ( CUDA ) Template matching and FFT implementation
I am using opencv GPU::matchTemplate() on GTX690.
I checked the function internally and found that gpu::matchTemplate() is not using any FFT in the process, while its CPU counterpart does.
My question is, what is the reason behind not using FFT in…

Sajad Karim
- 321
- 3
- 18
2
votes
0 answers
OpenCV template matching in multiple ROIs
I'm new to opencv so sorry if this question seems stupid.
I would like to find marker #1 for example in my image detect marker. I have limited my search area to multiple ROIs (squares) then I cropped my image to the ROIs and transformed it using…

A.Ul
- 21
- 1
2
votes
2 answers
JavaCV Create Mat from Resource (InputStream)
I use JavaCV (not OpenCV). My goal is to obtain a Mat object from an image that is stored as a Resource. Then I'm going to pass this Mat into opencv_imgproc.matchTemplate method. I've managed to write this bad code:
InputStream in =…

al0
- 374
- 1
- 7
- 20
2
votes
1 answer
Success of template-matching with opencv
How do I measure success of the opencv template-matching algorithm ?
I understand that the minmaxLoc function can be used to find the location of the best match. But does it also give an indication on how good the match actually was ? (If yes, how…

iKK
- 6,394
- 10
- 58
- 131