Region of Interest is a rectangular area in an image, to segment object for further processing. The ilustration is shown in Figure 1 below.
Fig 1. An image with Region of Interest defined
In the image above, a Region of Interest is defined at near top left of the image. Once the ROI defined, most OpenCV functions will performed only on that particular location. This is useful, for example when we want to crop an object from an image, or when we want to perform template matching within subimage. Note that the Region of Interest has to be inside the image.
To define Region of Interest, use the function:
cvSetImageROI( IplImage* img, CvRect rect )
Where img is the source image and rect is the area within the source image. To reset Region of Interest, use the function:
cvResetImageROI( IplImage* img )
Below are some samples where ROI is useful.
1. Crop an Object
Listing 1: Crop an object and save to new image
-
/* load image */
-
IplImage *img1 = cvLoadImage ( "elvita.jpg" , 1 ) ;
-
/* sets the Region of Interest
-
Note that the rectangle area has to be __INSIDE__ the image */
-
cvSetImageROI (img1 , cvRect ( 10 , 15 , 150 , 250 ) ) ;
-
/* create destination image
-
Note that cvGetSize will return the width and the height of ROI */
-
IplImage *img2 = cvCreateImage (cvGetSize (img1 ) ,
-
img1 ->depth ,
-
img1 ->nChannels ) ;
-
/* copy subimage */
-
cvCopy (img1 , i

图像的Region of Interest (ROI) 是一个用于进一步处理的矩形区域。在定义ROI后,大多数OpenCV函数只在此区域内操作,如裁剪对象、不同尺寸图像相加或在特定区域进行模板匹配。定义ROI使用`cvSetImageROI`函数,重置则用`cvResetImageROI`。示例包括:1) 裁剪对象,2) 不同尺寸图像相加,3) 模板匹配。在模板匹配中,ROI可以提高计算速度。
最低0.47元/天 解锁文章
1944

被折叠的 条评论
为什么被折叠?



