1 Star 0 Fork 0

MrLiuSheep/去水印模型

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AddWatermarkSample.py 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
import cv2
import numpy as np
import random
'''
cv2.FONT_ITALIC:斜体字的标志
cv2.FONT_HERSHEY_PLAIN:小尺寸无衬线字体
cv2.FONT_HERSHEY_SIMPLEX:正常大小的无衬线字体
cv2.FONT_HERSHEY_DUPLEX:正常大小的无衬线字体(比FONT_HERSHEY_SIMPLEX更复杂)
cv2.FONT_HERSHEY_COMPLEX:正常大小的衬线字体
cv2.FONT_HERSHEY_TRIPLEX:正常大小的衬线字体(比FONT_HERSHEY_COMPLEX更复杂)
cv2.FONT_HERSHEY_SCRIPT_SIMPLEX:手写体字体
cv2.FONT_HERSHEY_SCRIPT_COMPLEX(比FONT_HERSHEY_SCRIPT_SIMPLEX的更复杂)
'''
fontFace_list = [
cv2.FONT_ITALIC,
cv2.FONT_HERSHEY_PLAIN,
cv2.FONT_HERSHEY_SIMPLEX,
cv2.FONT_HERSHEY_DUPLEX,
cv2.FONT_HERSHEY_COMPLEX,
cv2.FONT_HERSHEY_TRIPLEX,
cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
cv2.FONT_HERSHEY_SCRIPT_COMPLEX
]
img = cv2.imread(r'D:\VOCtrainval_11-May-2012\JPEGImages\2007_000027.jpg')
mask = np.zeros(shape=img.shape, dtype=np.uint8)
for i in range(random.randint(2, 12)):
text = ''
for i in range(11):
text += str(random.randint(0, 9))
fontFace = fontFace_list[random.randint(0, len(fontFace_list)-1)]
fontScale = random.random() * 1.5 + 0.5
color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
thickness = random.randint(1, 3)
x, y = int(mask.shape[1]*random.random()), int(mask.shape[0]*random.random())
text_size = cv2.getTextSize(text, fontFace, fontScale, thickness)
w, h = text_size[0]
cv2.putText(mask, text, (x, y), fontFace, fontScale, color, thickness)
# cv2.rectangle(img, (x, y), (x+w, y-h), (0, 0, 255), 1)
for i in range(10, -1, -1):
watermark_img = cv2.addWeighted(img, 1, mask, i*0.1, 0)
cv2.imshow('a', watermark_img)
cv2.waitKey(0)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/LiuSheepSpace/remove-watermark-model.git
git@gitee.com:LiuSheepSpace/remove-watermark-model.git
LiuSheepSpace
remove-watermark-model
去水印模型
master

搜索帮助