feat(v1): chinese screenshot labels via Pillow with ASCII fallback

annotate_frame draws Chinese labels (e.g. '确认摔倒 P-0001') using a CJK
font via Pillow when available (Windows uses Microsoft YaHei), and falls
back to the ASCII cv2 label when Pillow or a CJK font is missing. 86 tests
pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ila
2026-07-22 00:10:07 +08:00
co-authored by Claude Opus 4.8
parent c5e4d87b42
commit 8b33f61112
6 changed files with 129 additions and 9 deletions
+9
View File
@@ -406,3 +406,12 @@
- 阻塞:真实中文观感需 Windows(用 C:/Windows/Fonts/msyh.ttc);标签、字体查找与回退逻辑本环境可测。
- 决策:auto 字体候选只放 CJK 字体(msyh/simhei/文泉驿/Noto CJK),找不到就回退 ASCII 而非渲染豆腐块;Windows 自动用雅黑,无需配置。
- 下一步:加 `annotation_label`/`_find_font`/PIL 绘制与回退,`annotate_frame` 接入,补测试。
## 【2026-07-22】T-213 截图中文标注(Pillow)(完成)
- 状态:DONE
- 变更:`alerts.py` 新增 `annotation_label`("确认摔倒 P-0001" 等中文)、`_find_font`(只在 CJK 字体候选中查找:Windows msyh/simhei、Linux 文泉驿/Noto CJK)、`_draw_labels`/`_draw_labels_pil`。`annotate_frame(image, view, font_path=None)`:cv2 画框/骨架/红边后,若 PIL 可用且找到 CJK 字体则 PIL 绘中文标签,否则回退 cv2 ASCII(保留 T-210)。`requirements.txt` 加 `Pillow==9.5.0`。
- 验证:新增 test_alerts 四项(中文标签、字体查找有无、无字体回退不崩溃、有 TTF 时 PIL 路径运行);`python3 -m pytest v1/tests -q` 为 86 passed;`python3 -m compileall -q v1` 退出码 0。本环境无 CJK 字体故 auto 走 ASCII 回退;用 DejaVu 显式路径验证 PIL 绘制路径不崩溃(中文字形需 Windows 雅黑)。
- 阻塞:真实中文观感需 Windows(自动用 C:/Windows/Fonts/msyh.ttc)。
- 决策:auto 字体候选只放 CJK 字体,找不到就回退 ASCII 而非渲染豆腐块;无需配置,Windows 自动中文、其它环境安全回退。
- 下一步:本批"别的"三项(T-211/212/213)完成;用户 Windows 冒烟中文标注、低延迟与灵敏度设置页。