当前位置:网站首页>【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. 多行倾斜文字水印
边栏推荐
- System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
- MySQL develops small mall management system
- How web pages interact with applets
- System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
- Intelligent gateway helps improve industrial data acquisition and utilization
- Log cannot be recorded after log4net is deployed to the server
- Kotlin: collection use
- Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
- Golang defer
- Hands on deep learning (44) -- seq2seq principle and Implementation
猜你喜欢

Write a mobile date selector component by yourself

How can Huawei online match improve the success rate of player matching

Mmclassification annotation file generation

2022-2028 global special starch industry research and trend analysis report

直方图均衡化

2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report

H5 audio tag custom style modification and adding playback control events

Histogram equalization

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

Hands on deep learning (34) -- sequence model
随机推荐
智慧路灯杆水库区安全监测应用
7-17 crawling worms (15 points)
Normal vector point cloud rotation
Explanation of for loop in golang
Custom type: structure, enumeration, union
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
Deadlock in channel
Machine learning -- neural network (IV): BP neural network
Modules golang
In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
Application of safety monitoring in zhizhilu Denggan reservoir area
About the for range traversal operation in channel in golang
Exercise 9-5 address book sorting (20 points)
H5 audio tag custom style modification and adding playback control events
Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share
Pcl:: fromrosmsg alarm failed to find match for field 'intensity'
2. Data type
Problems encountered by scan, scanf and scanln in golang
2022-2028 global seeder industry research and trend analysis report
Ultimate bug finding method - two points