当前位置:网站首页>水印图像读取与制作,三通道图转为4通道,制作透明图
水印图像读取与制作,三通道图转为4通道,制作透明图
2022-08-08 17:51:00 【AI算法联盟】
def watermark_handle(watermark_path):
'''
水印图像读取与制作,三通道图转为4通道,制作透明图
:param watermark_path: 水印图像路径
:return: 图像数据,图像高度,图像宽度
'''
im = cv2.imread(watermark_path)
h, w = im.shape[:2]
# 转换为灰度图
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# 像素翻转
thresh = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY_INV)[1]
img = np.stack((thresh,) * 3, axis=-1)
image = np.dstack([img, np.ones((h, w), dtype="uint8") * 255])
return image, h, w
def watermark_merge(frame, watermark, xmin, ymin):
frame_h, frame_w = frame.shape[:2]
wm_h, wm_w = watermark.shape[:2]
# 转为四通道图像数据
im = np.dstack([frame, np.ones((frame_h, frame_w), dtype="uint8") * 255])
overlay = np.zeros((frame_h, frame_w, 4), dtype="uint8")
overlay[ymin:ymin + wm_h, xmin:xmin+wm_w] = watermark
alpha = 0.25
cv2.addWeighted(overlay, alpha, im, 1.0, 0, im)
return im
边栏推荐
猜你喜欢
DSPE-PEG-FITC,Fluorescein-PEG-DSPE,修饰性PEG磷脂-聚乙二醇-荧光素
CF696C(计数推公式+欧拉降幂)
vlan同步—VTP通告
Qt——选择文件夹并获取路径以及文件夹下子文件
Reprinted, the fragment speaks very well, the big guy
什么是服务网格?在微服务体系中又是如何使用的?
CF633C(trie树dfs / 字符串hash + 线性dp)
瑞利衰落条件下扩频通信系统误码率仿真
How to set timed network disconnection to assist self-discipline in win10
Open source summer | I have nothing to do during the epidemic, I made a button display box special effect to display my blog
随机推荐
LeaRun模型驱动开发框架 重塑企业生产力
21天学习第五天--数组
CF803F(容斥原理+莫比乌斯函数)
js切换新闻列表样式
请教一个oracle - cdc问题。 设置为 StartupOptions.latest()
echart 股票数据分析 开发备忘录
迁移学习(Transfer Learning)的背景、历史
【FPGA教程案例47】图像案例7——基于FPGA的RGB图像转化为灰度图实现,通过MATLAB进行辅助验证
C人脸识别
banner 如何显示drawable图片
CF696C(计数推公式+欧拉降幂)
【开源教程2】疯壳·开源编队无人机-硬件资源简介
开源一夏 | RuntimeException 子类
钱放在股票账户安全吧?
【TypeScript】函数类型:返回值类型和参数类型到底如何定义?
【FPGA教程案例46】图像案例6——基于FPGA的图像高斯滤波verilog实现,通过MATLAB进行辅助验证
Digital currency perpetual contract exchange development and development functions and code presentation
AtCoder Regular Contest 145
spark学习笔记(八)——sparkSQL概述-定义/特点/DataFrame/DataSet
建设必要的是什么意思