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