0

I am trying to match 2 images using the following matchTemplate code.

                int match_method = Imgproc.TM_CCOEFF_NORMED;
                int result_colsAB = matB.cols() - matA.cols() + 1;
                int result_rowsAB = matB.rows() - matA.rows() + 1;


                Mat resultAB = new Mat(result_rowsAB, result_colsAB, CvType.CV_8UC1);


                Imgproc.matchTemplate(matA, matB, resultAB,match_method);

                //Core.normalize(resultAB, resultAB, 0.0, 1.0, Core.NORM_MINMAX, -1, new Mat());
                 MinMaxLocResult mmr = Core.minMaxLoc(resultAB);
                System.out.println( mmr.maxVal);

It gives the expected .99 when comparing 2 filled circles as expected

But it gives a 1.0 when comparing a filled circle and a filled square of almost the same size.

what am i doing wrong? The images are in black and white.

berak
  • 39,159
  • 9
  • 91
  • 89
  • What were you expecting? – a-Jays Nov 21 '14 at 06:52
  • Its shouldnt give a 1.0...atleast something less then .99(which is the result when comparing exactly same images) – K23_avalon Nov 23 '14 at 17:04
  • I doubt the correctness of that statement. AFAIK, `matchTemplate` does a correlation, the result of which would have the largest values where the regions "match the most". It is highly possible that another region could have an appearance of a better match. – a-Jays Nov 23 '14 at 17:08
  • ok.That makes sense.i initially thought thought that it returns the most matching img...Thanks! – K23_avalon Nov 24 '14 at 19:19
  • Does your circle fit inside the square ;) ? – ed22 Jul 01 '19 at 08:32

1 Answers1

0

A perfect match should show as .99999999

If you are getting a 1.0 you are either normalizing the values after (which it doesn't look like you are)

or something else is going on.

You might want to make sure your sizing is correct (search template, results matrix etc.)

I really don't think you should get a 1.0 returned as I have tested this myself with a perfect match and my results were .9999.....

JoeCodeCreations
  • 660
  • 2
  • 6
  • 19