ocr_engine¶
ocr_engine
¶
OCR Engine for extracting text and bounding boxes from images.
Provides standardized access to multiple OCR backends (Tesseract, EasyOCR, and Google Cloud Vision) with built-in sentence/phrase merging.
OCRResult
¶
Standardized OCR result for a single block of text.
Initializes the OCRResult.
| 引数 | デスクリプション |
|---|---|
text
|
The extracted text fragment.
タイプ:
|
x
|
X-coordinate of top-left corner.
タイプ:
|
y
|
Y-coordinate of top-left corner.
タイプ:
|
w
|
Width of the bounding box.
タイプ:
|
h
|
Height of the bounding box.
タイプ:
|
confidence
|
Recognition confidence score (0.0 to 1.0).
タイプ:
|
ソースコード位置: src/core/ocr_engine.py
to_dict
¶
Converts the result to a dictionary for serialization or debugging.
| 戻り値 | デスクリプション |
|---|---|
dict
|
Dictionary representation of the OCR result.
タイプ:
|
ソースコード位置: src/core/ocr_engine.py
run_ocr
¶
Runs OCR on an image and returns standardized merged results.
Coordinates backend execution, samples text colors, and applies spatial merging.
| 引数 | デスクリプション |
|---|---|
image_path
|
Path to the image file.
タイプ:
|
method
|
OCR method to use.
タイプ:
|
src_lang
|
Source language label (e.g.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
list[OCRResult]
|
list[OCRResult]: List of merged OCR results with color info. |
ソースコード位置: src/core/ocr_engine.py
merge_ocr_results
¶
Groups OCR fragments into sentences based on spatial proximity.
Uses vertical overlap to identify lines and horizontal gaps to identify sentence breaks.
| 引数 | デスクリプション |
|---|---|
results
|
Raw fragments from OCR engine.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
list[OCRResult]
|
list[OCRResult]: Cohesive text blocks. |
ソースコード位置: src/core/ocr_engine.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
_run_tesseract
¶
Runs Tesseract OCR using subprocess and returns parsed word-level results.
If the requested language pack is not installed, automatically retries
with English (eng) as a fallback.
| 引数 | デスクリプション |
|---|---|
image_path
|
Path to the image file.
タイプ:
|
lang
|
Tesseract language code (e.g.
タイプ:
|
ソースコード位置: src/core/ocr_engine.py
_bypass_uno_import
¶
Temporarily restores Python's original import if UNO's hook is active.
LibreOffice UNO replaces builtins.__import__ with _uno_import,
which crashes on C-extension wildcard imports (e.g.
from _elementtree import *) because it accesses mod.__dict__
without guarding against mod being None.
| 戻り値 | デスクリプション |
|---|---|
Callable[..., Any] | None
|
The UNO import hook that was replaced, or |
Callable[..., Any] | None
|
was needed. The caller must restore it via |
Callable[..., Any] | None
|
|
ソースコード位置: src/core/ocr_engine.py
_get_easyocr_reader
¶
Returns a cached EasyOCR Reader for the given languages.
Creates a new Reader on first call for each language set, then reuses it. Disables GPU (no accelerator available) and quantization (deprecated in torch 2.10) to avoid intermittent failures.
| 引数 | デスクリプション |
|---|---|
langs
|
EasyOCR language codes (e.g.
タイプ:
|
| 戻り値 | デスクリプション |
|---|---|
object
|
An |
ソースコード位置: src/core/ocr_engine.py
_run_easyocr
¶
Runs EasyOCR backend.
If the requested language is not supported by EasyOCR, automatically
retries with English (["en"]) as a fallback.
| 引数 | デスクリプション |
|---|---|
image_path
|
Path to the image file.
タイプ:
|
languages
|
EasyOCR language codes (e.g.
タイプ:
|
ソースコード位置: src/core/ocr_engine.py
_run_google_cloud
¶
Runs Google Cloud Vision OCR backend via REST API.
| 引数 | デスクリプション |
|---|---|
image_path
|
Path to the image file.
タイプ:
|
lang_hints
|
Optional BCP-47 language hint codes (e.g.
タイプ:
|
ソースコード位置: src/core/ocr_engine.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |