OCR API
OCR providers translate images to candidate lines. The decode pipeline remains responsible for integrity and correction.
glyphive.restore.ocr
Lazy OCR provider registry and voting orchestration.
__all__ = ['OcrLine', 'OcrProvider', 'available', 'available_engines', 'get', 'names', 'ocr_image', 'ocr_pages', 'ocr_vote']
module-attribute
OcrLine
Bases: NamedTuple
One OCR-read line: its text plus optional per-character confidence.
char_conf is None when the provider (or a non-OCR text/QR path)
has no per-character confidence to offer -- callers MUST keep tolerating
that (plan 3: OCR-confidence-assisted char-level erasures is an
optimization, never a requirement). When present, char_conf has
exactly len(text) entries, one per character of text (spaces
included -- a provider gives whitespace a confidence of 1.0), each
in 0.0..1.0 (or None for a single character the provider itself
could not score). It is deliberately RAW: aligned to the full printed
line as read, not yet sliced down to the codec's payload region -- see
:func:glyphive.codec.engine.align_payload_char_conf, which does that
alignment once the codec's frame shape is known.
char_conf = None
class-attribute
instance-attribute
text
instance-attribute
OcrProvider
Bases: ABC
Base class for stateless, no-argument image OCR providers.
name
class-attribute
__init_subclass__(**kwargs)
Source code in src/glyphive/restore/ocr/_base.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
available()
classmethod
Source code in src/glyphive/restore/ocr/_base.py
57 58 59 60 61 62 63 | |
get(name)
classmethod
Source code in src/glyphive/restore/ocr/_base.py
65 66 67 68 69 70 71 72 73 74 | |
is_available()
classmethod
Source code in src/glyphive/restore/ocr/_base.py
76 77 78 | |
names()
classmethod
Source code in src/glyphive/restore/ocr/_base.py
53 54 55 | |
ocr_image(image_path)
abstractmethod
Return candidate lines (text + optional per-char confidence) from one image.
Source code in src/glyphive/restore/ocr/_base.py
100 101 102 | |
available()
Return registered OCR provider names currently available to use.
Source code in src/glyphive/restore/ocr/__init__.py
51 52 53 | |
available_engines()
Return available providers in the documented preference order.
Source code in src/glyphive/restore/ocr/__init__.py
56 57 58 59 60 61 62 63 64 65 66 67 | |
get(name)
Source code in src/glyphive/restore/ocr/__init__.py
43 44 | |
names()
Source code in src/glyphive/restore/ocr/__init__.py
47 48 | |
ocr_image(image_path, *, engine=None)
OCR one image with a selected or highest-preference provider.
Source code in src/glyphive/restore/ocr/__init__.py
90 91 92 | |
ocr_pages(image_paths, *, engine=None)
OCR several images, resolving one provider before any page work.
Source code in src/glyphive/restore/ocr/__init__.py
95 96 97 98 99 100 | |
ocr_vote(image_path, *, engines)
Return a majority-vote hint; CRC/RS remains the correctness oracle.
Votes on each line's TEXT only; the winning line's char_conf (from
whichever engine's reading was chosen) is carried through unchanged --
voting picks which text wins, it never blends or discards confidence.
Source code in src/glyphive/restore/ocr/__init__.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |