visual c++ - OpenCV MatchTemplate limited to roi -
my question related use of matchtemplate in opencv. i'm able use function find template within whole image. possible limit "searching area" restricted region within image, i.e. using roi? tried set roi before calling matchtemplate didn't have effect.
so, know way limit search of template subregion of image? because know target can found in limited region.
here line of code taken directly opencv samples:
void matchingmethod( int, void* ) { // source image display mat img_display; img.copyto( img_display ); // create result matrix int result_cols = img.cols - templ.cols + 1; int result_rows = img.rows - templ.rows + 1; result.create( result_cols, result_rows, cv_32fc1 ); // matching , normalize img.adjustroi(100, 100, 500, 500); matchtemplate( img, templ, result, match_method ); normalize( result, result, 0, 1, norm_minmax, -1, mat() ); // localizing best match minmaxloc double minval; double maxval; point minloc; point maxloc; point matchloc; minmaxloc( result, &minval, &maxval, &minloc, &maxloc, mat() ); // sqdiff , sqdiff_normed, best matches lower values. other methods, higher better if( match_method == cv_tm_sqdiff || match_method == cv_tm_sqdiff_normed ) { matchloc = minloc; } else { matchloc = maxloc; } // show me 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 ); imshow( image_window, img_display ); imshow( result_window, result ); }
sure !
rect roi( x,y,w,h ); matchtemplate( img( roi ), templ, result, method );
Comments
Post a Comment