內置了對windows、mac、linux平臺的類庫在jar裏頭,能夠本身加載,無需額外在操做系統安裝,可便攜性強一點。java
<!-- 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一個實例linux
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);