Hi team
I’m facing an issue where Tesseract OCR works correctly from the CLI, but returns an empty string when called programmatically using Go (via gosseract).
For this particular image: https://pmi-api.ubconnex.ca/files/icons/2025-03/11c6051eec503f52c43f0de382980d31.png, the OCR always returns an empty string when running programmatically. Yet when I run the exact same image manually using Tesseract from terminal by command: tesseract /tmp/ocr-3678469497.png stdout
It correctly detects and returns NO SMOKING
Environment
Tesseract version: tesseract 5.x (CLI works fine)
Go binding: github.com/otiai10/gosseract/v2
Go version: go1.23.x
Different PSM modes (SPARSE_TEXT, SINGLE_BLOCK, etc.)
Preprocessing (grayscale, contrast enhancement, flattening transparency).
Verified that the image file is saved correctly and readable by Tesseract.
Tried increasing image size and contrast.
Is there any known discrepancy between the CLI binary and the gosseract API in how page segmentation modes or image preprocessing are handled internally?
Any insight on why Tesseract detects text in CLI but gosseract binding returns empty output would be very helpful.
Best Regards,
Harshit Goel
--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/tesseract-ocr/54875e13-9f91-4f45-9eb8-ee8eec4e5846n%40googlegroups.com.
Hi Ger,
Thanks a lot for the detailed guidance — it was really helpful.
I ran deeper diagnostics and confirmed a few things:
Running Tesseract CLI directly works perfectly and extracts: NO SMOKING
However, when using gosseract from Go, I still get empty text output and a single empty bounding box like:
Text: [ ], Box: (1476397136,32579)-(1476956064,32579)
The image being processed is a valid 8-bit/16-bit PNG (confirmed via file command).
Setting TESSDATA_PREFIX or SetTessdataPrefix("/usr/share/tessdata") works correctly — no language load errors.
Even after forcing engine mode with tessedit_ocr_engine_mode = 1 (LSTM only) and using PSM_SPARSE_TEXT, gosseract still returns empty text.
This makes me think gosseract is initializing Tesseract differently (maybe not loading the same configs or missing something in the setup phase), because the CLI and Go layer are using the same image and tessdata.
Do you have any suggestions for checking whether gosseract is properly initializing TessBaseAPI with the same defaults as CLI?
Thanks again for your help — your earlier hint about checking bounding boxes and configuration alignment was spot on.
Best regards,
Harshit
To view this discussion visit https://groups.google.com/d/msgid/tesseract-ocr/CAFP60foBhh_8kWyiP9-zVyfO8JrxwgDmvm%3DZH5pnE3sHYiu_1g%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/tesseract-ocr/CADRW4UeJiWeZa6aO%2BS2pZoqG1zkMX0q18Rg0efCk7irb5u6Zsw%40mail.gmail.com.