opencv 叠加两张图,opencv混合(叠加)具有不同通道的两个图像

当尝试使用OpenCV的addWeighted函数叠加具有不同通道的两张图片时遇到问题。虽然OpenCV没有内置直接处理这种情况的API,但可以通过自定义代码实现。提供了一个将BGR背景和BGRA前景图层融合的函数,该函数根据透明度规则进行混合,并考虑了位置和不透明度参数。通过示例展示了如何使用该函数进行完全覆盖和50%透明度的叠加效果。
摘要由CSDN通过智能技术生成

I want to overlay two images (maybe different format (channels) with opencv. Originally I use addWeighted, however, it fails on two images with different channels. Is there any way in opencv that can handle this case? Thanks

解决方案

No, there is no API in OpenCV that offers this feature nativelly. On the other hand, there's nothing stopping you from writing your own code to do that.

A few weeks ago a made some changes to a function I saw somewhere else on the Internet to be able to:

Pass two input images: the background as BGR and the foreground as BGRA;

Blend them together according to a simple transparency rule;

(I don't remember where most of this code came from, sorry... but thank you whoever you are!)

void overlayImage(const cv::Mat &background, const cv::Mat &foreground, cv::Mat &output, cv::Point2i location, double opaci

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值