Skip to content

How do I use Tesseract instances globally #39

@qwe1177

Description

@qwe1177

first:

pub(crate) static ref tess: Mutex<tesseract::Tesseract> = {
let datapath ="/tesspath";
let language ="/tesslang";
let mut _tess = tesseract::Tesseract::new(Some(datapath ), Some(language )).unwrap();
Mutex::new(_tess)
};

after:

let tess = crate::tess.lock().unwrap().set_image_from_mem(&[255]);

error:

201 | let tess = crate::tess.lock().unwrap().set_image_from_mem(&[255]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------------
| | |
| | value moved due to this method call
| move occurs because value has type Tesseract, which does not implement the Copy trait

reason:

I looked at the set_image_from_mem method:
pub fn set_image_from_mem(
mut self,
img: &[u8],
) -> Result<Self, plumbing::leptonica_plumbing::PixReadMemError> {
let pix = plumbing::leptonica_plumbing::Pix::read_mem(img)?;
self.0.set_image_2(&pix);
Ok(self)
}

Can you change ownership to variable borrowing?
I want to use tesseracet instances globally, without having to use a new instance each time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions