|
|
@@ -24,75 +24,6 @@ class OCRLayoutManager:
|
|
|
self.validator = validator
|
|
|
self.config = validator.config
|
|
|
|
|
|
- def create_interactive_plot(self, image: Image.Image, selected_bbox: Optional[List[int]] = None) -> go.Figure:
|
|
|
- """创建交互式图片显示"""
|
|
|
- fig = go.Figure()
|
|
|
-
|
|
|
- # 添加图片
|
|
|
- fig.add_layout_image(
|
|
|
- dict(
|
|
|
- source=image,
|
|
|
- xref="x", yref="y",
|
|
|
- x=0, y=image.height,
|
|
|
- sizex=image.width, sizey=image.height,
|
|
|
- sizing="stretch", opacity=1.0, layer="below"
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- colors = self.config['styles']['colors']
|
|
|
-
|
|
|
- # 添加所有bbox(浅色显示)
|
|
|
- for text, info_list in self.validator.text_bbox_mapping.items():
|
|
|
- for info in info_list:
|
|
|
- bbox = info['bbox']
|
|
|
- if len(bbox) >= 4:
|
|
|
- x1, y1, x2, y2 = bbox[:4]
|
|
|
-
|
|
|
- if text in self.validator.marked_errors:
|
|
|
- color = f"rgba(244, 67, 54, 0.3)" # 错误标记为红色
|
|
|
- line_color = colors['error']
|
|
|
- else:
|
|
|
- color = f"rgba(2, 136, 209, 0.2)" # 默认浅蓝色
|
|
|
- line_color = colors['primary']
|
|
|
-
|
|
|
- fig.add_shape(
|
|
|
- type="rect",
|
|
|
- x0=x1, y0=image.height-y2,
|
|
|
- x1=x2, y1=image.height-y1,
|
|
|
- line=dict(color=line_color, width=1),
|
|
|
- fillcolor=color,
|
|
|
- )
|
|
|
-
|
|
|
- # 高亮显示选中的bbox
|
|
|
- if selected_bbox and len(selected_bbox) >= 4:
|
|
|
- x1, y1, x2, y2 = selected_bbox[:4]
|
|
|
- fig.add_shape(
|
|
|
- type="rect",
|
|
|
- x0=x1, y0=image.height-y2,
|
|
|
- x1=x2, y1=image.height-y1,
|
|
|
- line=dict(color=colors['error'], width=3),
|
|
|
- fillcolor="rgba(255, 0, 0, 0.2)",
|
|
|
- )
|
|
|
-
|
|
|
- # 设置布局 - 增加图片大小并确保从顶部开始显示
|
|
|
- fig.update_xaxes(visible=False, range=[0, image.width])
|
|
|
- fig.update_yaxes(visible=False, range=[0, image.height], scaleanchor="x")
|
|
|
-
|
|
|
- # 计算合适的显示尺寸
|
|
|
- aspect_ratio = image.width / image.height
|
|
|
- display_height = 800 # 增加显示高度
|
|
|
- display_width = int(display_height * aspect_ratio)
|
|
|
-
|
|
|
- fig.update_layout(
|
|
|
- width=display_width,
|
|
|
- height=display_height,
|
|
|
- margin=dict(l=0, r=0, t=0, b=0),
|
|
|
- xaxis_showgrid=False, yaxis_showgrid=False,
|
|
|
- plot_bgcolor='white'
|
|
|
- )
|
|
|
-
|
|
|
- return fig
|
|
|
-
|
|
|
def render_content_section(self, layout_type: str = "standard"):
|
|
|
"""渲染内容区域 - 统一方法"""
|
|
|
st.header("📄 OCR识别内容")
|
|
|
@@ -198,7 +129,7 @@ class OCRLayoutManager:
|
|
|
key=f"{layout_type}_text_area"
|
|
|
)
|
|
|
|
|
|
- # 三种布局实现
|
|
|
+ # 布局实现
|
|
|
def create_standard_layout(self, font_size: int = 10, zoom_level: float = 1.0):
|
|
|
"""创建标准布局"""
|
|
|
if zoom_level is None:
|