master
周文涛 2 years ago
parent f62c0d1bf3
commit 902ad5c8b7

@ -135,7 +135,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length()); String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult); List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult);
if (resultToPoints.size() > 0) { if (resultToPoints.size() > 0) {
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath); ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath,"red");
ocrIdentifyDetail.setDrawDashedImageUrl(outputImagePath); ocrIdentifyDetail.setDrawDashedImageUrl(outputImagePath);
} }
} }
@ -433,9 +433,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} else { } else {
ocrResultDTO.setTextRate(new BigDecimal(d).setScale(2, RoundingMode.HALF_UP).doubleValue()); ocrResultDTO.setTextRate(new BigDecimal(d).setScale(2, RoundingMode.HALF_UP).doubleValue());
} }
System.out.println("-----------------"); /*System.out.println("-----------------");
System.out.println(failureReason); System.out.println(failureReason);
System.out.println("-----------------"); System.out.println("-----------------");*/
if (StringUtils.isNotBlank(imgPath)) { if (StringUtils.isNotBlank(imgPath)) {
SourceImage sourceImage = new SourceImage(); SourceImage sourceImage = new SourceImage();
sourceImage.setPath(imgPath); sourceImage.setPath(imgPath);
@ -702,7 +702,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
} }
if (hasPoints){ if (hasPoints){
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath); ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath,"green");
imgPath = outputImagePath; imgPath = outputImagePath;
} }
} }
@ -721,6 +721,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
String fieldName = value.getFieldName();//校验的字段名称 String fieldName = value.getFieldName();//校验的字段名称
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断 String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断
String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败 String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败
if (StringUtils.isBlank(fieldName)) {
continue;
}
List<String> fieldNameList = Arrays.asList(fieldName.split(",")); List<String> fieldNameList = Arrays.asList(fieldName.split(","));
text = null; text = null;
//boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet())); //boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet()));
@ -728,7 +731,18 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
//TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确 //TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
List<JSONObject> ocrArray = new ArrayList<>(); List<JSONObject> ocrArray = new ArrayList<>();
for (String s : fieldNameList) { 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) { if (jsonArray != null && jsonArray.size() > 0) {
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class)); ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
} }

@ -3,6 +3,7 @@ package org.jeecg.modules.ocr.utils;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import net.coobird.thumbnailator.Thumbnails; import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.lang.StringUtils;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
@ -21,6 +22,7 @@ import java.util.List;
* @Date 2023/8/16 12:06 * @Date 2023/8/16 12:06
*/ */
public class ImageUtils { public class ImageUtils {
static Color green = new Color(71, 255, 30);
/* /*
Java使ImageIOThumbnailsJava Advanced Imaging APIJAI使ImageIO Java使ImageIOThumbnailsJava Advanced Imaging APIJAI使ImageIO
*/ */
@ -41,7 +43,7 @@ public class ImageUtils {
List<List<Point>> pointList = new ArrayList<>(); List<List<Point>> pointList = new ArrayList<>();
pointList.add(points); pointList.add(points);
pointList.add(points2); 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"); //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<List<Point>> pointList, String outputPath) { public static void drawDashedRectangleOnImages(String imagePath, List<List<Point>> pointList, String outputPath,String color) {
try { try {
// Load the image // Load the image
BufferedImage image = null; BufferedImage image = null;
@ -115,8 +117,12 @@ public class ImageUtils {
} }
for (List<Point> points : pointList) { for (List<Point> points : pointList) {
Graphics2D g2d = image.createGraphics(); Graphics2D g2d = image.createGraphics();
// 设置线的颜色 if (StringUtils.isNotBlank(color) && "green".equals(color)) {
g2d.setColor(new Color(255, 30, 30)); g2d.setColor(green);
}else{
// 设置线的颜色
g2d.setColor(new Color(255, 30, 30));
}
// 定义虚线的样式 // 定义虚线的样式
float[] dash = {5.0f}; float[] dash = {5.0f};
BasicStroke dashed = BasicStroke dashed =

Loading…
Cancel
Save