Tesseract-OCR支持中文識別,並且開源和提供全套的訓練工具,是快速低成本開發的首選。
Tess4J則是Tesseract在Java PC上的應用
Tesseract的OCR引擎最先由HP實驗室於1985年開始研發,至1995年時已經成為OCR業內最准確的三款識別引擎之一。然而,HP不久便決定放棄OCR業務,Tesseract也從此塵封。
數年以后,HP意識到,與其將Tesseract束之高閣,不如貢獻給開源軟件業,讓其重煥新生--2005年,Tesseract由美國內華達州信息技術研究所獲得,並求諸於Google對Tesseract進行改進、消除Bug、優化工作。
Tesseract目前已作為開源項目發布在Google Project,其項目主頁在這里查看。
<!-- https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j -->
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.4.0</version>
</dependency>
實現代碼開發:
File imageFile = new File("input dir/shuzi.png"); Tesseract tessreact = new Tesseract(); //需要指定訓練集 訓練集到 https://github.com/tesseract-ocr/tessdata 下載。
tessreact.setDatapath("E:\\itcast\\env\\tess4j\\tessdata"); //注意 默認是英文識別,如果做中文識別,需要單獨設置。
tessreact.setLanguage("chi_sim"); try { String result = tessreact.doOCR(imageFile); System.out.println(result); } catch (TesseractException e) { System.err.println(e.getMessage()); }