pub struct Rec { /* private fields */ }Expand description
载入好的识别模型。
Implementations§
Source§impl Rec
impl Rec
Sourcepub fn load(dir: &Path) -> Result<Rec, String>
pub fn load(dir: &Path) -> Result<Rec, String>
dir 是模型目录:model.safetensors、config.json、preprocessor_config.json(含字符表)。
Examples found in repository?
examples/rec_check.rs (line 41)
38fn main() {
39 let a: Vec<String> = std::env::args().skip(1).collect();
40 let t = Instant::now();
41 let rec = pagesift_ocr::rec::Rec::load(std::path::Path::new(&a[0])).unwrap();
42 println!("载入 {:.0} ms", t.elapsed().as_secs_f64() * 1e3);
43 for p in &a[1..] {
44 let img = read_ppm(p);
45 let t = Instant::now();
46 let (text, score) = rec.recognize(&img).unwrap();
47 let ms = t.elapsed().as_secs_f64() * 1e3;
48 let name = std::path::Path::new(p)
49 .file_name()
50 .unwrap()
51 .to_string_lossy();
52 println!(
53 "{name}\t{}x{}\t{ms:.0} ms\t{score:.3}\t{text}",
54 img.width, img.height
55 );
56 }
57}Sourcepub fn recognize(&self, line: &Image) -> Result<(String, f32), String>
pub fn recognize(&self, line: &Image) -> Result<(String, f32), String>
识别一行字的图(已裁出、拉正成水平的一行)。返回文字和置信度。
Examples found in repository?
examples/rec_check.rs (line 46)
38fn main() {
39 let a: Vec<String> = std::env::args().skip(1).collect();
40 let t = Instant::now();
41 let rec = pagesift_ocr::rec::Rec::load(std::path::Path::new(&a[0])).unwrap();
42 println!("载入 {:.0} ms", t.elapsed().as_secs_f64() * 1e3);
43 for p in &a[1..] {
44 let img = read_ppm(p);
45 let t = Instant::now();
46 let (text, score) = rec.recognize(&img).unwrap();
47 let ms = t.elapsed().as_secs_f64() * 1e3;
48 let name = std::path::Path::new(p)
49 .file_name()
50 .unwrap()
51 .to_string_lossy();
52 println!(
53 "{name}\t{}x{}\t{ms:.0} ms\t{score:.3}\t{text}",
54 img.width, img.height
55 );
56 }
57}Sourcepub fn input_channels(&self) -> usize
pub fn input_channels(&self) -> usize
网络输入的通道数。
Sourcepub fn input_height(&self) -> usize
pub fn input_height(&self) -> usize
网络输入的高。
Auto Trait Implementations§
impl Forget for Rec
impl Freeze for Rec
impl Move for Rec
impl RefUnwindSafe for Rec
impl Send for Rec
impl Sync for Rec
impl Unpin for Rec
impl UnsafeUnpin for Rec
impl UnwindSafe for Rec
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
Mutably borrows from an owned value. Read more