MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / OpenOCR

Class OpenOCR

openocr.py:34–297  ·  view source on GitHub ↗

Unified OpenOCR interface that dispatches to different task implementations. Supported tasks: - 'det': Text detection only - 'rec': Text recognition only - 'ocr': End-to-end OCR (text detection + recognition) - 'unirec': Universal recognition with Vision-Language Model

Source from the content-addressed store, hash-verified

32
33
34class OpenOCR:
35 """
36 Unified OpenOCR interface that dispatches to different task implementations.
37
38 Supported tasks:
39 - 'det': Text detection only
40 - 'rec': Text recognition only
41 - 'ocr': End-to-end OCR (text detection + recognition)
42 - 'unirec': Universal recognition with Vision-Language Model
43 - 'doc': Document OCR with layout analysis (tables, formulas, etc.)
44 - 'launch_openocr_demo': Launch OpenOCR Gradio demo
45 - 'launch_unirec_demo': Launch UniRec Gradio demo
46 - 'launch_opendoc_demo': Launch OpenDoc Gradio demo
47 """
48
49 def __init__(
50 self,
51 task: str = 'ocr',
52 # Common parameters
53 use_gpu: str = 'auto',
54 # OCR task parameters
55 mode: str = 'mobile',
56 backend: str = 'onnx',
57 onnx_det_model_path: Optional[str] = None,
58 onnx_rec_model_path: Optional[str] = None,
59 drop_score: float = 0.5,
60 det_box_type: str = 'quad',
61 # UniRec task parameters
62 unirec_encoder_path: Optional[str] = None,
63 unirec_decoder_path: Optional[str] = None,
64 tokenizer_mapping_path: Optional[str] = None,
65 max_length: int = 2048,
66 # Doc task parameters
67 layout_model_path: Optional[str] = None,
68 layout_threshold: float = 0.5,
69 use_layout_detection: bool = True,
70 use_chart_recognition: bool = True,
71 auto_download: bool = True,
72 max_parallel_blocks: int = 4,
73 ):
74 """
75 Initialize OpenOCR unified interface.
76
77 Args:
78 task: Task type ('ocr', 'det', 'rec', 'unirec', 'doc', 'launch_openocr_demo', 'launch_unirec_demo', 'launch_opendoc_demo')
79
80 # Common parameters
81 use_gpu: GPU usage strategy ('auto', 'true', or 'false')
82
83 # OCR task parameters
84 mode: Model mode ('mobile' or 'server')
85 backend: Backend type ('onnx')
86 onnx_det_model_path: Path to detection ONNX model
87 onnx_rec_model_path: Path to recognition ONNX model
88 drop_score: Score threshold for filtering results
89 det_box_type: Detection box type ('quad' or 'poly')
90
91 # UniRec task parameters

Callers 2

test_python_apiMethod · 0.90
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_python_apiMethod · 0.72