Kaynağa Gözat

feat(增强布局绘制功能): 在module_debug_viz.py中新增印章和图表的颜色定义,优化绘制逻辑,添加OCR框收集功能,提升文档元素的可视化效果与识别能力。

zhch158_admin 1 ay önce
ebeveyn
işleme
bcea502090
1 değiştirilmiş dosya ile 22 ekleme ve 2 silme
  1. 22 2
      ocr_utils/module_debug_viz.py

+ 22 - 2
ocr_utils/module_debug_viz.py

@@ -42,9 +42,18 @@ LAYOUT_CATEGORY_COLORS_BGR = {
     'image_body': (0, 255, 0),
     'image_caption': (0, 200, 0),
     'image_footnote': (0, 150, 0),
+    'chart': (255, 255, 0),   # 青色(BGR 下 B=255,G=255,R=0)
+    # 注意:OpenCV 为 BGR,(0,255,255) 在屏幕上呈黄色(与 title 相同),勿用于 seal
+    'seal': (0, 140, 255),    # 亮橙,与红 table / 黄 title / 蓝 text 均易区分
     'abandon': (128, 128, 128),
 }
 
+# seal 常与 table 重叠:加粗线宽 + 黑色外描边
+LAYOUT_HIGHLIGHT_CATEGORIES = frozenset({'seal'})
+LAYOUT_HIGHLIGHT_LINE_THICKNESS = 4
+LAYOUT_HIGHLIGHT_OUTLINE_BGR = (0, 0, 0)
+LAYOUT_DEFAULT_LINE_THICKNESS = 2
+
 # 亮蓝(BGR),在白底/浅灰流水上比黄色更易辨认;与 layout 红色框区分
 OCR_BOX_COLOR_BGR = (255, 0, 0)
 OCR_BOX_LINE_THICKNESS = 2
@@ -76,14 +85,25 @@ def draw_layout_boxes_cv2(
             continue
         category = result.get('category', 'unknown')
         color = LAYOUT_CATEGORY_COLORS_BGR.get(category, (128, 128, 128))
+        thickness = (
+            LAYOUT_HIGHLIGHT_LINE_THICKNESS
+            if category in LAYOUT_HIGHLIGHT_CATEGORIES
+            else LAYOUT_DEFAULT_LINE_THICKNESS
+        )
         x1, y1, x2, y2 = int(bbox[0]), int(bbox[1]), int(bbox[2]), int(bbox[3])
-        cv2.rectangle(vis, (x1, y1), (x2, y2), color, 2)
+        if category in LAYOUT_HIGHLIGHT_CATEGORIES:
+            cv2.rectangle(
+                vis, (x1, y1), (x2, y2),
+                LAYOUT_HIGHLIGHT_OUTLINE_BGR,
+                thickness + 2,
+            )
+        cv2.rectangle(vis, (x1, y1), (x2, y2), color, thickness)
         label = category
         confidence = result.get('confidence', result.get('score', 0))
         if confidence:
             label += f":{float(confidence):.2f}"
         font = cv2.FONT_HERSHEY_SIMPLEX
-        font_scale = 0.4
+        font_scale = 0.5 if category in LAYOUT_HIGHLIGHT_CATEGORIES else 0.4
         text_thickness = 1
         (text_width, text_height), baseline = cv2.getTextSize(
             label, font, font_scale, text_thickness