1

checking simple mask applications:

im1=cv.imread('test.png')
im2=cv.imread('test2.png')
mask=cv.imread('mask.png')

res1=cv.matchTemplate(im1,im1,cv.TM_SQDIFF)
res2=cv.matchTemplate(im2,im1,cv.TM_SQDIFF)

res1m=cv.matchTemplate(im1,im1,cv.TM_SQDIFF,mask)
res2m=cv.matchTemplate(im2,im1,cv.TM_SQDIFF,mask)

But as a result i always get the same. Here are my images: https://i.stack.imgur.com/3LCoz.jpg

What's the problem? I should get the same res1m and res2m,due to formula:

SUM[W(x,y)*(I(x,y)-T(x,y))^2],W-mask,I-image,T-template

F1res
  • 118
  • 2
  • 9
  • not sure what you are trying to do, but `matchTemplate` returns comparison results from which you have to find the point of maximum and then crop your input image based on that point's location and the size of template. Have a look at this tutorial for a complete reference: https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html – tkhurana96 Jan 28 '18 at 12:59
  • yes,but i have only one result coz images are same size – F1res Jan 28 '18 at 13:08
  • can you elaborate on " i have only one result coz images are same size" and it would be helpful if you upload the images for `res1`, `res2`, `res1m` and `res2m` – tkhurana96 Jan 28 '18 at 13:13
  • https://imgur.com/a/75QUA as you can see,there is no difference using mask – F1res Jan 28 '18 at 13:20
  • 2
    because as stated in the docs here: https://docs.opencv.org/2.4/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#matchtemplate , the `matchTemplate` function takes the 4th argument as the `result` matrix which it fills with the result values in, as written in the docs: `result – Map of comparison results` – tkhurana96 Jan 28 '18 at 13:29
  • Thank you! Now its working propperly – F1res Jan 28 '18 at 13:46
  • glad it helped you – tkhurana96 Jan 28 '18 at 13:47

1 Answers1

1

Solved: res1m=cv.matchTemplate(im2,im1,cv.TM_SQDIFF,mask=mask)

F1res
  • 118
  • 2
  • 9