Ask Your Question
1

Template matching results from basic SQDIFF method

asked 2015-12-22 01:23:21 -0600

jummijammi gravatar image

The provided template matching documentation (/template_matching.html) gives the formulae for the different template matching methods. I needed a simple template matching calculation in my Java code and including OpenCV in my Java app just for a simple evaluation would be overkill.

So, using the formula (a) in the template matching documentation I programmed my own function to calculate the squared difference from two equal sized images. I see the calculation very straight forward, but when comparing the numerical values from my Java code and OpenCV, I get slightly different results. For example, from comparing two grayscale png images of resolution 1366x768 I got a SQDIFF value 751601095 from my Java code and OpenCV gave me 1645311360, which is just over two times bigger value. I loaded the image in OpenCV using CV_LOAD_IMAGE_UNCHANGED and used CV_8U when creating the result matrix.

The funniest thing is, that when comparing two exactly same images (copies of each other), my own implementation gives 0 (as expected), but OpenCV gives a squared difference of 3020. This makes me doubt about what tricks is OpenCV actually doing in the template maching process.

So, any ideas what would explain the difference in the results and the OpenCV faulty value with two equal images?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-21 10:50:32 -0600

glumb gravatar image

I have a similar problem with CV_TM_SQDIFF since using OpenCV 3.1. It worked fine for me in 2.4.5 as long, as I didn't specify the type (imread) when loading the grayscaled template and image to be searched in. If I specify the type when loading, I even get negative values for both versions on some test cases. After all, the locations seem to be correct...

Could you resolve the issue or may there be some bugs in OpenCV involved?

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-12-22 01:23:21 -0600

Seen: 563 times

Last updated: Dec 22 '15