From 268d6bbdd6bffa34b7ac135eab340a5c04f9810c Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Thu, 16 Oct 2025 16:44:41 +0800 Subject: [PATCH] =?UTF-8?q?ocr=E7=9A=84SmartJavaAI=E7=A6=BB=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 34 +++++++++++++++++++ .../zhgd/xmgl/call/SmartJavaAIOcrCall.java | 18 +++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b5e1ee387..7a46902c1 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,8 @@ 2.6 1.9.6 9.0.30 + win-x86_64 + linux-x86_64 @@ -92,6 +94,38 @@ + + + + ai.djl.pytorch + pytorch-native-cpu + ${djl.platform.linux-x86_64} + 2.5.1 + runtime + + + ai.djl.pytorch + pytorch-jni + 2.5.1-0.32.0 + runtime + + + + ai.djl.tensorflow + tensorflow-native-cpu + ${djl.platform.linux-x86_64} + runtime + 2.16.1 + + + + ai.djl.mxnet + mxnet-native-mkl + ${djl.platform.linux-x86_64} + runtime + 1.9.1 + + com.tencentcloudapi tencentcloud-sdk-java diff --git a/src/main/java/com/zhgd/xmgl/call/SmartJavaAIOcrCall.java b/src/main/java/com/zhgd/xmgl/call/SmartJavaAIOcrCall.java index 4edb3e91b..cb184eaf2 100644 --- a/src/main/java/com/zhgd/xmgl/call/SmartJavaAIOcrCall.java +++ b/src/main/java/com/zhgd/xmgl/call/SmartJavaAIOcrCall.java @@ -14,12 +14,17 @@ import com.alibaba.fastjson.JSONObject; import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.xmgl.call.api.OcrManufacturer; import com.zhgd.xmgl.modules.ocr.entity.OcrConfig; -import com.zhgd.xmgl.util.FileUtils; +import com.zhgd.xmgl.util.PathUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.Base64; @Slf4j @@ -62,8 +67,11 @@ public class SmartJavaAIOcrCall implements OcrManufacturer { recModelConfig.setRecModelEnum(CommonRecModelEnum.PP_OCR_V5_MOBILE_REC_MODEL); //指定识别模型位置,需要更改为自己的模型路径(下载地址请查看文档) // recModelConfig.setRecModelPath("/Users/xxx/Documents/develop/model/ocr/PP-OCRv5_mobile_rec_infer/PP-OCRv5_mobile_rec_infer.onnx"); - FileUtils.getExportTemplateFile("/models/ocr/dict.txt"); - recModelConfig.setRecModelPath(FileUtils.getExportTemplateFile("/models/ocr/PP-OCRv5_mobile_rec_infer.onnx").getAbsolutePath()); + String tmpdir = PathUtil.getBasePath(); + Files.copy(new ClassPathResource("/models/ocr/dict.txt").getInputStream(), Paths.get(tmpdir, "dict.txt"), StandardCopyOption.REPLACE_EXISTING); + Path recModelPath = Paths.get(tmpdir, "PP-OCRv5_mobile_rec_infer.onnx"); + Files.copy(new ClassPathResource("/models/ocr/PP-OCRv5_mobile_rec_infer.onnx").getInputStream(), recModelPath, StandardCopyOption.REPLACE_EXISTING); + recModelConfig.setRecModelPath(recModelPath.toAbsolutePath().toString()); recModelConfig.setDevice(device); recModelConfig.setTextDetModel(getDetectionModel()); return OcrModelFactory.getInstance().getRecModel(recModelConfig); @@ -80,7 +88,9 @@ public class SmartJavaAIOcrCall implements OcrManufacturer { config.setModelEnum(CommonDetModelEnum.PP_OCR_V5_MOBILE_DET_MODEL); //指定模型位置,需要更改为自己的模型路径(下载地址请查看文档) // config.setDetModelPath("/Users/xxx/Documents/develop/model/ocr/PP-OCRv5_mobile_det_infer/PP-OCRv5_mobile_det_infer.onnx"); - config.setDetModelPath(FileUtils.getExportTemplateFile("/models/ocr/PP-OCRv5_mobile_det_infer.onnx").getAbsolutePath()); + Path path = Paths.get(PathUtil.getBasePath(), "PP-OCRv5_mobile_det_infer.onnx"); + Files.copy(new ClassPathResource("/models/ocr/PP-OCRv5_mobile_det_infer.onnx").getInputStream(), path, StandardCopyOption.REPLACE_EXISTING); + config.setDetModelPath(path.toAbsolutePath().toString()); config.setDevice(device); return OcrModelFactory.getInstance().getDetModel(config); }