自学内容网 自学内容网

java实现OCR图片识别,RapidOcr开源免费

先看一下识别效果(自我感觉很牛逼),比Tess4J +Tesseract省事,这个还需要训练,安装软件、下载语言包什么的 很费事,关键识别率不高

RapidOcr不管文字的横竖,还是斜的都能识别(代码实现放最后)

先引入jar

<!--ocr识别-->
        <dependency>
            <groupId>io.github.mymonstercat</groupId>
            <artifactId>rapidocr</artifactId>
            <version>0.0.7</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--  一般只需要引入一个,CPU端建议使用onnx,移动端建议使用ncnn     -->
        <!--  可前往maven中央仓库https://repo1.maven.org/maven2/io/github/mymonstercat/,查看版本      -->
        <dependency>
            <groupId>io.github.mymonstercat</groupId>
            <artifactId>rapidocr-onnx-platform</artifactId>
            <version>0.0.7</version>
        </dependency>
public static void main(String[] args) {
String temPath = "E:\\cstp3.png";
ParamConfig paramConfig = ParamConfig.getDefaultConfig();
paramConfig.setDoAngle(true);
paramConfig.setMostAngle(true);
InferenceEngine engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4);
// 开始识别
OcrResult ocrResult = engine.runOcr(temPath, paramConfig);
System.out.println("识别内容"+ocrResult.getStrRes().replace("\n", " "));
}

原文地址:https://blog.csdn.net/xujiahn/article/details/140657185

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!