当前位置:网站首页>水印图像读取与制作,三通道图转为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
边栏推荐
- Digital currency perpetual contract exchange development and development functions and code presentation
- mysql5.7安装教程(附下载链接)
- uri (url urn 的区别)
- 2.MySQL链接和创建数据库,创建数据表
- dp, dpi, px knowledge supplement
- CF696C(计数推公式+欧拉降幂)
- 基于simulink的风力机房温度控制系统仿真
- The difference between a uri (url urn)
- 2 prerequisites for the success of "digital transformation" of enterprises!
- Qt——选择文件夹并获取路径以及文件夹下子文件
猜你喜欢
win10如何设置定时联网断网辅助自律
js温度计插件自定义数值
2 prerequisites for the success of "digital transformation" of enterprises!
Open source summer | I have nothing to do during the epidemic, I made a button display box special effect to display my blog
21天学习第三天--常用运算符
从2022投影行业最新报告,读懂2022年家用智能投影仪该怎么选!
开源一夏 | 疫情期间闲来无事,我自制了一个按钮展示框特效来展示我的博客
【CC3200AI 实验教程4】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-GPIO
LeaRun模型驱动开发框架 重塑企业生产力
无需精子卵子子宫体外培育胚胎,Cell论文作者这番话让网友们炸了
随机推荐
openGauss社区七月运作报告
The difference between a uri (url urn)
阿里巴巴云原生大数据运维平台 SREWorks 正式开源
【云图说】第252期 初识云速建站服务
【CC3200AI 实验教程4】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-GPIO
开源一夏 | 疫情期间闲来无事,我自制了一个按钮展示框特效来展示我的博客
Tensorflow教程(六)——变量基础操作
Node基于TCP建立的服务器
DSPE-PEG-FITC,Fluorescein-PEG-DSPE,修饰性PEG磷脂-聚乙二醇-荧光素
21天学习第五天--数组
Jetpack Compose 的 Navigation学习
套接字的概念
博客主页rrs代码
AtCoder Regular Contest 145
软件工程基础知识--认识软件工程
建设必要的是什么意思
c语言指针运算
钱放在股票账户安全吧?
ARP协议详解,小白易懂
使用电脑通过VNC Viewer远程连接树莓派4B