当前位置:网站首页>【OpenCV 例程200篇】218. 多行倾斜文字水印
【OpenCV 例程200篇】218. 多行倾斜文字水印
2022-07-04 09:35:00 【小白YouCans】
【youcans 的 OpenCV 例程200篇】218. 多行倾斜文字水印
8.1 添加多行倾斜文字水印
水印是叠加在图像上的标志、签名、文本或图案,用于保护图像的版权。
先在黑色背景上添加图像或文字制作水印,再使用 cv.addWeight 函数,通过重叠混合把水印添加到原始图像上。
也可以以水印图案或文字区域作为掩模,使用 cv.add 函数修改掩模区域的像素值,实现把水印添加到原始图像上。
例程 A4.10:为图像添加水印
# A4.10 为图像添加水印
img = cv.imread("../images/imgLena.tif", 1) # 加载原始图片
h, w = img.shape[0], img.shape[1]
# # 生成水印图案
# logo = cv.imread("../images/logoXupt.png", 0) # 加载 Logo
# logoResize = cv.resize(logo, (100,100)) # 调整图片尺寸
# grayMark = np.zeros(img.shape[:2], np.uint8) # 水印黑色背景
# grayMark[10:110,10:110] = logoResize # 生成水印图案
# 生成文字水印
mark = np.zeros(img.shape[:2], np.uint8) # 黑色背景
for i in range(h//100):
cv.putText(mark, "youcans2022", (50,70+100*i), cv.FONT_HERSHEY_SIMPLEX, 1.5, 255, 2)
MAR = cv.getRotationMatrix2D((w//2,h//2), 45, 1.0) # 旋转 45 度
grayMark = cv.warpAffine(mark, MAR, (w,h)) # 旋转变换,默认为黑色填充
# 为图像添加水印 1
markC3 = cv.merge([grayMark, grayMark, grayMark])
imgMark1 = cv.addWeighted(img, 1, markC3, 0.25, 0) # 加权加法图像融合
# 为图像添加水印2
imgMark2 = cv.add(img, 64, mask=grayMark) # 以水印图案作为掩模
plt.figure(figsize=(9, 6))
plt.subplot(221), plt.title("original"), plt.axis('off')
plt.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))
plt.subplot(222), plt.title("watermark"), plt.axis('off')
plt.imshow(cv.cvtColor(markC3, cv.COLOR_BGR2RGB))
plt.subplot(223), plt.title("watermark embedded"), plt.axis('off')
plt.imshow(cv.cvtColor(imgMark1, cv.COLOR_BGR2RGB))
plt.subplot(224), plt.title("watermark embedded"), plt.axis('off')
plt.imshow(cv.cvtColor(imgMark1, cv.COLOR_BGR2RGB))
plt.tight_layout()
plt.show()
【本节完】
版权声明:
[email protected] 原创作品,转载必须标注原文链接:(https://blog.csdn.net/youcans/article/details/125506829)
Copyright 2022 youcans, XUPT
Crated:2022-6-28
217. 鼠标交互获取多边形区域
218. 多行倾斜文字水印
边栏推荐
- 2022-2028 global small batch batch batch furnace industry research and trend analysis report
- MySQL transaction mvcc principle
- Solution to null JSON after serialization in golang
- Svg image quoted from CodeChina
- Exercise 8-7 string sorting (20 points)
- Normal vector point cloud rotation
- Summary of the most comprehensive CTF web question ideas (updating)
- Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
- Hands on deep learning (44) -- seq2seq principle and Implementation
- Write a jison parser (7/10) from scratch: the iterative development process of the parser generator 'parser generator'
猜你喜欢
Advanced technology management - how to design and follow up the performance of students at different levels
libmysqlclient.so.20: cannot open shared object file: No such file or directory
2022-2028 global protein confectionery industry research and trend analysis report
Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)
2022-2028 global edible probiotic raw material industry research and trend analysis report
Regular expression (I)
2022-2028 global intelligent interactive tablet industry research and trend analysis report
Histogram equalization
5g/4g wireless networking scheme for brand chain stores
JDBC and MySQL database
随机推荐
Logstack configuration details -- elasticstack (elk) work notes 020
Web端自动化测试失败原因汇总
Hands on deep learning (35) -- text preprocessing (NLP)
Exercise 9-1 time conversion (15 points)
Exercise 7-8 converting strings to decimal integers (15 points)
The child container margin top acts on the parent container
H5 audio tag custom style modification and adding playback control events
Explanation of closures in golang
2022-2028 global elastic strain sensor industry research and trend analysis report
lolcat
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
Problems encountered by scan, scanf and scanln in golang
Pueue data migration from '0.4.0' to '0.5.0' versions
Golang Modules
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
Lauchpad X | 模式
Write a jison parser from scratch (6/10): parse, not define syntax
How can people not love the amazing design of XXL job
SQL replying to comments
libmysqlclient.so.20: cannot open shared object file: No such file or directory