運行結果
安裝步驟
- 電腦必須安裝“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’”:字體庫不存在