OpenCV's matchTemplate tutorial code not giving expected results

asked 2017-09-16 06:49:04 -0600

lagarkane gravatar image

updated 2017-09-16 08:02:52 -0600

Hi!

I've been having troubbles with OpenCV's matchTemplate function. The probability map that I got when runnin my code didn't seem correct to me.

I decided to code a test to ensure that I would get the same behavior than opencv's binary example "cpp-tutorial-MatchTemplate_Demo" with the images given in the online tutorial (the couple in a plane).

That's when I realized that the example code doesn't give me the expected results either.. Here are some screenshots of the template matching ran with the example code and example pictures

image description

image description

image description

image description

image description

image description

I compiled OpenCV myself, after checking out the tag 3.2.0 I don't think I changed much of the cmake settings, except for WITH_QT=ON

I am recompiling with BUILD_TESTS=ON, maybe it'll bring additional information, if there's a unit test on it. I am looking forward to your input on this issue!

I'm running Arch Linux (Linux cerberus 4.12.8-2-ARCH #1 SMP PREEMPT Fri Aug 18 14:08:02 UTC 2017 x86_64 GNU/Linux)

edit retag flag offensive close merge delete

Comments

where is your code, and why do you think, the results are incorrect?

(also, it would be nice, if you could put your images here , not behind some urlshortened thing, where noone knows, where it's leading.)

berak gravatar imageberak ( 2017-09-16 07:36:40 -0600 )edit

Sorry for the pictures, they were uploaded on ImgBB. I rectified. As for the code, I didn't code anything here. My issue is directly with the Template matching demo code that is embedded in OpenCV's git repository and compiled with the sources when enabling samples in CMake. As for the pictures I used, I took them on this Opencv tutorial page. And I know that the results are incorrect since the tutorial shows completely different probability maps with the same inputs and the same code.

lagarkane gravatar imagelagarkane ( 2017-09-16 08:09:47 -0600 )edit

ok, i'm getting the same results on win. not nice.

berak gravatar imageberak ( 2017-09-16 08:20:06 -0600 )edit

I have a colleague who told me he doesn't have this problem. I'll write down here his version of opencv, linux, and compile options as soon as he answers. In the meantime, I checked out 3.1.0 and got the same issue. I updated master and recompiled, and again, same issue... :/

lagarkane gravatar imagelagarkane ( 2017-09-16 09:06:52 -0600 )edit
berak gravatar imageberak ( 2017-09-16 09:35:19 -0600 )edit

It looks like TM_CCORR is wrong too. And that eliminates a lot of the possible errors, since it only uses the crossCorr function, and not the common_matchTemplate.

Tetragramm gravatar imageTetragramm ( 2017-09-16 14:22:09 -0600 )edit

Hmm, the only change I see it the HAL DFT.

EDIT: Nope, that's not it. So maybe I just picked a bad image to test? SQDIFF works, and the others fail...

EDIT2: I just tested a whole bunch of images and SQDIFF is the only one that works. CCORR and CCOEFF both fail every time.

Tetragramm gravatar imageTetragramm ( 2017-09-16 14:45:57 -0600 )edit

I don't have the issue on ubuntu 17.04 with opencv 3.0.0. Though, on Arch linux, with the same version (git checkout 3.0.0) I get the same problem. I compiled with the same version of gcc (5.4), with the same cmake options... For me none of the method succeed (SQDIFF / CCOEF / CCORR..)

lagarkane gravatar imagelagarkane ( 2017-09-18 12:44:51 -0600 )edit

Have you tried with openCL and IPP turned off?

Tetragramm gravatar imageTetragramm ( 2017-09-18 17:37:12 -0600 )edit

IPP OFF ; OpenCL OFF -> same result.. :(

lagarkane gravatar imagelagarkane ( 2017-09-19 03:43:49 -0600 )edit