一、下載下傳
1.進入官網下載下傳頁面
https://sourceforge.net/projects/tess4j/ 2.點選download
二、使用Tess4J
1.将dist和lib下的包導入java項目
public class OCRDemo {
public static void main(String[] args) {
try {
double start=System.currentTimeMillis();
File imageFile = new File("C:\\Users\\dan\\Desktop\\12345.png");//圖檔位置
ITesseract instance = new Tesseract();
//instance.setDatapath("");//設定tessdata位置
instance.setLanguage("chi_sim");//選擇字庫檔案
String result = instance.doOCR(imageFile);//開始識别
double end=System.currentTimeMillis();
System.out.println(result);//列印圖檔内容
System.out.println("耗時"+(end-start)/1000+" s");
} catch (TesseractException e) {
e.printStackTrace();
}
}
}
注意事項:
①如果tessdata沒有放入根目錄,務必設定teedata的位置
instance.setDatapath("");//設定tessdata位置
②選擇字庫檔案不需要寫上字尾,預設 tessdata 包中可能沒有 chi_sim 這個中文包,需要自己下載下傳
https://github.com/tesseract-ocr/tessdata三、運作結果
官方字庫識别率還是偏低的,如果對精度要求高的話需要自己訓練字庫了