当前位置:网站首页>【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. 多行倾斜文字水印
边栏推荐
- 【leetcode】540. A single element in an ordered array
- How can Huawei online match improve the success rate of player matching
- Latex download installation record
- JDBC and MySQL database
- 2022-2028 global special starch industry research and trend analysis report
- Lauchpad x | MODE
- Kotlin: collection use
- Exercise 7-2 finding the maximum value and its subscript (20 points)
- Mmclassification annotation file generation
- lolcat
猜你喜欢

Matlab tips (25) competitive neural network and SOM neural network

Four common methods of copying object attributes (summarize the highest efficiency)

Sort out the power node, Mr. Wang he's SSM integration steps

The child container margin top acts on the parent container

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

Kubernetes CNI 插件之Fabric

Write a mobile date selector component by yourself

Hands on deep learning (36) -- language model and data set

Pcl:: fromrosmsg alarm failed to find match for field 'intensity'

xxl-job惊艳的设计,怎能叫人不爱
随机推荐
Web端自动化测试失败原因汇总
Golang defer
Log cannot be recorded after log4net is deployed to the server
2022-2028 global optical transparency industry research and trend analysis report
Fatal error in golang: concurrent map writes
Nuxt reports an error: render function or template not defined in component: anonymous
Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
2022-2028 global gasket plate heat exchanger industry research and trend analysis report
Lauchpad X | 模式
Launpad | 基礎知識
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
Write a mobile date selector component by yourself
百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
2. Data type
Lauchpad x | MODE
Four common methods of copying object attributes (summarize the highest efficiency)
Golang type comparison
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
Write a jison parser from scratch (6/10): parse, not define syntax