200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > opencv将透明PNG图片填充为白色背景

opencv将透明PNG图片填充为白色背景

时间:2022-06-02 17:15:10

相关推荐

opencv将透明PNG图片填充为白色背景

本篇博客介绍使用两种方式来实现将透明PNG图片填充为白色背景。

第一种方法:

代码:

#include<opencv2/imgproc/imgproc.hpp>#include<opencv2/highgui/highgui.hpp>using namespace cv;int i, j;Mat overlayImage(const Mat &background, const Mat &foreground){Mat output;background.copyTo(output);for (int y = std::max(0, 0); y < background.rows; ++y){int fY = y - 0; if (fY >= foreground.rows)break;for (int x = std::max(0, 0); x < background.cols; ++x){int fX = x - 0; if (fX >= foreground.cols)break;double opacity =((double)foreground.data[fY * foreground.step + fX * foreground.channels() + 3])/ 255.;for (int c = 0; opacity > 0 && c < output.channels(); ++c){uns

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。