运行结果
安装步骤
- 电脑必须安装“tesseract-ocr”应用程序,安装成功后,到相应目录运行。
电脑应用程序是提供给JAVA程序调用的
- 配置环境变量(此处省略),jar包里面封装,必须按照名字来(可修改,不建议修改)。假如CMD运行成功,但是java无法调用,建议重启eclipse,或者重启电脑。
- 安装dll文件必须的 运行库
- main方法测试,或者直接在使用junit直接运行demo测试代码块。(需要配置)
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
可能出现错误
- “找不到指定模块” :运行库不匹配
- “tess4j Failed loading language ‘eng’”:字体库不存在