diff --git a/video-ai-system/engines/subtitle-pipeline/qc-tools/subtitle-safe-area-qc.py b/video-ai-system/engines/subtitle-pipeline/qc-tools/subtitle-safe-area-qc.py index d79e74b..aae6e05 100644 --- a/video-ai-system/engines/subtitle-pipeline/qc-tools/subtitle-safe-area-qc.py +++ b/video-ai-system/engines/subtitle-pipeline/qc-tools/subtitle-safe-area-qc.py @@ -171,7 +171,7 @@ def detect_subtitle_box(image: np.ndarray) -> list: if not contours: return [0, int(height * 0.85), width, int(height * 0.12)] # 默认底部区域 - # 合并所有轮廓的边界框 + # 收集所有轮廓的边界框 all_x = [] all_y = [] all_w = [] @@ -184,15 +184,23 @@ def detect_subtitle_box(image: np.ndarray) -> list: all_w.append(w) all_h.append(h) - # 计算合并后的边界框 - 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 + + # 最后统一加偏移 + x = x_bottom + y = y_bottom + int(height * 0.85) + # w, h 不需要加偏移(它们是在bottom_region里的尺寸) return [x, y, w, h] - - + + def calculate_iou(box1: list, box2: list) -> float: """ 计算两个边界框的 IOU(交并比)