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