Skip to main content

OcrLite

Struct OcrLite 

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

Implementations§

Source§

impl OcrLite

Source

pub fn new() -> Self

Source

pub fn set_doc_orientation_model(&mut self, clf: DocOrientationClassifier)

Carica il classificatore orientamento pagina (PP-LCNet_x1_0_doc_ori_onnx). Necessario per OcrOptions { use_doc_orientation: true }.

Source

pub fn init_models( &mut self, det_path: &str, cls_path: &str, rec_path: &str, num_thread: usize, ) -> Result<(), OcrError>

Source

pub fn init_models_with_dict( &mut self, det_path: &str, cls_path: &str, rec_path: &str, dict_path: &str, num_thread: usize, ) -> Result<(), OcrError>

Source

pub fn init_models_no_angle( &mut self, det_path: &str, rec_path: &str, dict_path: &str, num_thread: usize, ) -> Result<(), OcrError>

Variante senza angle-net: init solo det + rec, salta il cls model. Usare con do_angle: false (se do_angle=true l’inferenza fallisce con SessionNotInitialized). Utile nei test dove il cls ONNX non è disponibile in cache.

Source

pub fn init_models_with_dict_and_builder( &mut self, det_path: &str, cls_path: &str, rec_path: &str, dict_path: &str, num_thread: usize, builder_fn: Option<fn(SessionBuilder) -> Result<SessionBuilder, Error>>, ) -> Result<(), OcrError>

Variante di init_models_with_dict che accetta un builder_fn custom da applicare a tutti e 3 i Session::builder() (det+cls+rec). Usato dai consumer (Edge) per registrare execution provider hardware-accelerated (QNN-HTP / DirectML / CoreML / CUDA / XNNPACK) invece del default CPU-only del path standard.

Source

pub fn init_models_custom( &mut self, det_path: &str, cls_path: &str, rec_path: &str, builder_fn: fn(SessionBuilder) -> Result<SessionBuilder, Error>, ) -> Result<(), OcrError>

Source

pub fn init_models_custom_with_dict( &mut self, det_path: &str, cls_path: &str, rec_path: &str, dict_path: &str, builder_fn: fn(SessionBuilder) -> Result<SessionBuilder, Error>, ) -> Result<(), OcrError>

Source

pub fn init_models_from_memory( &mut self, det_bytes: &[u8], cls_bytes: &[u8], rec_bytes: &[u8], num_thread: usize, ) -> Result<(), OcrError>

Source

pub fn init_models_from_memory_custom( &mut self, det_bytes: &[u8], cls_bytes: &[u8], rec_bytes: &[u8], builder_fn: fn(SessionBuilder) -> Result<SessionBuilder, Error>, ) -> Result<(), OcrError>

Source

pub fn detect( &mut self, img_src: &RgbImage, padding: u32, max_side_len: u32, box_score_thresh: f32, box_thresh: f32, un_clip_ratio: f32, do_angle: bool, most_angle: bool, ) -> Result<OcrResult, OcrError>

检测图片

§Arguments
  • &self (undefined) - Describe this parameter.
  • img_src (&image) - 图片
  • padding (u32) - 变换图片时添加边框的宽度(提高检测效果)
  • max_side_len (u32) - 变换图片后图片宽和高保留的最大边长(超出该尺寸的图片将缩小)
  • box_score_thresh (f32) - 检测存在文本的区域的分值阈值
  • do_angle (bool) - 是否进行角度检测
Source

pub fn detect_angle_rollback( &mut self, img_src: &RgbImage, padding: u32, max_side_len: u32, box_score_thresh: f32, box_thresh: f32, un_clip_ratio: f32, do_angle: bool, most_angle: bool, angle_rollback_threshold: f32, ) -> Result<OcrResult, OcrError>

支持角度回滚的检测图片 在 do_angle 为 true 时生效,如果图片经过了角度纠正,但识别效果过差,则取消角度纠正

§Arguments
  • &self (undefined) - Describe this parameter.
  • img_src (&image) - 图片
  • padding (u32) - 变换图片时添加的边框的宽度(提高检测效果)
  • max_side_len (u32) - 变换图片后图片宽和高保留的最大边长(超出该尺寸的图片将缩小)
  • box_score_thresh (f32) - 检测存在文本的区域的分值阈值
  • do_angle (bool) - 是否进行角度检测
  • angle_rollback_threshold (f32) - 角度回滚的阈值,如果识别到的文字得分低于该值(或等于 NaN),则取消角度回滚
Source

pub fn detect_from_path( &mut self, img_path: &str, padding: u32, max_side_len: u32, box_score_thresh: f32, box_thresh: f32, un_clip_ratio: f32, do_angle: bool, most_angle: bool, ) -> Result<OcrResult, OcrError>

Source

pub fn detect_with_layout( &mut self, image: &RgbImage, layout: &mut LayoutAnalyzer, padding: u32, max_side_len: u32, box_score_thresh: f32, box_thresh: f32, un_clip_ratio: f32, do_angle: bool, most_angle: bool, options: OcrOptions, ) -> Result<LayoutAwareResult, OcrError>

Pipeline layout-aware completa: cls (per-line) → layout → ppocr (det+cls+rec) → associazione text-line ↔ layout-box → orphan recovery (nearest-neighbor) → sort per reading-order.

Vincolo utente: le text-line di OCR sono fonte di verità per il testo (non si filtrano per layout, evitando i buchi quando il layout omette regioni). Il layout serve per ordering + classifica semantica + associazione spaziale.

Ordering:

  1. Primary: LayoutBox.reading_order (-1 va in fondo).
  2. Secondary: y-position del centroide del text-block dentro lo stesso box (top-to-bottom).
  3. Tertiary: x-position del centroide (left-to-right) — utile per box che contengono testo affiancato.

Orphan recovery: text-line con centroide fuori da TUTTI i layout-box → assigned al box più vicino (centroid distance). Se non ci sono layout-box → tutto torna come orphan ordinato per y/x (fallback graceful per pagine senza layout detection).

Source

pub fn detect_with_options( &mut self, img_src: &RgbImage, padding: u32, max_side_len: u32, box_score_thresh: f32, box_thresh: f32, un_clip_ratio: f32, do_angle: bool, most_angle: bool, options: OcrOptions, ) -> Result<OcrResult, OcrError>

Variante “ricca” di Self::detect con OcrOptions.

I flag use_seal, use_formula, use_chart, use_doc_orientation e use_doc_unwarping sono riservati e non ancora implementati: se impostati a true viene emesso un warning su eprintln! e l’esecuzione prosegue senza lo stage corrispondente. Questo garantisce che i caller esistenti non si rompano quando gli stage verranno aggiunti in futuro.

Trait Implementations§

Source§

impl Debug for OcrLite

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OcrLite

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more