opencv(Python与c++双实现)随笔记录:4.ROI(感兴趣区域)及图像混合

ROI为region of interest,即感兴趣区域

先上效果图(将icon 混合到dog图 上)
opencv(Python与c++双实现)随笔记录:4.ROI(感兴趣区域)及图像混合

1.c++实现部分

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <math.h>
using namespace std;
using namespace cv;
// mix fig: extract the ROI of fig1 into fig 2
int main(int argc, char *argv[])
{
    Mat image=imread("/home/liuxin/dog.jpeg");
    Mat icon=imread("/home/liuxin/icon.jpeg");
    imshow("original fig ",image);
    //ROI的起点以及icon的大小,方便将icon拷贝到指定位置
    Mat ROIimage=image(Rect(30,40,icon.cols,icon.rows));
    //注意此处的ROI仍在image上
    imshow("ROI image ",ROIimage);
    // depict the rectangle
    //rectangle(image,Rect(0,0,200,200),Scalar(0,255,0),2);// 0,0 it's the point of rectangle.
    //define Mat and restore the ROI of image   (ROI:region of interest)
    //image(Rect(0,0,200,200)).copyTo(ROIimage);//copy
    //1. ROI  specific coordinate and width and height

    //imageROI(Range(10,10+image2.rows),Range(100,100+image2.cols));
    //add image2 to image
    //image上被确定的ROIimage不透明为0.1,icon在此处的为0.9.依旧在image上操作
    addWeighted(ROIimage,0.1,icon,0.9,0.,ROIimage);

    //display
    imshow("mixed figure ",image);

    waitKey();
    return 0;


}

2.Python实现部分

待写