Skip to main content

OcrModel

Struct OcrModel 

Source
pub struct OcrModel { /* private fields */ }

Implementations§

Source§

impl OcrModel

Source

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.

Source

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.

Source

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 px–crate::ocr_prep::REC_MAX_WIDTH) 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).

Source

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): RapidOCR’s warp of the box’s quad, upright out of the detector’s rotated rectangle (tall lines turned 90°; #981) and, with Self::set_textline_orientation on, a 180° turn where the orientation classifier reads it upside down.

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V