java使用开源类库Tesseract实现图片识别

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());
        }

猜你喜欢

转载自www.cnblogs.com/alexzhang92/p/11488679.html