图像 ROI

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

  1. /* load image */
  2. IplImage *img1 = cvLoadImage ( "elvita.jpg" , 1 ) ;
  3. /* sets the Region of Interest
  4.    Note that the rectangle area has to be __INSIDE__ the image */
  5. cvSetImageROI (img1 , cvRect ( 10 , 15 , 150 , 250 ) ) ;
  6. /* create destination image
  7.    Note that cvGetSize will return the width and the height of ROI */
  8. IplImage *img2 = cvCreateImage (cvGetSize (img1 ) ,
  9.                                img1 ->depth ,
  10.                                img1 ->nChannels ) ;
  11. /* copy subimage */
  12. cvCopy (img1 , i
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值