Java Code Examples for net.sourceforge.tess4j.Tesseract#setDatapath()

The following examples show how to use net.sourceforge.tess4j.Tesseract#setDatapath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageOCRBatchController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public boolean makeActualParameters() {
    if (!super.makeActualParameters()) {
        return false;
    }

    try {
        OCRinstance = new Tesseract();
        // https://stackoverflow.com/questions/58286373/tess4j-pdf-to-tiff-to-tesseract-warning-invalid-resolution-0-dpi-using-70/58296472#58296472
        OCRinstance.setTessVariable("user_defined_dpi", "96");
        OCRinstance.setTessVariable("debug_file", "/dev/null");
        String path = AppVariables.getUserConfigValue("TessDataPath", null);
        if (path != null) {
            OCRinstance.setDatapath(path);
        }
        if (selectedLanguages != null) {
            OCRinstance.setLanguage(selectedLanguages);
        }
        textFiles = new ArrayList<>();
        return true;
    } catch (Exception e) {
        logger.error(e.toString());
        return false;
    }

}
 
Example 2
Source File: Tess4JExample.java    From tutorials with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    String result = null;
    try {
        File image = new File("src/main/resources/images/baeldung.png");
        Tesseract tesseract = new Tesseract();
        tesseract.setLanguage("spa");
        tesseract.setPageSegMode(1);
        tesseract.setOcrEngineMode(1);
        tesseract.setHocr(true);
        tesseract.setDatapath("src/main/resources/tessdata");
        result = tesseract.doOCR(image, new Rectangle(1200, 200));
    } catch (TesseractException e) {
        e.printStackTrace();
    }
    System.out.println(result);
}
 
Example 3
Source File: TessOcr.java    From MillionHero with MIT License 5 votes vote down vote up
TessOcr() {
    instance = new Tesseract();
    File tessDataFolder = LoadLibs.extractTessResources("tessdata");
    instance.setLanguage("chi_sim");
    //Set the tessdata path
    instance.setDatapath(tessDataFolder.getAbsolutePath());
}
 
Example 4
Source File: PdfOcrBatchController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean makeActualParameters() {
    if (!super.makeActualParameters()) {
        return false;
    }
    separator = separatorInput.getText();
    if (!separatorCheck.isSelected() || separator == null || separator.isEmpty()) {
        separator = null;
    }
    try {
        OCRinstance = new Tesseract();
        // https://stackoverflow.com/questions/58286373/tess4j-pdf-to-tiff-to-tesseract-warning-invalid-resolution-0-dpi-using-70/58296472#58296472
        if (convertRadio.isSelected()) {
            OCRinstance.setTessVariable("user_defined_dpi", dpi + "");
        } else {
            OCRinstance.setTessVariable("user_defined_dpi", "96");
        }
        OCRinstance.setTessVariable("debug_file", "/dev/null");

        String path = AppVariables.getUserConfigValue("TessDataPath", null);
        if (path != null) {
            OCRinstance.setDatapath(path);
        }
        OCRinstance.setLanguage(selectedLanguages);
        return true;
    } catch (Exception e) {
        logger.error(e.toString());
        return false;
    }
}
 
Example 5
Source File: VisualConfig.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
@Bean
public Tesseract tesseract() {
  Tesseract tess = new Tesseract();
  tess.setDatapath(tesseractDataPath);
  return tess;
}