From eab0f0e0d4e309020606a281c8924f80b9150398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E6=9C=94?= <565183519@qq.com> Date: Wed, 24 Jun 2026 13:05:43 +0800 Subject: [PATCH] =?UTF-8?q?D144=20=C2=B7=20=E4=BF=AE=E5=A4=8D=20reference-?= =?UTF-8?q?subtitle-analyzer=20=E5=9D=90=E6=A0=87=E7=B3=BBbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 轮廓合并逻辑错误:max(all_x) + max(all_w) 改为 max(all_x[i]+all_w[i]) - 坐标系混用:y提前加offset但max_y没加,导致h=-1597 - 修复:先在bottom_region坐标系算完,最后加一次offset - 验证:测试图检测y=1750/h=55px/描边2px全部正确 冰朔 TCS-0002∞ 见证 ⊢ 铸渊 ICE-GL-ZY001 · D144 · 2026-06-24 --- .../reference-subtitle-analyzer.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/video-ai-system/engines/subtitle-pipeline/reference-analysis/reference-subtitle-analyzer.py b/video-ai-system/engines/subtitle-pipeline/reference-analysis/reference-subtitle-analyzer.py index 68052ec..721cea8 100644 --- a/video-ai-system/engines/subtitle-pipeline/reference-analysis/reference-subtitle-analyzer.py +++ b/video-ai-system/engines/subtitle-pipeline/reference-analysis/reference-subtitle-analyzer.py @@ -111,6 +111,7 @@ def analyze_subtitle_region(image_path: str, interactive: bool = False) -> dict: h = int(height * 0.12) else: # 合并所有轮廓的边界框 + # 正确算式:找到所有轮廓的最小外接矩形 all_x = [] all_y = [] all_w = [] @@ -123,20 +124,28 @@ def analyze_subtitle_region(image_path: str, interactive: bool = False) -> dict: all_w.append(cw) all_h.append(ch) - # 计算合并后的边界框 - x = min(all_x) - y = min(all_y) + int(height * 0.85) # 加上裁剪偏移 - w = max(all_x) + max(all_w) - x - h = max(all_y) + max(all_h) - y - + # 正确合并:先在 bottom_region 坐标系里算完,最后再加偏移 + x_bottom = min(all_x) + y_bottom = min(all_y) + max_x_bottom = max([all_x[i] + all_w[i] for i in range(len(all_x))]) + max_y_bottom = max([all_y[i] + all_h[i] for i in range(len(all_y))]) + w = max_x_bottom - x_bottom + h = max_y_bottom - y_bottom + # 扩展边界框(包含描边) padding = 10 - x = max(0, x - padding) - y = max(0, y - padding) + x = max(0, x_bottom - padding) + y = max(0, y_bottom - padding) + int(height * 0.85) # 偏移只加一次,在最后 w = min(width - x, w + 2 * padding) h = min(height - y, h + 2 * padding) # 计算字幕参数 + # 先做边界校验,防止裁剪出空数组 + x = max(0, min(x, width - 1)) + y = max(0, min(y, height - 1)) + w = max(1, min(w, width - x)) + h = max(1, min(h, height - y)) + subtitle_box = {"x": x, "y": y, "width": w, "height": h} subtitle_height_px = h bottom_distance_px = height - (y + h)