您的位置:首页 > 运维架构

OPENCV学习笔记1-7_定义感兴趣区域

2018-01-21 19:43 337 查看
  Sometimes, a processing function(处理函数) needs to be applied only to a portion(部分) of an image. OpenCV incorporates (内嵌)an elegant(精致) and simple mechanism(机制) to define a subregion(子区域) in an image and manipulate(操作) it as a regular image(普通图像).

  The key(关键在于) is that the ROI is indeed(实际上) a cv::Mat object that points to the same data buffer as its parent image(指向与父图像相同的数据缓冲区) and has a header that specifies the coordinates(指定坐标) of the ROI.

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
namedWindow("YunFung Image");
Mat image = imread("test.jpg");
Mat logo  = imread("yunfung.png");
// define image ROI at image top-right
Mat imageROI(image,    Rect(image.cols - logo.cols, 0,        // ROI coordinates
logo.cols, logo.rows));           // ROI size
// insert logo
logo.copyTo(imageROI);
// not imwrite
imshow("YunFung Image", image);
waitKey(0);
return 0;
}




 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: