当前位置:网站首页>水印图像读取与制作,三通道图转为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
边栏推荐
猜你喜欢
How to set timed network disconnection to assist self-discipline in win10
串行通信:常见的串行通信接口协议UART、SPI、I2C简介
R file not found problem
KITTI数据集简介(一)—— 传感器介绍
如何让您的wiki内容更高级?
Nioke 2022 Summer Multi-School 6 B Eezie and Pie (Difference on the tree + multiplication to find the kth ancestor board)
Go源码之原子操作(atomic)
Prometheus+Grafana监控系统
Regular use in js
【DB运营管理/开发解决方案】上海道宁为您提供提高工作便利性的集成开发工具——Orange
随机推荐
List<String>用空串替换null值,并且都加上单引号,并且转为字符串用,分割
中金证券股票开户流程是什么,我需要准备身份证吗,安全吗
mysql5.7安装教程(附下载链接)
套接字的概念
迁移学习(Transfer Learning)的背景、历史
同态加密:正则嵌入、理想格和RLWE问题
2.MySQL链接和创建数据库,创建数据表
@Transactional
21天学习第五天--数组
JVM内存模型和结构详解(五大模型图解)
Superficial understanding of ports
Node基于TCP建立的服务器
arm交叉编译
Codeforces Round #699 (Div. 2)
Tensorflow教程(六)——变量基础操作
CF187C(堆优化BFS)
【AI玩家养成记 • 第3期】AI开发者必备!史上最适合新手的昇腾AI环境搭建教程!!
win10如何设置定时联网断网辅助自律
用皮肤“听”音乐,网友戴上这款装备听音乐会:仿佛住在钢琴里
Jetpack Compose 的 Navigation学习