asprise-java-ocr-api
内置了对windows、mac、linux平台的类库在jar里头,可以自己加载,无需额外在操作系统安装,可便携性强一点。
maven
<!-- https://mvnrepository.com/artifact/com.asprise.ocr/java-ocr-api -->
<dependency>
<groupId>com.asprise.ocr</groupId>
<artifactId>java-ocr-api</artifactId>
<version>15.3.0.3</version>
</dependency>
调用
public static String recognize(BufferedImage image) {
Ocr.setUp();
Ocr ocr = new Ocr();
ocr.startEngine("eng", Ocr.SPEED_FASTEST);
String result = ocr.recognize(image,com.asprise.ocr.Ocr.RECOGNIZE_TYPE_ALL, com.asprise.ocr.Ocr.OUTPUT_FORMAT_PLAINTEXT,0,null);
ocr.stopEngine();
return result;
}
Ocr不是线程安全的,因此多线程的话,每个线程自己new一个实例
测试
ClassLoader classLoader = getClass().getClassLoader();
String path = classLoader.getResource("xxxx.jpg").getPath();
BufferedImage img = ImageIO.read(new File(path));
String result = recognize(img);
System.out.println(result);