Skip to content

Commit d19e0ef

Browse files
committed
enhance: text placement on video
1 parent f625e74 commit d19e0ef

File tree

6 files changed

+4
-5
lines changed

6 files changed

+4
-5
lines changed

index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from vcab import Model, save_video_stream_predictions
22

3-
video_path = r"v_ArmFlapping_01.mp4"
3+
video_path = "videos/v_Spinning_01.mp4"
44
predictions = Model().predict_stream(video_path=video_path)
55
save_video_stream_predictions(
6-
video_path=video_path, predictions=predictions, output_path="v_ArmFlapping_output.mp4")
6+
video_path=video_path, predictions=predictions, output_path="output/v_Spinning_01.mp4")

output/v_ArmFlapping_01.mp4

449 KB
Binary file not shown.

output/v_Headbanging_01.mp4

15 KB
Binary file not shown.

output/v_Spinning_01.mp4

315 KB
Binary file not shown.
193 Bytes
Binary file not shown.

vcab/utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ def save_video_stream_predictions(video_path: str, predictions, output_path="out
4444

4545
if current_time >= start_sec and current_time <= end_sec:
4646
for i, text in enumerate(texts):
47-
text_size = cv2.getTextSize(
48-
text[0], font, font_scale, 1)[0]
47+
max_text_height = max(cv2.getTextSize(text[0], font, font_scale, 1)[0][1] for text in texts)
4948
text_x = 10
50-
text_y = 10 + i * (text_size[1] + 5)
49+
text_y = 10 + max_text_height + i * (max_text_height + 5)
5150
cv2.putText(frame, f"{text[0]} {text[1]}", (text_x, text_y),
5251
font, font_scale, color, 1, cv2.LINE_AA)
5352

0 commit comments

Comments
 (0)