Skip to content

Commit a499575

Browse files
committed
add flag
1 parent 4bc4feb commit a499575

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

add_flag/flag.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf8 -*-
2+
import cv2
3+
# 读取头像和国旗图案
4+
img_head = cv2.imread('getqrcode.jpg')
5+
img_flag = cv2.imread('flag.png')
6+
# 获取头像和国旗图案宽度
7+
w_head, h_head = img_head.shape[:2]
8+
w_flag, h_flag = img_flag.shape[:2]
9+
# 计算图案缩放比例
10+
scale = w_head / w_flag / 4
11+
# 缩放图案
12+
img_flag = cv2.resize(img_flag, (0, 0), fx=scale, fy=scale)
13+
# 获取缩放后新宽度
14+
w_flag, h_flag = img_flag.shape[:2]
15+
# 按3个通道合并图片
16+
for c in range(0, 3):
17+
img_head[w_head - w_flag:, h_head - h_flag:, c] = img_flag[:, :, c]
18+
# 保存最终结果
19+
cv2.imwrite('new_head.jpg', img_head)

0 commit comments

Comments
 (0)