![OpenCV 4 Computer Vision Application Programming Cookbook(Fourth Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/631/36698631/b_36698631.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
Let's take a look at the following steps:
- The first step consists of defining the ROI. We can use Rect to define the ROI:
cv::Rect myRoi= cv::Rect(image.cols-logo.cols, //ROI coordinates image.rows-logo.rows, logo.cols,logo.rows)
- Once the ROI is defined, we can create a new mat applying the ROI to another mat and it can be manipulated as a regular cv::Mat instance. 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. Inserting the logo would then be accomplished as follows:
// define image ROI at image bottom-right cv::Mat imageROI(image, myRoi); // insert logo logo.copyTo(imageROI);
Here, image is the destination image, and logo is the logo image (of a smaller size). The following image is then obtained by executing the previous code:
![](https://epubservercos.yuewen.com/87DAA0/19470379101492006/epubprivate/OEBPS/Images/fe3cc663-2dad-4e76-ae1e-4ef59c6bc278.png?sign=1738883705-CKl0nV3I78c8kxQfW4q2RRtlz06rWhF5-0-d98f054305b17d101ce6bc857ebf9bd3)
Now, let's go behind the scenes to understand the code better.