tess4j icon indicating copy to clipboard operation
tess4j copied to clipboard

Tesseract1.doOCR method doesn't take into account the stride of the image

Open kpentaris opened this issue 1 year ago • 6 comments

Hello,

We recently integrated Tesseract and Tess4J and noticed that the APIs do not take into account the stride of the image which can potentially differ from the width or xsize of the image. I thought that maybe the setImage method would calculate this using the ByteBuffer.capacity() or something but checking the implementation it just assumes that the stride will be a multiple of the width and the bytes per pixel which is not always case e.g. when storing color images using 32bits but the bit depth still is 24. Is there something I'm missing or is this something to be fixed?

kpentaris avatar Jan 05 '24 11:01 kpentaris

@kpentaris The stride may be used internally by Tesseract OCR engine, but its public C API does not use or expose it, so Tess4J does not need to consider it.

nguyenq avatar Jan 25 '24 02:01 nguyenq

@nguyenq the C API has the TessBaseAPISetImage call which takes the bytes_per_line argument. The tess4j wrapper in Tesseract1.setImage method (which calls TessBaseAPISetImage) generates the bytes per line assuming that there is no padding (which is what the stride denotes). I'm guessing this is why it's bytes per line and not pixels per line.

kpentaris avatar Jan 26 '24 12:01 kpentaris

@nguyenq hello. Is there a commit number where this issue is fixed (since it was marked as completed)? Thanks!

kpentaris avatar Mar 05 '24 11:03 kpentaris

@kpentaris Sorry, it was meant to close as not planned since it's not an issue. Tesseract engine does not consider image stride.

nguyenq avatar Mar 08 '24 03:03 nguyenq

@nguyenq I'm confused, in my previous comment I showed exactly where it considers it in the TessBaseAPISetImage function.

kpentaris avatar Mar 08 '24 10:03 kpentaris

@kpentaris I misunderstood your statement. Please submit a PR.

nguyenq avatar Mar 09 '24 01:03 nguyenq