Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant get output no matter what i try. #55

Open
jonatino opened this issue Apr 10, 2023 · 1 comment
Open

Cant get output no matter what i try. #55

jonatino opened this issue Apr 10, 2023 · 1 comment

Comments

@jonatino
Copy link

jonatino commented Apr 10, 2023

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
Copy link
Collaborator

ccouzens commented May 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants