Javacpp-presets: How to use TessBaseAPI.init() to load xxx.traineddata file from InputStream

Created on 23 Sep 2019  路  2Comments  路  Source: bytedeco/javacpp-presets

I want initialize "chi_sim.traineddata" via TessBaseAPI.init() method锛宐ut my program only permit to initialize from InputStream,

//The way only load file via filename
if (tessBaseAPI.Init("/user/share/tessdata", "chi_sim") != 0) {
    log.error("Could not initialize tesseract.");
    throw new IOException();
}

how to initialize from inputStream? please

question

Most helpful comment

@saudet thank you , if Tesseract don't support use inputstream to initialize tessdata, the following coe will help others when tessdata from inputstream.

        InputStream inputStream = resource.getInputStream();
        File somethingFile = File.createTempFile("chi_sim", ".traineddata");
        FileUtils.copyInputStreamToFile(inputStream, somethingFile);

        if (tessBaseAPI.Init(somethingFile.getParent(),
                FilenameUtils.getBaseName(somethingFile.getName())) != 0) {
            log.error("Could not initialize tesseract.");
            throw new IOException();
        }

All 2 comments

I don't think Tesseract supports that any other way than by creating a temporary file.

@saudet thank you , if Tesseract don't support use inputstream to initialize tessdata, the following coe will help others when tessdata from inputstream.

        InputStream inputStream = resource.getInputStream();
        File somethingFile = File.createTempFile("chi_sim", ".traineddata");
        FileUtils.copyInputStreamToFile(inputStream, somethingFile);

        if (tessBaseAPI.Init(somethingFile.getParent(),
                FilenameUtils.getBaseName(somethingFile.getName())) != 0) {
            log.error("Could not initialize tesseract.");
            throw new IOException();
        }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryantheseer picture ryantheseer  路  43Comments

blueberry picture blueberry  路  32Comments

mmanco picture mmanco  路  20Comments

archenroot picture archenroot  路  29Comments

thunterdb picture thunterdb  路  37Comments