Qt OpenCV addWeighted实现2张图像融合

1 篇文章 0 订阅

图像要求:尺寸大小一致

void procImg(float alpha)
{
    QString imgPath1 = "girl1.jpg";
    Mat imgSrc1 = imread(imgPath1.toLatin1().data());
    cvtColor(imgSrc1 ,imgSrc1 ,COLOR_BGR2RGB);
    
    
    QString imgPath2 = "girl2.jpg";
    Mat imgSrc2 = imread(imgPath2.toLatin1().data());
    cvtColor(imgSrc2,imgSrc2,COLOR_BGR2RGB);

    Mat imgDst;
    //根据两种原图和alpha值,用插值算法合成一张新图
    addWeighted(imgSrc2,alpha,imgSrc1,1-alpha,0,imgDst); 
    QImage img = QImage((const unsigned char*)(imgDst.data),imgDst.cols,imgDst.rows,QImage::Format_RGB888);
    imgShow(img);
}

效果图:

报错信息:

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.3) Error: Sizes of input arguments do not match (The operation is neither 'array op array' 
(where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array') 
in arithm_op, file D:\OpenCV_3.4.3-Source\modules\core\src\arithm.cpp, line 656

原因:

两幅图的size不一致

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值