|
@@ -42,9 +42,18 @@ LAYOUT_CATEGORY_COLORS_BGR = {
|
|
|
'image_body': (0, 255, 0),
|
|
'image_body': (0, 255, 0),
|
|
|
'image_caption': (0, 200, 0),
|
|
'image_caption': (0, 200, 0),
|
|
|
'image_footnote': (0, 150, 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),
|
|
'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 红色框区分
|
|
# 亮蓝(BGR),在白底/浅灰流水上比黄色更易辨认;与 layout 红色框区分
|
|
|
OCR_BOX_COLOR_BGR = (255, 0, 0)
|
|
OCR_BOX_COLOR_BGR = (255, 0, 0)
|
|
|
OCR_BOX_LINE_THICKNESS = 2
|
|
OCR_BOX_LINE_THICKNESS = 2
|
|
@@ -76,14 +85,25 @@ def draw_layout_boxes_cv2(
|
|
|
continue
|
|
continue
|
|
|
category = result.get('category', 'unknown')
|
|
category = result.get('category', 'unknown')
|
|
|
color = LAYOUT_CATEGORY_COLORS_BGR.get(category, (128, 128, 128))
|
|
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])
|
|
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
|
|
label = category
|
|
|
confidence = result.get('confidence', result.get('score', 0))
|
|
confidence = result.get('confidence', result.get('score', 0))
|
|
|
if confidence:
|
|
if confidence:
|
|
|
label += f":{float(confidence):.2f}"
|
|
label += f":{float(confidence):.2f}"
|
|
|
font = cv2.FONT_HERSHEY_SIMPLEX
|
|
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_thickness = 1
|
|
|
(text_width, text_height), baseline = cv2.getTextSize(
|
|
(text_width, text_height), baseline = cv2.getTextSize(
|
|
|
label, font, font_scale, text_thickness
|
|
label, font, font_scale, text_thickness
|