当前位置:网站首页>【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. 多行倾斜文字水印
边栏推荐
- Explanation of closures in golang
- Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
- 2022-2028 global seeder industry research and trend analysis report
- H5 audio tag custom style modification and adding playback control events
- MySQL foundation 02 - installing MySQL in non docker version
- Exercise 7-3 store the numbers in the array in reverse order (20 points)
- JDBC and MySQL database
- Golang 类型比较
- Implementing expired localstorage cache with lazy deletion and scheduled deletion
- Exercise 9-1 time conversion (15 points)
猜你喜欢
2022-2028 global elastic strain sensor industry research and trend analysis report
Hands on deep learning (III) -- Torch Operation (sorting out documents in detail)
Advanced technology management - how to design and follow up the performance of students at different levels
Custom type: structure, enumeration, union
SQL replying to comments
Intelligent gateway helps improve industrial data acquisition and utilization
JDBC and MySQL database
智慧路灯杆水库区安全监测应用
Hands on deep learning (40) -- short and long term memory network (LSTM)
The child container margin top acts on the parent container
随机推荐
Exercise 7-8 converting strings to decimal integers (15 points)
智慧路灯杆水库区安全监测应用
Log cannot be recorded after log4net is deployed to the server
Golang defer
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
Kotlin 集合操作汇总
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
el-table单选并隐藏全选框
Daughter love: frequency spectrum analysis of a piece of music
C语言指针经典面试题——第一弹
On Multus CNI
Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
自动化的优点有哪些?
Modules golang
SQL replying to comments
Les différents modèles imbriqués de listview et Pageview avec les conseils de flutter
Solution to null JSON after serialization in golang
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
2022-2028 global small batch batch batch furnace industry research and trend analysis report
Ultimate bug finding method - two points