Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,9 @@ def process_video_with_mask(video_path, mask_path, text="Joker"):
|
|
22 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
23 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
24 |
|
|
|
|
|
|
|
25 |
while True:
|
26 |
ret_video, frame_video = cap_video.read()
|
27 |
ret_mask, frame_mask = cap_mask.read()
|
@@ -55,7 +58,11 @@ def process_video_with_mask(video_path, mask_path, text="Joker"):
|
|
55 |
# 计算中心点和尺寸
|
56 |
center = rect[0]
|
57 |
size = rect[1]
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
|
60 |
# 创建透明画布绘制文字
|
61 |
text_image = Image.new("RGBA", (int(size[0]), int(size[1])), (0, 0, 0, 0))
|
@@ -78,8 +85,8 @@ def process_video_with_mask(video_path, mask_path, text="Joker"):
|
|
78 |
# 绘制文字
|
79 |
text_draw.text((pos_x, pos_y), text, fill=(255, 255, 0, 255), font=font)
|
80 |
|
81 |
-
#
|
82 |
-
rotated_text = text_image.rotate(
|
83 |
|
84 |
# 计算粘贴位置
|
85 |
paste_x = int(center[0] - rotated_text.width / 2)
|
|
|
22 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
23 |
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
24 |
|
25 |
+
# 初始化固定角度为None
|
26 |
+
fixed_angle = None
|
27 |
+
|
28 |
while True:
|
29 |
ret_video, frame_video = cap_video.read()
|
30 |
ret_mask, frame_mask = cap_mask.read()
|
|
|
58 |
# 计算中心点和尺寸
|
59 |
center = rect[0]
|
60 |
size = rect[1]
|
61 |
+
current_angle = rect[2]
|
62 |
+
|
63 |
+
# 如果是第一帧,记录角度
|
64 |
+
if fixed_angle is None:
|
65 |
+
fixed_angle = current_angle
|
66 |
|
67 |
# 创建透明画布绘制文字
|
68 |
text_image = Image.new("RGBA", (int(size[0]), int(size[1])), (0, 0, 0, 0))
|
|
|
85 |
# 绘制文字
|
86 |
text_draw.text((pos_x, pos_y), text, fill=(255, 255, 0, 255), font=font)
|
87 |
|
88 |
+
# 使用固定角度旋转文字
|
89 |
+
rotated_text = text_image.rotate(fixed_angle, expand=True, center=(size[0]/2, size[1]/2))
|
90 |
|
91 |
# 计算粘贴位置
|
92 |
paste_x = int(center[0] - rotated_text.width / 2)
|