pom文件报错_解决mac下tess4j文字识别报错问题
tesseract想必大家都知道(不知道自個查去),tess4j是java對tesseract的封裝。
Description: A Java JNA wrapper for Tesseract OCR API. Tess4J is released and distributed under the Apache License, v2.0. ## Features: The library provides optical character recognition (OCR) support for: TIFF, JPEG, GIF, PNG, and BMP image formats Multi-page TIFF images PDF document format
python調用tesseract的案例有很多,網上一搜一大堆,在此也不細說了。
最近有個小需求,需要使用java來提取圖片里的文字,首先想到的就是用tess4j,其實tess4j的使用也比較簡單,在pom里引入
<dependency><groupId>net.sourceforge.tess4j</groupId><artifactId>tess4j</artifactId><version>4.3.1</version></dependency>測試方法:
@Testpublic void test1() {String path = ""; //我的項目存放路徑File file = new File("WechatIMG1436.png");ITesseract instance = new Tesseract();File directory = new File(path);String courseFile = null;try {courseFile = directory.getCanonicalPath();} catch (IOException e) {e.printStackTrace();}//設置訓練庫的位置instance.setDatapath("/tessdata");instance.setLanguage("chi_sim");//chi_sim :簡體中文, eng 根據需求選擇語言庫String result = null;try {long startTime = System.currentTimeMillis();result = instance.doOCR(file);long endTime = System.currentTimeMillis();System.out.println("Time is:" + (endTime - startTime) + " 毫秒");} catch (TesseractException e) {e.printStackTrace();}System.out.println("result: ");System.out.println(result);}比較奇特的是上面一段代碼在windows里是完全沒問題的,在mac下就完全執行不了
tess4j報錯信息google了半天,大多在重復瞎扯,什么一會java不支持tesseract都能扯出來,后面在Stack Overflow上看到有人在python下調用tesseract也會報這個錯,然后他們的解決方式是在代碼里加上
import locale locale.setlocale(locale.LC_ALL, 'C')其實就是增加一個環境變量,那么我在java里執行前也加上這個環境變量不就行了。。so,在idea里加了個參數,果然好了。。
下面是一張圖片的測試結果;
下面是我在python下測試的輸出:
可以看到識別結果是有區別的,不過這個區別應該是模型文件的不同導致,在java里面指定了一個單獨下載的模型文件。
總結
以上是生活随笔為你收集整理的pom文件报错_解决mac下tess4j文字识别报错问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python分位数回归模型_如何理解分位
- 下一篇: 油价三连降:今晚国内油价将下调,加满一箱