houqp / leptess

Productive and safe Rust binding for leptonica and tesseract
https://houqp.github.io/leptess/leptess/index.html
MIT License
258 stars 29 forks source link

Cant get output no matter what i try. #55

Open jonatino opened 1 year ago

jonatino commented 1 year ago

Hello, first of all thanks for your efforts for these very nicely done rust bindings :)

I'm trying to use this to read specific regions on screen and output the values. Most of these regions will only contain numeric value (0-9 and ,'s).

Code:

    // Location on screen relative to window
    let hp = Bounds {
        x: 965,
        y: 87,
        width: 30,
        height: 20,
    };

    // Grab the rgb values of each pixel in this region from the screen and store it in a buffer
    let mut buffer = ImageBuffer::from_fn(hp.width, hp.height, |x, y| {
        let rgb = get_pixel_col(hp.x + x, hp.y + y);
        Rgb([(rgb & 0xff) as u8, ((rgb >> 8) & 0xff) as u8, ((rgb >> 16) & 0xff) as u8])
    });

    // Convert the raw RGB buffer above to TIFF format
    let mut tiff_buffer = Vec::new();
    buffer.write_to(
        &mut Cursor::new(&mut tiff_buffer),
        image::ImageOutputFormat::Tiff,
    )
        .unwrap();

    buffer.save("ocrtest.tiff"); // Test to verify image is correct

    let mut lt = LepTess::new(None, "eng").unwrap();

    lt.set_image_from_mem(&tiff_buffer).unwrap();
    lt.set_variable(Variable::TesseditCharWhitelist, "0123456789").unwrap(); // White list only numeric values
    lt.set_source_resolution(240);

Image trying to OCR: image

The size is 30px width x 20px height at 240dpi. I'm using the generic English model provided in your repo, would it benefit training a new dataset specifically for this font?

ccouzens commented 1 year ago

Hey,

Sorry for the slow response.

When I use the command line tool, I also get an empty response.

⬢[chris@toolbox tesseract-rs]$ tesseract ~/Downloads/230999208-ea36048c-28ee-452f-a027-bfa43c965c99.png ~/Downloads/output
Estimating resolution as 159
Empty page!!
Estimating resolution as 159
Empty page!!
⬢[chris@toolbox tesseract-rs]$ cat ~/Downloads/output.txt
# empty

I also tried with the numeric white list

tesseract ~/Downloads/230999208-ea36048c-28ee-452f-a027-bfa43c965c99.png ~/Downloads/output -c tessedit_char_whitelist=0123456789

And I tried scaling the image to be 300x200 in an image editing tool. Scaling without the whitelist produced different output, but not correct output.

Although I contributed to the bindings I don't have the knowledge to help suggest how you'd get results for this image and similar.