diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java index e1bafc2..9aa7d23 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java @@ -135,7 +135,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult); if (resultToPoints.size() > 0) { - ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath); + ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath,"red"); ocrIdentifyDetail.setDrawDashedImageUrl(outputImagePath); } } @@ -433,9 +433,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl fieldNameList = Arrays.asList(fieldName.split(",")); text = null; //boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet())); @@ -728,7 +731,18 @@ public class OcrIdentifyServiceImpl extends ServiceImpl ocrArray = new ArrayList<>(); for (String s : fieldNameList) { - JSONArray jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s); + JSONArray jsonArray = new JSONArray(); + if (Arrays.asList("医生名称","姓名","医生").contains(s)) { + for (String s1 : Arrays.asList("医生名称", "姓名", "医生")) { + JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1); + if (CollectionUtils.isNotEmpty(semantic_result)) { + jsonArray.addAll(semantic_result); + } + } + }else{ + jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s); + } + if (jsonArray != null && jsonArray.size() > 0) { ocrArray.addAll(jsonArray.toJavaList(JSONObject.class)); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java index 3e16eeb..b06c155 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/ImageUtils.java @@ -3,6 +3,7 @@ package org.jeecg.modules.ocr.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import net.coobird.thumbnailator.Thumbnails; +import org.apache.commons.lang.StringUtils; import javax.imageio.ImageIO; import java.awt.*; @@ -21,6 +22,7 @@ import java.util.List; * @Date 2023/8/16 12:06 */ public class ImageUtils { + static Color green = new Color(71, 255, 30); /* 当涉及到图像压缩时,Java中有几个可以使用的库,比如ImageIO、Thumbnails和Java Advanced Imaging API(JAI)。以下是一个使用ImageIO库来进行图片压缩的示例: */ @@ -41,7 +43,7 @@ public class ImageUtils { List> pointList = new ArrayList<>(); pointList.add(points); pointList.add(points2); - drawDashedRectangleOnImages("http://47.103.213.109:8072/files/nfs/ocr/shared_directory/fdd50089f33e4b4391b8c88b6299735b/a86aff69fc3ff5397d038b4dbcde6165.jpeg", pointList, "C:\\Users\\Denim\\Desktop\\output_image.png"); + drawDashedRectangleOnImages("http://47.103.213.109:8072/files/nfs/ocr/shared_directory/fdd50089f33e4b4391b8c88b6299735b/a86aff69fc3ff5397d038b4dbcde6165.jpeg", pointList, "C:\\Users\\Denim\\Desktop\\output_image.png","red"); //drawDashedRectangleOnImage("http://47.103.213.109:8072/files/nfs/ocr/shared_directory/fdd50089f33e4b4391b8c88b6299735b/a86aff69fc3ff5397d038b4dbcde6165.jpeg", points, "C:\\Users\\Denim\\Desktop\\output_image.png"); } @@ -104,7 +106,7 @@ public class ImageUtils { } - public static void drawDashedRectangleOnImages(String imagePath, List> pointList, String outputPath) { + public static void drawDashedRectangleOnImages(String imagePath, List> pointList, String outputPath,String color) { try { // Load the image BufferedImage image = null; @@ -115,8 +117,12 @@ public class ImageUtils { } for (List points : pointList) { Graphics2D g2d = image.createGraphics(); - // 设置线的颜色 - g2d.setColor(new Color(255, 30, 30)); + if (StringUtils.isNotBlank(color) && "green".equals(color)) { + g2d.setColor(green); + }else{ + // 设置线的颜色 + g2d.setColor(new Color(255, 30, 30)); + } // 定义虚线的样式 float[] dash = {5.0f}; BasicStroke dashed =