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

The following examples show how to use net.sourceforge.tess4j.Tesseract#setLanguage() . 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: ImageUtil.java    From JewelCrawler with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args){
		try {
			boolean load = true;
			load = false;
//			BufferedImage image = ImageIO.read(new URL("http://www.miitbeian.gov.cn/captcha.jpg")) ;
//			if(load){
//				ImageIO.write(image, "jpg", new File("E:/captcha.jpg") );
//			}else{
//				image = ImageIO.read(new File("D:\\爬虫测试\\yzm\\111.png")) ;
//			}
			BufferedImage image = ImageIO.read(new File("D:\\爬虫测试\\yzm\\11.jpg")) ;
//			image = ImageUtil.grayFilter(image);
			image = ImageUtil.binaryFilter(image);
			image = ImageUtil.lineFilter(image);
//			image = ImageUtil.lineFilter(image);
//			image = ImageUtil.line2Filter(image);
//			image = ImageUtil.point2Filter(image);
//			image = ImageUtil.lineFilter(image);
			image = ImageUtil.meanFilter(image);
//			image = ImageUtil.lineFilter(image);
//			image = ImageUtil.binaryFilter(image);
			
			
			File imageFile = new File("E:/captcha5.jpg");
//			imageFile = new File("E:/test/test.jpg");
			
			ImageIO.write(image, "jpg", imageFile);
			
			Tesseract tesseract = Tesseract.getInstance();
			tesseract.setLanguage("eng");
			String code = tesseract.doOCR(imageFile);

			System.out.println(code);
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}