SmartJavaAIOrc的bug修改

This commit is contained in:
guoshengxiong 2025-08-05 15:18:40 +08:00
parent 098bb63b31
commit 73a2fc37b2
2 changed files with 5 additions and 4 deletions

View File

@ -85,7 +85,7 @@ public class BaiDuOrcCall implements OcrManufacturer {
log.info("百度AI 手写文字识别,result:{}", result);
OcrResult ocrResult = JSONObject.parseObject(result, OcrResult.class);
if (CollUtil.isNotEmpty(ocrResult.getWords_result())) {
return ocrResult.getWords_result().stream().map(OcrResult.WordsResult::getWords).collect(Collectors.joining());
return ocrResult.getWords_result().stream().map(wordsResult -> wordsResult.getWords()+"\n").collect(Collectors.joining());
}
return null;
}

View File

@ -44,7 +44,7 @@ public class SmartJavaAIOrcCall implements OcrManufacturer {
public String ocrHandwriting(String base64Img) {
try {
OcrCommonRecModel recModel = getRecModel();
OcrInfo ocrInfo = recModel.recognize(Base64.getDecoder().decode(base64Img), new OcrRecOptions());
OcrInfo ocrInfo = recModel.recognize(Base64.getDecoder().decode(base64Img.contains(",") ? base64Img.substring(base64Img.indexOf(",") + 1) : base64Img), new OcrRecOptions());
log.info("OCR识别结果{}", JSONObject.toJSONString(ocrInfo));
return ocrInfo != null ? ocrInfo.getFullText() : null;
} catch (Exception e) {
@ -63,7 +63,8 @@ public class SmartJavaAIOrcCall 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");
recModelConfig.setRecModelPath(Fileutils.getExportTemplateFile("models/ocr/PP-OCRv5_mobile_rec_infer.onnx").getAbsolutePath());
Fileutils.getExportTemplateFile("/models/ocr/dict.txt");
recModelConfig.setRecModelPath(Fileutils.getExportTemplateFile("/models/ocr/PP-OCRv5_mobile_rec_infer.onnx").getAbsolutePath());
recModelConfig.setDevice(device);
recModelConfig.setTextDetModel(getDetectionModel());
return OcrModelFactory.getInstance().getRecModel(recModelConfig);
@ -80,7 +81,7 @@ public class SmartJavaAIOrcCall 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-PP-OCRv5_mobile_det_infer.onnx").getAbsolutePath());
config.setDetModelPath(Fileutils.getExportTemplateFile("/models/ocr/PP-OCRv5_mobile_det_infer.onnx").getAbsolutePath());
config.setDevice(device);
return OcrModelFactory.getInstance().getDetModel(config);
}