pub struct OcrLite { /* private fields */ }Implementations§
Source§impl OcrLite
impl OcrLite
pub fn new() -> Self
Sourcepub fn set_doc_orientation_model(&mut self, clf: DocOrientationClassifier)
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 }.
pub fn init_models( &mut self, det_path: &str, cls_path: &str, rec_path: &str, num_thread: usize, ) -> Result<(), OcrError>
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>
Sourcepub fn init_models_no_angle(
&mut self,
det_path: &str,
rec_path: &str,
dict_path: &str,
num_thread: usize,
) -> Result<(), OcrError>
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.
Sourcepub 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>
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.
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>
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>
pub fn init_models_from_memory( &mut self, det_bytes: &[u8], cls_bytes: &[u8], rec_bytes: &[u8], num_thread: usize, ) -> Result<(), OcrError>
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>
Sourcepub 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>
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) - 是否进行角度检测
Sourcepub 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>
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),则取消角度回滚
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>
Sourcepub 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>
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:
- Primary:
LayoutBox.reading_order(-1 va in fondo). - Secondary: y-position del centroide del text-block dentro lo stesso box (top-to-bottom).
- 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).
Sourcepub 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>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for OcrLite
impl !UnwindSafe for OcrLite
impl Freeze for OcrLite
impl Send for OcrLite
impl Sync for OcrLite
impl Unpin for OcrLite
impl UnsafeUnpin for OcrLite
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.