Ask Your Question

Revision history [back]

Hi Deniz!

You can use the MinVal, MaxVal from the template matching output to threshold the match score. Refer this example. In this example you can see the minMaxLoc().

int threshold = 0.75;
if (maxval >= threshold)
{
  /// Show me what you got
  rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );
  rectangle( result, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );   
}

Note that based on the Template matching type you use the limit will vary. e.g for CV_TM_SQDIFF & CV_TM_SQDIFF_NORMED take min value. since more the correlation in both image less the match value. And for others take MaxVal since more the correlation match value will be more ranges from 0-1. I think you can implement the same in java too.

Also .Gif are not supported in opencv.

These are the formats supported by opencv.

    Windows bitmaps - *.bmp, *.dib (always supported)
    JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
    JPEG 2000 files - *.jp2 (see the Notes section)
    Portable Network Graphics - *.png (see the Notes section)
    Portable image format - *.pbm, *.pgm, *.ppm (always supported)
    Sun rasters - *.sr, *.ras (always supported)
    TIFF files - *.tiff, *.tif (see the Notes section)
click to hide/show revision 2
Corrected Puntuation

Hi Deniz!

You can use the MinVal, MaxVal from the template matching output to threshold the match score. Refer this example. In this example you can see the minMaxLoc().

int threshold = 0.75;
if (maxval >= threshold)
{
  /// Show me what you got
  rectangle( img_display, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );
  rectangle( result, matchLoc, Point( matchLoc.x + templ.cols , matchLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );   
}

Note that based on the Template matching type you use the limit will vary.

e.g for CV_TM_SQDIFF & CV_TM_SQDIFF_NORMED take min value. since more the correlation in both image image, less the match value. And for others take MaxVal MaxVal. since more the correlation correlation, match value will be more ranges from 0-1. I think you can implement the same in java too.

Also .Gif are not supported in opencv.

These are the formats supported by opencv.

    Windows bitmaps - *.bmp, *.dib (always supported)
    JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
    JPEG 2000 files - *.jp2 (see the Notes section)
    Portable Network Graphics - *.png (see the Notes section)
    Portable image format - *.pbm, *.pgm, *.ppm (always supported)
    Sun rasters - *.sr, *.ras (always supported)
    TIFF files - *.tiff, *.tif (see the Notes section)