Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the OpenCV template matching Max Min value range ? Need to be used as a theshold / c++/java

I am creating a simple openCV application using template matching where I need to compare find a small image in a big image and return the result as true(if match found) or false( no matches found).

    Imgproc.matchTemplate(largeImage, smallImage, result, matchMethod);
    Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());

    MinMaxLocResult mmr = Core.minMaxLoc(result);

    double minMaxValue = 1;
    if (matchMethod== Imgproc.TM_SQDIFF || matchMethod== Imgproc.TM_SQDIFF_NORMED)
    {
        minMaxValue = mmr.minVal;
        useMinThreshold = true;
    }
    else
    {
        minMaxValue = mmr.maxVal;
    }

Now the problem is in taking decision (true/false) using this minMaxValue. I know the above two methods TM_SQDIFF and TM_SQDIFF_NORMED returns low values while the others return high values so I can have 2 different thresholds and compare one of threshold (depending on the template method type).

So it would be great if some one can explain what is the minVal and maxVal range that the MinMaxLocResult returns.

Is it 0 to 1 range?

If yes, for Max type template method value 1 is a perfect match?

like image 619
Emily Webb Avatar asked Jul 22 '13 10:07

Emily Webb


2 Answers

MinMaxLocResult does not return minVal and maxVal range. minVal and maxVal are just minimum and maximum matching scores as can be seen in the link.

The structure MinMaxLocResult has also minLoc and maxLoc properties which are of type Point, giving the matching locations. Given that you use TM_SQDIFF or TM_SQDIFF_NORMED as a matching criterion , the best matching location will be mmr.minLoc.

In order to set a threshold for the detection, you can declare a variabledouble thresholdMatch and set its value experimentally. if minVal < thresholdMatch then it can be said that target object is detected

like image 118
fatihk Avatar answered Nov 17 '22 10:11

fatihk


Dont normalize the result, then it will give the proper value, i mean remove this line

   Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
like image 36
Mehul Thakkar Avatar answered Nov 17 '22 11:11

Mehul Thakkar