houqp / leptess

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

Implement set_frame() function #53

Closed yosefahab closed 1 year ago

yosefahab commented 1 year ago

I'm currently working with the ffmpeg_the_third crate to extract some video frames, which are raw [u8] slices, attempting to use this with set_image_from_mem() and then applying ocr causes a panic:

Error in pixReadMem: Unknown format: no pix returned Please call SetImage before attempting recognition.

i was also experementing with another (less flexible) tesseract crate and found set_frame() function which seems to work fine, i'm not sure why.

Would it be possible to implement it?

ccouzens commented 1 year ago

Hi,

which are raw [u8] slices

The bytes need an encoding in order to represent an image. I believe tesseract usually prefers the buffers to be tiff formatted (eg this example).

set_frame takes additional metadata about the image which is why you can pass in a raw buffer.

Would it be possible to dump the [u8] slice to a file and provide the parameters you were using with set_frame such that we can make it into a test case?

yosefahab commented 1 year ago

I've experimented a bit more into that, and found that ffmpeg_the_third might have some issues with extracting frames as images, the resulting bytes aren't exactly correct, and converting them to image formats isn't exactly straightfoward (or necessarily correct).

I tried a different ffmpeg crate which has a built in Frame struct that works with the example you provided. That being said, if you still want to implement set_frame() to be able to set image from an rgb buffer, let me know and i'll provide you with data you need.

Thank you.

ccouzens commented 1 year ago

Great. It's good you've got it working.

I'll close this issue for now, but if there's additional demand for the feature I might ask for your help with example data.