Quellcode durchsuchen

feat: 更新parse_mineru_data函数,支持图像类别的解析和处理

zhch158_admin vor 1 Monat
Ursprung
Commit
ee34bdc8f6
1 geänderte Dateien mit 22 neuen und 1 gelöschten Zeilen
  1. 22 1
      ocr_validator_utils.py

+ 22 - 1
ocr_validator_utils.py

@@ -316,7 +316,7 @@ def parse_mineru_data(data: List, config: Dict, tool_name="mineru") -> List[Dict
                 parsed_data.append({
                     'text': str(text).strip(),
                     'bbox': bbox[:4],
-                    'category': 'text',
+                    'category': category,
                     'confidence': confidence,
                     'source_tool': tool_name,
                     'text_level': item.get('text_level', 0)  # 保留文本层级信息
@@ -337,6 +337,27 @@ def parse_mineru_data(data: List, config: Dict, tool_name="mineru") -> List[Dict
                     'img_path': img_path,
                     'table_body': table_html
                 })
+        elif category == 'image':
+            img_path = item.get(tool_config.get('img_path_field', 'img_path'), '')
+            if bbox and len(bbox) >= 4:
+                parsed_data.append({
+                    'text': '[Image]',
+                    'bbox': bbox[:4],
+                    'category': 'image',
+                    'confidence': confidence,
+                    'source_tool': tool_name,
+                    'img_path': img_path
+                })
+        else:
+            # 其他类型,按文本处理,  header, table_cell, ...
+            if text and bbox and len(bbox) >= 4:
+                parsed_data.append({
+                    'text': str(text).strip(),
+                    'bbox': bbox[:4],
+                    'category': category,
+                    'confidence': confidence,
+                    'source_tool': tool_name
+                })
         
     return parsed_data