tess4j 官方最新demo运行成功记录

运行结果

在这里插入图片描述

安装步骤

  1. 电脑必须安装“tesseract-ocr”应用程序,安装成功后,到相应目录运行。
    电脑应用程序是提供给JAVA程序调用的
  1. 配置环境变量(此处省略),jar包里面封装,必须按照名字来(可修改,不建议修改)。假如CMD运行成功,但是java无法调用,建议重启eclipse,或者重启电脑。
    在这里插入图片描述
    在这里插入图片描述
  1. 安装dll文件必须的 运行库
    在这里插入图片描述
    在这里插入图片描述
  1. main方法测试,或者直接在使用junit直接运行demo测试代码块。(需要配置)
    main测试
    Junit测试
package net.sourceforge.tess4j;

import java.io.File;

public class Test {
	private final static String testResourcesDataPath = "src/test/resources/test-data";
	
	public static void main(String[] args) {
		
		String datapath = System.getenv("TESSDATA_PREFIX");
		System.out.println(datapath);
		String JAVA_HOME = System.getenv("JAVA_HOME");
		System.out.println(JAVA_HOME);
		 
		File imageFile = new File(testResourcesDataPath, "eurotext.tif");
		ITesseract instance = new Tesseract();
		instance.setDatapath("D:\\Program Files\\Tesseract-OCR\\tessdata");
		try {
			String result = instance.doOCR(imageFile);
			System.out.println(result);
		} catch (TesseractException e) {
			System.err.println(e.getMessage());
		}
    }
}

所需工具下载地址

tesseract桌面应用程序:https://github.com/UB-Mannheim/tesseract/wiki
微软常用运行库合集:http://www.pc6.com/softview/SoftView_104246.html
tess4j github:https://github.com/nguyenq/tess4j
字体库:https://github.com/tesseract-ocr/tessdata
博主测试工具代码整体打包:https://download.csdn.net/download/qq471208499/12086601

可能出现错误

  1. “找不到指定模块” :运行库不匹配
  2. “tess4j Failed loading language ‘eng’”:字体库不存在
发布了16 篇原创文章 · 获赞 10 · 访问量 2271
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章