views:

18

answers:

2

Greetings!

I am working on a project using OpenCV on template matching, and I want to limit the search region on an image. Image is captured continuously from a camera.

Is there any way to Zero / mask out image outside ROI defined, so that template matching process can be specific on remaining region, faster and accurate?

Thanks is advance.

+1  A: 

Take a look at the cvSetImageROI function.

void cvSetImageROI(IplImage* image, CvRect rect)

Sets an image Region Of Interest (ROI) for a given rectangle. Parameters:

  • image – A pointer to the image header
  • rect – The ROI rectangle

If the original image ROI was NULL and the rect is not the whole image, the ROI structure is allocated.

Most OpenCV functions support the use of ROI and treat the image rectangle as a separate image. For example, all of the pixel coordinates are counted from the top-left (or bottom-left) corner of the ROI, not the original image.

This blog has some nice examples of how to use the ROI featrue.

Frank Bollack
A: 

You use cvSetImageROI to set the region of interest. The template matching functions use only the ROI you set (and ignore whatever is outside it)

Utkarsh Sinha
Thanks for the guidance. Managed to get it running. Thanks.
YS