pub struct OcrModel { /* private fields */ }Implementations§
Source§impl OcrModel
impl OcrModel
Sourcepub fn load_with(lang: OcrLang, lanes: usize) -> Result<Self, String>
pub fn load_with(lang: OcrLang, lanes: usize) -> Result<Self, String>
Load the recognition model and its character dictionary for lang —
see resolve_rec_pair for the selection rules (explicit
DOCLING_OCR_REC_ONNX/DOCLING_OCR_DICT paths win) — with lanes
recognition sessions.
Each session is pinned to one intra-op thread: ORT’s multi-threaded
float-reduction order varies across runs, which flips the CTC argmax on
low-confidence characters (e.g. noisy faxes) and makes the snapshot
output non-deterministic. Recognition is linear in line width (~0.17 ms
per pixel column on one core) and on a scanned page it, plus the
orientation probe that reads the six widest lines, is ~35% of the wall
time while the other cores idle. Lines are independent, so lanes
sessions recognise disjoint same-width batches concurrently — each
line still sees exactly the single-thread kernel path, results are
placed by index, and the output is byte-identical to one lane.
DOCLING_RS_OCR_SESSIONS overrides the caller’s lane count; under a
CUDA-class provider the default is one lane (#842) — the lanes exist
to use idle CPU cores, and on one GPU each is another session’s arena.
Sourcepub fn set_textline_orientation(&mut self, enable: bool)
pub fn set_textline_orientation(&mut self, enable: bool)
Turn RapidOCR’s line orientation handling on or off (#666): oriented crops, the 90° turn, and the 0/180 classifier on detector lines.
Sourcepub fn recognize_crops(
&mut self,
crops: &[RgbImage],
) -> Result<Vec<RecognizedLine>, String>
pub fn recognize_crops( &mut self, crops: &[RgbImage], ) -> Result<Vec<RecognizedLine>, String>
Recognize standalone line crops (#939) — no layout model, no page assembly, no detector: each image is taken to be one upright text line (dark ink on light ground, as the recognizer was trained), resized to the recognizer’s 48 px height at its aspect ratio (width clamped to 8–2400 px) and read with the same deterministic width-batching and recognition lanes as the page OCR — so a crop yields what the page OCR would read from the same pixels.
Returns exactly one RecognizedLine per crop, in input order; a
zero-sized crop reads as empty text with confidence 0.0. Nothing is
filtered — the page OCR’s text_score drop is
RecognizedLine::passes_text_score, left to the caller — and no
orientation handling runs here (see Self::recognize_det_boxes).
Sourcepub fn recognize_det_boxes(
&mut self,
img: &RgbImage,
boxes: &[DetBox],
) -> Result<Vec<RecognizedLine>, String>
pub fn recognize_det_boxes( &mut self, img: &RgbImage, boxes: &[DetBox], ) -> Result<Vec<RecognizedLine>, String>
Recognize the lines a text detector found on img (#939) — the
boxes DetModel::detect returns, in
img pixels — without running page layout. Each box is cropped as
the page OCR crops it (crate::ocr_prep::det_box_crop): with
Self::set_textline_orientation on, RapidOCR’s warp of the box’s
quad (tall lines turned 90°) and a 180° turn where the orientation
classifier reads it upside down; off (the default), the axis-aligned
box clamped to the image.
One RecognizedLine per box, in input order (so boxes[i] is the
geometry of result i, in img pixels); a box with nothing inside
the image reads as empty with confidence 0.0. Nothing is filtered,
as in Self::recognize_crops.
Sourcepub fn ocr_page_with(
&mut self,
img: &RgbImage,
regions: &[Region],
scale: f32,
detected: Option<&[DetBox]>,
) -> Result<Vec<(TextCell, f32)>, String>
pub fn ocr_page_with( &mut self, img: &RgbImage, regions: &[Region], scale: f32, detected: Option<&[DetBox]>, ) -> Result<Vec<(TextCell, f32)>, String>
OCR a page: produce text cells (page points) for every line found inside
the text regions, each paired with its recognition confidence (mean
emitted-character probability — feeds the page ocr_score, #183).
scale is image-px per page-point. detected — the text detector’s
boxes, in image pixels of img — makes them the line source inside
the regions (#570, see prep_region_lines_det); None keeps the
projection segmentation.
Sourcepub fn ocr_table_words(
&mut self,
img: &RgbImage,
regions: &[Region],
scale: f32,
detected: Option<&[DetBox]>,
) -> Result<Vec<(TextCell, f32)>, String>
pub fn ocr_table_words( &mut self, img: &RgbImage, regions: &[Region], scale: f32, detected: Option<&[DetBox]>, ) -> Result<Vec<(TextCell, f32)>, String>
Recognize the word crops inside the page’s table regions (mirroring
the browser scanned path): ocr_page_with deliberately
skips table labels, so a scanned table would otherwise reach the cell
matcher with no words at all and dissolve (#173). Returns word-level
TextCells in page points.
Auto Trait Implementations§
impl !RefUnwindSafe for OcrModel
impl !UnwindSafe for OcrModel
impl Freeze for OcrModel
impl Send for OcrModel
impl Sync for OcrModel
impl Unpin for OcrModel
impl UnsafeUnpin for OcrModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more