nguyenq / tess4j

Java JNA wrapper for Tesseract OCR API
Apache License 2.0
1.58k stars 372 forks source link

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

Open kpentaris opened 8 months ago

kpentaris commented 8 months ago

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?

nguyenq commented 7 months ago

@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.

kpentaris commented 7 months ago

@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 commented 6 months ago

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

nguyenq commented 6 months ago

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

kpentaris commented 6 months ago

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

nguyenq commented 6 months ago

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