写一个ROI叠加的小例子

时间紧任务重,只能抽时间写一个ROI叠加的小例子了。主要用到了addWeight()方法,它的参数如下:

Parameters:
  src1 first input array.
  alpha weight of the first array elements.
  src2 second input array of the same size and channel number as src1.
  beta weight of the second array elements.
  gamma scalar added to each sum.
  dst output array that has the same size and number of channels as the input arrays.
  dtype optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which       will be equivalent to src1.depth().

叠加的公式是:

dst = src1*alpha + src2*beta + gamma;

代码不长:

#include <opencv2/opencv.hpp>

using namespace cv;

int main()
{

// 读入两张源图像
Mat src1 = imread("images/xn3.jpg");
imshow("小南天主教堂1", src1);

Mat src2 = imread("images/xn4.jpg");
imshow("小南天主教堂2", src2);


Mat imageROI;
imageROI = src1(Rect(0, 0, src2.cols, src2.rows)); // 定义ROI区域
addWeighted(imageROI, 0., src2, 1., 0., imageROI); // 区域叠加

imshow("叠加图", src1);
// imwrite("由imwrite生成的图片.jpg", src1);

waitKey(0);
return 0;
}

OpenCV自学笔记26. 写一个ROI叠加的小例子_#include

先到这里吧,拜拜~