matchTemplate Resultspace Padding
Hello everyone,
in the matchTemplate function there is a picture illustrating the slinding-window-approach (the one with the two black arrows).
First of all: as I understand the code, the coordinates in this pictures are not right, are they?
I came to this assumption, because the result-variable contains the match between left upper corner from template with left upper corner from queryimage (not the center of template with left upper corner from query as shown in the picture).
If this is correct it means that the whole template has to fit on the searchimage. A situation as shown (half dogs had correlate to nothing) is not possible.
Could someone confirm this assumption, please?
edit:
see @berak 's post.
I also did an example with should explain the situation: see the pictures below where I used berak's suggested cv::copyMakeBorder.
This solution leads me to the following Question: What kind of borders seems to be the more general sultion? A black or a borderInterpolate?
I also worked with the matlab version of the normalized cross-correlation normxcorr2. In this function the result space is in the dimensions of (rows.template + rows.query +1) x (cols.template + cols.query +1).
Can you give me a hint, if or how such an output is possible as well with openCV? could adding a black border do the trick? -> it does see the pictures
result_cols = img.cols - templ.cols + 1;
(- , not +, same for rows)Thank you, berak. The dimension you mentioned are for opencv, i was referring to the matlab implementation. Is the result i am trying to get clear?
why would that differ ? (unless they're padding) also, where does it say so ?you could use copyMakeBorder for the padding
Which flags do you use for matchTemplate ?
At the moment i work with CV_TM_SQDIFF_NORMED
I think you should use an image an a template with zero means
@LBerger, I am sorry, but I don't really understand what you mean by "template with zero means". Is it a constant black border around the image, or something I have do do with the template?
Before processing a signal x, we offen transform it in xe such that : xe = x - mean(x)