ai

rapidocr Java sdk调用

依赖:


            <dependency>
                <groupId>io.github.mymonstercat</groupId>
                <artifactId>rapidocr</artifactId>
                <version>0.0.7</version>
            </dependency>

            <dependency>
                <groupId>io.github.mymonstercat</groupId>
                <artifactId>rapidocr-onnx-platform</artifactId>
                <version>0.0.7</version>
            </dependency>

java:

    private static volatile InferenceEngine ocrEngine;


    /**
     * 初始化ocr引擎
     */
    private static void initEngine() {
        if (ocrEngine == null) {
            synchronized (RapidocrUtils.class) {
                if (ocrEngine == null) {
                    ocrEngine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4);
                }
            }
        }
    }
 /**
     * ocr
     *
     * @param absolutePath
     * @return
     */
    public static OcrResult runOcrImg(String absolutePath) {
        initEngine();
        //非线程安全加同步
        synchronized (RapidocrUtils.class) {
            try {
                return ocrEngine.runOcr(absolutePath);
            } catch (Exception e) {
                log.error("rapidocr异常", e);

                return null;
            }

        }
    }

关于作者

程序员,软件工程师,java, golang, rust, c, python,vue, Springboot, mybatis, mysql,elasticsearch, docker, maven, gcc, linux, ubuntu, centos, axum,llm, paddlepaddle, onlyoffice,minio,银河麒麟,中科方德,rpm