Mask / Zero out area outside specified ROI

孤街浪徒 提交于 2019-12-23 05:11:58

问题


I'm 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?


回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/3361916/mask-zero-out-area-outside-specified-roi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!