Run Tesseract with ProcessBuilder

15 views
Skip to first unread message

magethle

unread,
Apr 1, 2025, 10:26:39 AMApr 1
to javacpp
Hi,

I tried to run tesseract from the command line as in the following example
      String tesseract = Loader.load(org.bytedeco.tesseract.program.tesseract.class);
      ProcessBuilder pb = new ProcessBuilder(tesseract, "--version");
      pb.inheritIO().start().waitFor();

as documented in

But this doesn't work.
If I run the command from the command line (<home>\.javacpp\cache\tesseract-5.5.0-1.5.11-windows-x86_64.jar\org\bytedeco\tesseract\windows-x86_64\tesseract.exe) I get a system error that there are some dll's missing.
Do I need to have gcc installed?

Thanks
Matthias


Samuel Audet

unread,
Apr 1, 2025, 9:57:36 PMApr 1
to javacpp...@googlegroups.com, magethle
Tesseract needs the DLLs from Leptonica, so we need to add those to the
PATH manually before launching the process. We can get the path to
Leptonica's DLLs as per
https://github.com/bytedeco/javacpp-presets/wiki/Debugging-UnsatisfiedLinkError-on-Windows

This could obviously be improved though. Contributions are welcome!

Samuel

Samuel Audet

unread,
Apr 2, 2025, 3:21:31 AMApr 2
to Matthias Agethle, javacpp
We don't need to set the PATH on Linux, so no need to worry about that.

On 4/2/25 16:04, Matthias Agethle wrote:
Thanks, I got it to work on windows now.
But how could I get the PATH variable generically? My program should run also on Linux environments.

I found these @Properties annotations, would I have to read these metadata? Or how could this be solved generically?
@Properties(
    inherit = {javacpp.class},
    target = "org.bytedeco.leptonica",
    global = "org.bytedeco.leptonica.global.leptonica",
    value = {@Platform(
    include = {"leptonica/alltypes.h", "leptonica/environ.h", "leptonica/array.h", "leptonica/array_internal.h", "leptonica/bbuffer.h", "leptonica/hashmap.h", "leptonica/heap.h", "leptonica/list.h", "leptonica/ptra.h", "leptonica/queue.h", "leptonica/rbtree.h", "leptonica/stack.h", "leptonica/arrayaccess.h", "leptonica/bmf.h", "leptonica/ccbord.h", "leptonica/ccbord_internal.h", "leptonica/colorfill.h", "leptonica/dewarp.h", "leptonica/gplot.h", "leptonica/imageio.h", "leptonica/jbclass.h", "leptonica/morph.h", "leptonica/pix.h", "leptonica/pix_internal.h", "leptonica/recog.h", "leptonica/regutils.h", "leptonica/stringcode.h", "leptonica/sudoku.h", "leptonica/watershed.h", "leptonica/allheaders.h"},
    link = {"leptonica@.6"},
    resource = {"include", "lib"}
), @Platform(
    value = {"linux"},
    preloadpath = {"/usr/lib/", "/usr/lib32/", "/usr/lib64/"},
    preload = {"gomp@.1"}
), @Platform(
    value = {"linux-armhf"},
    preloadpath = {"/usr/arm-linux-gnueabihf/lib/", "/usr/lib/arm-linux-gnueabihf/"}
), @Platform(
    value = {"linux-arm64"},
    preloadpath = {"/usr/aarch64-linux-gnu/lib/", "/usr/lib/aarch64-linux-gnu/"}
), @Platform(
    value = {"linux-x86"},
    preloadpath = {"/usr/lib32/", "/usr/lib/"}
), @Platform(
    value = {"linux-x86_64"},
    preloadpath = {"/usr/lib64/", "/usr/lib/"}
), @Platform(
    value = {"linux-ppc64"},
    preloadpath = {"/usr/lib/powerpc64-linux-gnu/", "/usr/lib/powerpc64le-linux-gnu/"}
), @Platform(
    value = {"android"},
    link = {"leptonica"}
), @Platform(
    value = {"windows"},
    preload = {"libwinpthread-1", "libgcc_s_dw2-1", "libgcc_s_seh-1", "libgomp-1", "libstdc++-6", "libleptonica"}
), @Platform(
    value = {"windows-x86"},
    preloadpath = {"C:/msys64/mingw32/bin/"}
), @Platform(
    value = {"windows-x86_64"},
    preloadpath = {"C:/msys64/mingw64/bin/"}
)}
)
@NoException
public class leptonica implements InfoMapper {
Reply all
Reply to author
Forward
0 new messages