使用asprise進行圖片驗證碼識別

asprise-java-ocr-api

內置了對windows、mac、linux平臺的類庫在jar裏頭,能夠本身加載,無需額外在操做系統安裝,可便攜性強一點。java

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一個實例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);

doc

相關文章
相關標籤/搜索