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

写一个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;
}

这里写图片描述

先到这里吧,拜拜~

这里写图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值