From 88cb33a1dce12ab6ae847dd417effc00d6954688 Mon Sep 17 00:00:00 2001 From: William Manley Date: Wed, 20 Jun 2012 15:22:52 +0100 Subject: [PATCH] templatematch: Match rectangle grows redder with increased match certainty This is useful for debugging your matches as it indicates how certain the match was in addition to its position. --- ext/opencv/gsttemplatematch.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ext/opencv/gsttemplatematch.c b/ext/opencv/gsttemplatematch.c index 7123bdbf27..36163e02fa 100644 --- a/ext/opencv/gsttemplatematch.c +++ b/ext/opencv/gsttemplatematch.c @@ -370,13 +370,23 @@ gst_template_match_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) if (filter->display) { CvPoint corner = best_pos; + CvScalar color; + if (filter->method == CV_TM_SQDIFF_NORMED + || filter->method == CV_TM_CCORR_NORMED + || filter->method == CV_TM_CCOEFF_NORMED) { + /* Yellow growing redder as match certainty approaches 1.0. This can + only be applied with method == *_NORMED as the other match methods + aren't normalized to be in range 0.0 - 1.0 */ + color = CV_RGB (255, 255 - pow (255, best_res), 32); + } else { + color = CV_RGB (255, 32, 32); + } buf = gst_buffer_make_writable (buf); corner.x += filter->cvTemplateImage->width; corner.y += filter->cvTemplateImage->height; - cvRectangle (filter->cvImage, best_pos, corner, CV_RGB (255, 32, 32), 3, - 8, 0); + cvRectangle (filter->cvImage, best_pos, corner, color, 3, 8, 0); } }