From 78681dcdc633d41f046e251f494477ada315440e Mon Sep 17 00:00:00 2001 From: wangxun Date: Tue, 22 Apr 2025 14:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=A4=96=E6=B5=81=E7=A8=8B=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulator/service/HikVisionService.java | 3 + .../service/impl/AlgorithmServiceImpl.java | 31 +- .../service/impl/HikVisionServiceImpl.java | 567 +++++++----------- 3 files changed, 240 insertions(+), 361 deletions(-) diff --git a/src/main/java/com/inspect/simulator/service/HikVisionService.java b/src/main/java/com/inspect/simulator/service/HikVisionService.java index 0fbd661..7f282d6 100644 --- a/src/main/java/com/inspect/simulator/service/HikVisionService.java +++ b/src/main/java/com/inspect/simulator/service/HikVisionService.java @@ -20,4 +20,7 @@ public interface HikVisionService { //图谱解析 ResponseEntity irPicAnalyse(String analyseRequest); + + InfraredInfo calculatePicture(InfraPictureInfo infraPictureInfo,String picData); + } diff --git a/src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java b/src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java index cf9a851..7c13156 100644 --- a/src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java +++ b/src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java @@ -3,11 +3,15 @@ package com.inspect.simulator.service.impl; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.inspect.simulator.constant.Color; +import com.inspect.simulator.domain.Infrared.Coordinate; +import com.inspect.simulator.domain.Infrared.InfraPictureInfo; +import com.inspect.simulator.domain.Infrared.InfraredInfo; import com.inspect.simulator.domain.algorithm.in.AnalyseReqItem; import com.inspect.simulator.domain.algorithm.in.AnalyseRequest; import com.inspect.simulator.domain.algorithm.out.AnalyseResItem; import com.inspect.simulator.domain.algorithm.out.AnalyseResPoint; import com.inspect.simulator.domain.algorithm.out.AnalyseResult; +import com.inspect.simulator.domain.basedata.BasedataEqpBookChannel; import com.inspect.simulator.domain.result.PatrolPresetPos; import com.inspect.simulator.mapper.PatrolPresetPosMapper; import com.inspect.simulator.service.AlgorithmService; @@ -38,6 +42,10 @@ public class AlgorithmServiceImpl implements AlgorithmService { @Resource private PatrolPresetPosMapper patrolPresetPosMapper; + + @Resource + private HikVisionServiceImpl hikVisionService; + @Override public String filterPicAnalyse(String analyseRequestStr) { log.info(Color.MAGENTA + "[FILTER] filterPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr); @@ -160,7 +168,7 @@ public class AlgorithmServiceImpl implements AlgorithmService { final String patrolPointId = analyseReqItem.getObjectId(); // 根据patrol_point_id查询数据表patrol_preset_pos,得到channel_id,根据channel_id查询数据表basedata_eqpbook_channel,得到channel_content List patrolPresetPosList = patrolPresetPosMapper.selectPatrolPresetPosByPatrolPointId(patrolPointId); - if(patrolPresetPosList == null || patrolPresetPosList.isEmpty()) { + if (patrolPresetPosList == null || patrolPresetPosList.isEmpty()) { log.error("[INFRARED] irPicAnalyse: patrolPresetPosList empty!"); return "{\"code\":\"203\"}"; } @@ -168,7 +176,13 @@ public class AlgorithmServiceImpl implements AlgorithmService { final String channelContent = patrolPresetPos.getChannelContent(); log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: channelContent={}" + Color.END, channelContent); + String[] imageUrlList = analyseReqItem.getImageUrlList(); // 调用红外算法 + InfraPictureInfo infraPictureInfo = new InfraPictureInfo(); + infraPictureInfo.setImgType(3); + infraPictureInfo.setFilePath(imageUrlList[0]); + InfraredInfo infraredInfo = hikVisionService.calculatePicture(infraPictureInfo,channelContent); + final String feedBackHostIp = analyseRequest.getRequestHostIp(); final String feedBackPort = analyseRequest.getRequestHostPort(); @@ -178,10 +192,19 @@ public class AlgorithmServiceImpl implements AlgorithmService { AnalyseResult analyseResult = new AnalyseResult(); analyseResult.setRequestId(analyseRequest.getRequestId()); AnalyseResPoint analyseResPoint = new AnalyseResPoint(); - analyseResPoint.setValue("0"); - analyseResPoint.setConf("0.85"); +// analyseResPoint.setValue("0"); +// analyseResPoint.setConf("0.85"); + + if (String.valueOf((double) infraredInfo.getFrameMax()) != null) { + analyseResPoint.setValue("0");//成功 + } else { + analyseResPoint.setValue("1");//失败 + } + analyseResPoint.setConf(String.format("%.2f", (double) infraredInfo.getFrameMax())); + analyseResPoint.setResImageUrl(infraredInfo.getOutPath()); + analyseResPoint.setCode("2000"); - analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]); +// analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]); List analyseResPoints = new ArrayList<>(); analyseResPoints.add(analyseResPoint); AnalyseResItem analyseResItem = new AnalyseResItem(); diff --git a/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java b/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java index 094147d..c9d49eb 100644 --- a/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java +++ b/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java @@ -23,6 +23,7 @@ import com.inspect.simulator.hikVision.utils.jna.HikVisionUtils; import com.inspect.simulator.hikVision.utils.jna.HCNetSDK; import com.inspect.simulator.mapper.BasedataEqpBookChannelMapper; import com.inspect.simulator.service.HikVisionService; +import com.inspect.simulator.service.remote.AnalysisRemoteService; import com.inspect.simulator.utils.HttpClientUtils; import com.inspect.simulator.utils.sftp.SftpClient; import com.sun.jna.ptr.IntByReference; @@ -90,6 +91,8 @@ public class HikVisionServiceImpl implements HikVisionService { @Value("${file.ftpUrlPort:test}") private Integer ftpUrlPort; + @Value("${file.infraredPath:null}") + private String infraredPath; @Resource private SftpClient sftpClient; @@ -97,6 +100,9 @@ public class HikVisionServiceImpl implements HikVisionService { @Resource private BasedataEqpBookChannelMapper basedataEqpBookChannelMapper; + @Resource + private AnalysisRemoteService analysisRemoteService; + // @Override // public AjaxResult login(NvrInfo nvrInfo) { // return login_V40(nvrInfo); @@ -391,18 +397,6 @@ public class HikVisionServiceImpl implements HikVisionService { //最大最小温度值 infraredInfo.setMaxTemp(maxTemp); infraredInfo.setMinTemp(minTemp); - if (ObjectUtil.isNotEmpty(coordinate)) { - // 获取指定坐标的温度 -// InfraredInfo infraredInfo1 = PointTemperatureShow(coordinate, width, height, temperatureMatrix); -// infraredInfo.setPointTemperature(infraredInfo1.getPointTemperature()); -// -// //框选的矩阵温度数值 -// InfraredInfo infraredInfo2 = matrixTemperatureShow(coordinate, temperatureMatrix); -// infraredInfo.setFrameAverage(infraredInfo2.getFrameAverage()); -// infraredInfo.setFrameMax(infraredInfo2.getFrameMax()); -// infraredInfo.setFrameMin(infraredInfo2.getFrameMin()); - - } // 3. 解析保留的数据(环境参数等) if (buffer.remaining() >= 18) { // 至少需要18字节(4+4+1+4+1+4) // 3.1 辐射率 (4字节 float) @@ -520,7 +514,6 @@ public class HikVisionServiceImpl implements HikVisionService { // coordinate.setSecondX(x2); // coordinate.setSecondY(y2); // } - if (coordinate.getSecondX() != 0 && coordinate.getSecondY() != 0) { for (int j = coordinate.getFirstY(); j <= coordinate.getSecondY(); j++) { // 列 if (j < 0 || j >= temperatureMatrix.length) continue; @@ -600,241 +593,38 @@ public class HikVisionServiceImpl implements HikVisionService { } } - //图片标注__nvr -// public String ImageOverlaysNvr(Coordinate coordinate, InfraredInfo infraredInfo) { -// -// Coordinate[] coordinates = coordinate.getCoordinates(); -// -// Date date = new Date(); -// SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); -// String markPicName = sf.format(date); -// // 图片路径(请替换为实际路径) -// String imagePath = coordinate.getFilePath(); -// // 获取文件名(不含扩展名) -// File file = new File(imagePath); -// String fileName = file.getName(); -// String pureName = fileName.substring(0, fileName.lastIndexOf('.')); -// String filename = picPath; -// String outputPath = picPath + pureName + "_" + markPicName + ".jpg"; -// //判断路径是否存在 -// File filePath = new File(filename); -// if (!filePath.exists()) { -// //不存在,创建目录 -// filePath.mkdirs(); -// } -// try { -// // 加载原始图片 -// BufferedImage originalImage = ImageIO.read(new File(imagePath)); -// if (originalImage == null) { -// System.err.println("无法加载图片: " + imagePath); -// return null; -// } -// -// // 创建可编辑的图片副本 -// BufferedImage annotatedImage = new BufferedImage( -// originalImage.getWidth(), -// originalImage.getHeight(), -// BufferedImage.TYPE_INT_RGB -// ); -// // 绘制原始图片 -// Graphics2D g2d = annotatedImage.createGraphics(); -// g2d.drawImage(originalImage, 0, 0, null); -// -// // 设置标注样式 -// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); -// Font font = new Font("微软雅黑", Font.BOLD, 17); -// -// for (Coordinate c : coordinates) { -// -// //点标注 -// if (c.getFirstX() != null && c.getFirstY() != null && c.getSecondX() == null && c.getSecondY() == null) { -// g2d.setFont(font); -// // 标注点坐标 -// g2d.setColor(Color.GREEN); -// int x = c.getFirstX(); -// int y = c.getFirstY(); -// -// // 确保坐标在图片范围内 -// if (x >= 0 && x < originalImage.getWidth() && -// y >= 0 && y < originalImage.getHeight()) { -// // 绘制点(用实心圆表示) -// g2d.fillOval(x - 3, y - 3, 6, 6); -// coordinate.setFirstX(x); -// coordinate.setFirstY(y); -// InfraredInfo drawStringPoint = PointTemperatureShow(coordinate, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); -// // 添加坐标标签 -// g2d.drawString("(" + String.format("%.2f", drawStringPoint.getPointTemperature()) + ")", x + 8, y - 8); -// } -// } -// -// //矩阵标注 -// if (c.getSecondX() != null && c.getSecondY() != null) { -// // 标注矩形(每两个点确定一个矩形) -// g2d.setColor(Color.RED); -// int x1 = c.getFirstX(); -// int y1 = c.getFirstY(); -// int x2 = c.getSecondX(); -// int y2 = c.getSecondY(); -// -// // 确保坐标在图片范围内 -// if (x1 >= 0 && x1 < originalImage.getWidth() && y1 >= 0 && y1 < originalImage.getHeight() && -// x2 >= 0 && x2 < originalImage.getWidth() && y2 >= 0 && y2 < originalImage.getHeight()) { -// -// // 确保x1,y1是左上角,x2,y2是右下角 -// int rectX = Math.min(x1, x2); -// int rectY = Math.min(y1, y2); -// int width = Math.abs(x2 - x1); -// int height = Math.abs(y2 - y1); -// // 绘制矩形 -// g2d.drawRect(rectX, rectY, width, height); -// -// coordinate.setFirstX(x1); -// coordinate.setFirstY(y1); -// coordinate.setSecondX(x2); -// coordinate.setSecondY(y2); -// -// InfraredInfo drawStringMatrix = matrixTemperatureShow(coordinate, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); -// infraredInfo.setFrameMax(Math.round(drawStringMatrix.getFrameMax() * 100) / 100f); -// // 添加矩形标签 -// g2d.drawString("平均温度:" + String.format("%.2f", drawStringMatrix.getFrameAverage()) + -// "最高温度:" + String.format("%.2f", drawStringMatrix.getFrameMax()) + -// "最低温度:" + String.format("%.2f", drawStringMatrix.getFrameMin()), rectX + 5, rectY + 15); -// -// } -// } -// } -// g2d.dispose(); -// // 保存标注后的图片 -// File outputFile = new File(outputPath); -// // 确保输出目录存在 -// outputFile.getParentFile().mkdirs(); -// -// ImageIO.write(annotatedImage, "jpg", outputFile); -//// System.out.println("标注后的图片已保存到: " + outputPath); -// -// } catch (IOException e) { -// System.err.println("处理图片时出错: " + e.getMessage()); -// e.printStackTrace(); -// } -// return outputPath; -// } - - //图片标注_iVS1800 - public String ImageOverlaysIvs(InfraPictureInfo infraPictureInfo, InfraredInfo infraredInfo) { - - List coordinates = infraPictureInfo.getCoordinates(); - - Date date = new Date(); - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String markPicName = sf.format(date); - // 图片路径(请替换为实际路径) - String imagePath = infraPictureInfo.getFilePath(); - // 获取文件名(不含扩展名) - File file = new File(imagePath); - String fileName = file.getName(); - String pureName = fileName.substring(0, fileName.lastIndexOf('.')); - String filename = picPath; - String outputPath = picPath + pureName + "_" + markPicName + ".jpg"; - //判断路径是否存在 - File filePath = new File(filename); - if (!filePath.exists()) { - //不存在,创建目录 - filePath.mkdirs(); + //NVR返回字符串根据宽高,获取温度矩阵 + private float[][] getMatrix(Integer picWidth, Integer height) { + float[][] tempMatrix = new float[height][picWidth]; + String temperatureStr = "11.00,12.00,12.00,14.00,15.00,22.00,33.00,22.00"; + String[] tempValues = temperatureStr.split(","); + float[] temps = new float[tempValues.length]; + for (int i = 0; i < tempValues.length; i++) { + temps[i] = Float.parseFloat(tempValues[i]); } - try { - // 加载原始图片 - InputStream inputStreamPath = downloadFtp(imagePath); - if (inputStreamPath == null) { - System.out.println("无法加载图片: " + imagePath); - } - BufferedImage originalImage = ImageIO.read(inputStreamPath); - if (originalImage == null) { - System.err.println("无法加载图片: " + imagePath); - return null; - } - - // 创建可编辑的图片副本 - BufferedImage annotatedImage = new BufferedImage( - originalImage.getWidth(), - originalImage.getHeight(), - BufferedImage.TYPE_INT_RGB - ); - // 绘制原始图片 - Graphics2D g2d = annotatedImage.createGraphics(); - g2d.drawImage(originalImage, 0, 0, null); - - // 设置标注样式 - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - Font font = new Font("微软雅黑", Font.BOLD, 17); - for (Coordinate c : coordinates) { - g2d.setFont(font); - //矩阵标注 - if (c.getSecondX() != null && c.getSecondY() != null) { - // 标注矩形(每两个点确定一个矩形) - g2d.setColor(Color.WHITE); - int x1 = c.getFirstX(); - int y1 = c.getFirstY(); - int x2 = c.getSecondX(); - int y2 = c.getSecondY(); - - // 确保坐标在图片范围内 - if (x1 >= 0 && x1 < originalImage.getWidth() && y1 >= 0 && y1 < originalImage.getHeight() && - x2 >= 0 && x2 < originalImage.getWidth() && y2 >= 0 && y2 < originalImage.getHeight()) { - - // 确保x1,y1是左上角,x2,y2是右下角 - int rectX = Math.min(x1, x2); - int rectY = Math.min(y1, y2); - int width = Math.abs(x2 - x1); - int height = Math.abs(y2 - y1); - // 绘制矩形 - g2d.drawRect(rectX, rectY, width, height); - - infraPictureInfo.setFirstX(x1); - infraPictureInfo.setFirstY(y1); - infraPictureInfo.setSecondX(x2); - infraPictureInfo.setSecondY(y2); - // 添加矩形标签 - //图片路径取值 - String[] dividePath = Paths.get(imagePath).getFileName().toString().replaceAll("(?i)\\.jpg$", "").split("_"); -// String max = dividePath[dividePath.length - 3]; // 最大值 -// String min = dividePath[dividePath.length - 2]; // 最小值 - String max = dividePath[dividePath.length - 1]; // 最大值 - infraredInfo.setFrameMax(Float.parseFloat(max)); -// g2d.drawString("平均温度:" +avg + "最高温度:" + max + "最低温度:" + min, rectX + 5, rectY + 15); - - String line1 = "最高温度:" + max; -// String line2 = "最高温度:" + max; -// String line3 = "最低温度:" + min; - - g2d.drawString(line1, rectX + 5, rectY + 15); -// g2d.drawString(line2, rectX + 5, rectY + 30); -// g2d.drawString(line3, rectX + 5, rectY + 45); - } + // 初始化矩阵,默认填充0.00 + for (int i = 0; i < height; i++) { + for (int j = 0; j < picWidth; j++) { + tempMatrix[i][j] = 0.00f; + } + } + // 按行优先填充数据 + int index = 0; + for (int i = 0; i < height; i++) { + for (int j = 0; j < picWidth; j++) { + if (index < temps.length) { + tempMatrix[i][j] = temps[index++]; + } else { + break; // 数据用完,剩余保持0.00 } } - g2d.dispose(); - - ByteArrayOutputStream os = new ByteArrayOutputStream(); - ImageIO.write(annotatedImage, "jpg", os); - InputStream inputStream = new ByteArrayInputStream(os.toByteArray()); - - picFtp(outputPath, inputStream, ftpUrlAddress, ftpUrlPort, ftpUrlAccount, ftpUrlPwd); - -// // 保存标注后的图片 -// File outputFile = new File(outputPath); -// // 确保输出目录存在 -// outputFile.getParentFile().mkdirs(); -// ImageIO.write(annotatedImage, "jpg", outputFile); - } catch (IOException e) { - System.err.println("处理图片时出错: " + e.getMessage()); - e.printStackTrace(); } - return outputPath; + return tempMatrix; } - //图片标注__无人机 - public String ImageOverlaysUav(InfraPictureInfo infraPictureInfo, InfraredInfo infraredInfo) { + //图片标注__无人机/ivs1800/nvr + public String ImageOverlays(InfraPictureInfo infraPictureInfo, InfraredInfo infraredInfo) { List coordinates = infraPictureInfo.getCoordinates(); @@ -859,15 +649,10 @@ public class HikVisionServiceImpl implements HikVisionService { InputStream inputStreamPath = downloadFtp(imagePath); if (inputStreamPath == null) { System.out.println("无法加载图片: " + imagePath); + return null; } // 加载原始图片 -// BufferedImage originalImage = ImageIO.read(new File(imagePath)); BufferedImage originalImage = ImageIO.read(inputStreamPath); - if (originalImage == null) { - System.err.println("无法加载图片: " + imagePath); - return null; - } - // 创建可编辑的图片副本 BufferedImage annotatedImage = new BufferedImage( originalImage.getWidth(), @@ -877,88 +662,155 @@ public class HikVisionServiceImpl implements HikVisionService { // 绘制原始图片 Graphics2D g2d = annotatedImage.createGraphics(); g2d.drawImage(originalImage, 0, 0, null); - // 设置标注样式 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("微软雅黑", Font.BOLD, 17); - for (Coordinate c : coordinates) { - - //点标注 - if (c.getFirstX() != null && c.getFirstY() != null && c.getSecondX() == null && c.getSecondY() == null) { - g2d.setFont(font); - // 标注点坐标 - g2d.setColor(Color.GREEN); - int x = c.getFirstX(); - int y = c.getFirstY(); - - // 确保坐标在图片范围内 - if (x >= 0 && x < originalImage.getWidth() && - y >= 0 && y < originalImage.getHeight()) { - // 绘制点(用实心圆表示) - g2d.fillOval(x - 3, y - 3, 6, 6); - infraPictureInfo.setFirstX(x); - infraPictureInfo.setFirstY(y); + if (infraPictureInfo.getImgType() == 3) { + for (Coordinate c : coordinates) { + //点标注 + if (c.getFirstX() != null && c.getFirstY() != null && c.getSecondX() == null && c.getSecondY() == null) { + g2d.setFont(font); + // 标注点坐标 + g2d.setColor(Color.GREEN); + int x = c.getFirstX(); + int y = c.getFirstY(); + + // 确保坐标在图片范围内 + if (x >= 0 && x < originalImage.getWidth() && + y >= 0 && y < originalImage.getHeight()) { + // 绘制点(用实心圆表示) + g2d.fillOval(x - 3, y - 3, 6, 6); + infraPictureInfo.setFirstX(x); + infraPictureInfo.setFirstY(y); // InfraredInfo drawStringPoint = PointTemperatureShow(c, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); // // 添加坐标标签 // g2d.drawString("(" + String.format("%.2f", drawStringPoint.getPointTemperature()) + ")", x + 8, y - 8); + } + } + //矩阵标注 + if (c.getSecondX() != null && c.getSecondY() != null) { + // 标注矩形(每两个点确定一个矩形) + g2d.setColor(Color.WHITE); + int x1 = c.getFirstX(); + int y1 = c.getFirstY(); + int x2 = c.getSecondX(); + int y2 = c.getSecondY(); + + // 确保坐标在图片范围内 + if (x1 >= 0 && x1 < originalImage.getWidth() && y1 >= 0 && y1 < originalImage.getHeight() && + x2 >= 0 && x2 < originalImage.getWidth() && y2 >= 0 && y2 < originalImage.getHeight()) { + + // 确保x1,y1是左上角,x2,y2是右下角 + int rectX = Math.min(x1, x2); + int rectY = Math.min(y1, y2); + int width = Math.abs(x2 - x1); + int height = Math.abs(y2 - y1); + // 绘制矩形 + g2d.drawRect(rectX, rectY, width, height); + infraPictureInfo.setFirstX(x1); + infraPictureInfo.setFirstY(y1); + infraPictureInfo.setSecondX(x2); + infraPictureInfo.setSecondY(y2); + + InfraredInfo drawStringMatrix = matrixTemperatureShow(c, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); + infraredInfo.setFrameMax(Math.round(drawStringMatrix.getFrameMax() * 100) / 100f); + // 添加矩形标签 + String line1 = "平均温度:" + String.format("%.2f", drawStringMatrix.getFrameAverage()); + String line2 = "最高温度:" + String.format("%.2f", drawStringMatrix.getFrameMax()); + String line3 = "最低温度:" + String.format("%.2f", drawStringMatrix.getFrameMin()); + g2d.drawString(line1, rectX + 5, rectY + 15); + g2d.drawString(line2, rectX + 5, rectY + 30); + g2d.drawString(line3, rectX + 5, rectY + 45); + } } } + } else if (infraPictureInfo.getImgType() == 2) { + for (Coordinate c : coordinates) { + g2d.setFont(font); + //矩阵标注 + if (c.getSecondX() != null && c.getSecondY() != null) { + // 标注矩形(每两个点确定一个矩形) + g2d.setColor(Color.WHITE); + int x1 = c.getFirstX(); + int y1 = c.getFirstY(); + int x2 = c.getSecondX(); + int y2 = c.getSecondY(); + + // 确保坐标在图片范围内 + if (x1 >= 0 && x1 < originalImage.getWidth() && y1 >= 0 && y1 < originalImage.getHeight() && + x2 >= 0 && x2 < originalImage.getWidth() && y2 >= 0 && y2 < originalImage.getHeight()) { + + // 确保x1,y1是左上角,x2,y2是右下角 + int rectX = Math.min(x1, x2); + int rectY = Math.min(y1, y2); + int width = Math.abs(x2 - x1); + int height = Math.abs(y2 - y1); + // 绘制矩形 + g2d.drawRect(rectX, rectY, width, height); + + infraPictureInfo.setFirstX(x1); + infraPictureInfo.setFirstY(y1); + infraPictureInfo.setSecondX(x2); + infraPictureInfo.setSecondY(y2); + // 添加矩形标签 + //图片路径取值 + String[] dividePath = Paths.get(imagePath).getFileName().toString().replaceAll("(?i)\\.jpg$", "").split("_"); + String max = dividePath[dividePath.length - 1]; // 最大值 + infraredInfo.setFrameMax(Float.parseFloat(max)); + String line1 = "最高温度:" + max; + g2d.drawString(line1, rectX + 5, rectY + 15); - //矩阵标注 - if (c.getSecondX() != null && c.getSecondY() != null) { - // 标注矩形(每两个点确定一个矩形) - g2d.setColor(Color.WHITE); - int x1 = c.getFirstX(); - int y1 = c.getFirstY(); - int x2 = c.getSecondX(); - int y2 = c.getSecondY(); - - // 确保坐标在图片范围内 - if (x1 >= 0 && x1 < originalImage.getWidth() && y1 >= 0 && y1 < originalImage.getHeight() && - x2 >= 0 && x2 < originalImage.getWidth() && y2 >= 0 && y2 < originalImage.getHeight()) { - - // 确保x1,y1是左上角,x2,y2是右下角 - int rectX = Math.min(x1, x2); - int rectY = Math.min(y1, y2); - int width = Math.abs(x2 - x1); - int height = Math.abs(y2 - y1); - // 绘制矩形 - g2d.drawRect(rectX, rectY, width, height); - infraPictureInfo.setFirstX(x1); - infraPictureInfo.setFirstY(y1); - infraPictureInfo.setSecondX(x2); - infraPictureInfo.setSecondY(y2); - - InfraredInfo drawStringMatrix = matrixTemperatureShow(c, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); - infraredInfo.setFrameMax(Math.round(drawStringMatrix.getFrameMax() * 100) / 100f); - // 添加矩形标签 - String line1 = "平均温度:" + String.format("%.2f", drawStringMatrix.getFrameAverage()); - String line2 = "最高温度:" + String.format("%.2f", drawStringMatrix.getFrameMax()); - String line3 = "最低温度:" + String.format("%.2f", drawStringMatrix.getFrameMin()); - g2d.drawString(line1, rectX + 5, rectY + 15); - g2d.drawString(line2, rectX + 5, rectY + 30); - g2d.drawString(line3, rectX + 5, rectY + 45); - + } + } + } + } else if (infraPictureInfo.getImgType() == 1) { + for (Coordinate c : coordinates) { + //矩阵标注 + if (c.getSecondX() != null && c.getSecondY() != null) { + // 标注矩形(每两个点确定一个矩形) + g2d.setColor(Color.RED); + int x1 = c.getFirstX(); + int y1 = c.getFirstY(); + int x2 = c.getSecondX(); + int y2 = c.getSecondY(); + + // 确保坐标在图片范围内 + if (x1 >= 0 && x1 < originalImage.getWidth() && y1 >= 0 && y1 < originalImage.getHeight() && + x2 >= 0 && x2 < originalImage.getWidth() && y2 >= 0 && y2 < originalImage.getHeight()) { + + // 确保x1,y1是左上角,x2,y2是右下角 + int rectX = Math.min(x1, x2); + int rectY = Math.min(y1, y2); + int width = Math.abs(x2 - x1); + int height = Math.abs(y2 - y1); + // 绘制矩形 + g2d.drawRect(rectX, rectY, width, height); + infraPictureInfo.setFirstX(x1); + infraPictureInfo.setFirstY(y1); + infraPictureInfo.setSecondX(x2); + infraPictureInfo.setSecondY(y2); + + InfraredInfo drawStringMatrix = matrixTemperatureShow(c, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); + infraredInfo.setFrameMax(Math.round(drawStringMatrix.getFrameMax() * 100) / 100f); + // 添加矩形标签 + String line1 = "平均温度:" + String.format("%.2f", drawStringMatrix.getFrameAverage()); + String line2 = "最高温度:" + String.format("%.2f", drawStringMatrix.getFrameMax()); + String line3 = "最低温度:" + String.format("%.2f", drawStringMatrix.getFrameMin()); + g2d.drawString(line1, rectX + 5, rectY + 15); + g2d.drawString(line2, rectX + 5, rectY + 30); + g2d.drawString(line3, rectX + 5, rectY + 45); + } } } } g2d.dispose(); - ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(annotatedImage, "jpg", os); InputStream inputStream = new ByteArrayInputStream(os.toByteArray()); picFtp(outputPath, inputStream, ftpUrlAddress, ftpUrlPort, ftpUrlAccount, ftpUrlPwd); -// // 保存标注后的图片 -// File outputFile = new File(outputPath); -// // 确保输出目录存在 -// outputFile.getParentFile().mkdirs(); -// -// ImageIO.write(annotatedImage, "jpg", outputFile); -// System.out.println("标注后的图片已保存到: " + outputPath); - } catch (IOException e) { System.err.println("处理图片时出错: " + e.getMessage()); e.printStackTrace(); @@ -1176,12 +1028,10 @@ public class HikVisionServiceImpl implements HikVisionService { } } catch (Exception e) { - } return inputStream; } - //异常处理返回本地csv private float[][] exceptionHandling() throws IOException { String localPath = picPath + "1.csv"; @@ -1244,9 +1094,10 @@ public class HikVisionServiceImpl implements HikVisionService { String[] imageUrlList = analyseReqItem.getImageUrlList(); InfraPictureInfo infraPictureInfo = new InfraPictureInfo(); +// infraPictureInfo.setChannelId(); infraPictureInfo.setImgType(3); infraPictureInfo.setFilePath(imageUrlList[0]); - InfraredInfo infraredInfo = calculatePicture(infraPictureInfo); + InfraredInfo infraredInfo = calculatePicture(infraPictureInfo,"1,1,639,511,640,512"); AnalyseResult analyseResult = new AnalyseResult(); @@ -1276,64 +1127,67 @@ public class HikVisionServiceImpl implements HikVisionService { try { String analyseResultOutJson = JSONObject.toJSONString(analyseResult); - + System.out.println("打印json返回:" + analyseResultOutJson); log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, analyseResultOutJson={}", feedbackUrl, analyseResultOutJson); - String result = HttpClientUtils.sendPostAgain(feedbackUrl, analyseResultOutJson); - log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, result: {}", feedbackUrl, result); +// String result = HttpClientUtils.sendPostAgain(feedbackUrl, analyseResultOutJson); +// log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, result: {}", feedbackUrl, result); } catch (Exception e) { log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, EXCEPTION: {}", feedbackUrl, e.getMessage()); } - return ResponseEntity.ok().body("{\"code\":\"200\"}"); - - } - public InfraredInfo calculatePicture(InfraPictureInfo infraPictureInfo) { + public InfraredInfo calculatePicture(InfraPictureInfo infraPictureInfo, String picData) { InfraredInfo infraredInfo = new InfraredInfo(); String imagePath = infraPictureInfo.getFilePath(); InputStream inputStream = downloadFtp(imagePath); +// Long channelId = infraPictureInfo.getChannelId(); +// BasedataEqpBookChannel basedataEqpBookChannel = basedataEqpBookChannelMapper.selectBasedataEqpBookChannelByChannelId(channelId); + int firstX = 1; + int firstY = 1; + int secondX = 639; + int secondY = 511; + int imgWidth = 640; + int imgHeight = 512; + if (picData != null) { + String[] parts = picData.split(","); + // 解析坐标 + firstX = Integer.parseInt(parts[0]); + firstY = Integer.parseInt(parts[1]); + secondX = Integer.parseInt(parts[2]); + secondY = Integer.parseInt(parts[3]); + imgHeight = Integer.parseInt(parts[4]); + imgWidth = Integer.parseInt(parts[5]); + }else { + log.error("无点位信息!"); + } + List coordinates = new ArrayList<>(); + coordinates.add(new Coordinate(firstX, firstY, secondX, secondY)); + infraPictureInfo.setImgWidth(imgWidth); + infraPictureInfo.setImgHeight(imgHeight); + infraPictureInfo.setCoordinates(coordinates); + if (infraPictureInfo.getImgType() == 1) { + //相机红外 // byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath)); // infraredInfo = readDataHw(imageBytes, infraPictureInfo.getCoordinates().get(0)); - } else if (infraPictureInfo.getImgType() == 2) { + float[][] matrix = getMatrix(infraPictureInfo.getImgWidth(), infraPictureInfo.getImgHeight());//图片宽、高 + infraredInfo.setTemperatureMatrix(matrix); + //画框标注 + String s = ImageOverlays(infraPictureInfo, infraredInfo); + infraredInfo.setOutPath(s); -// String s = ImageOverlaysIvs(infraPictureInfo.getCoordinates().get(0), infraredInfo); -// infraredInfo.setOutPath(s); + } else if (infraPictureInfo.getImgType() == 2) { + //ivs1800红外图 + String s = ImageOverlays(infraPictureInfo, infraredInfo); + infraredInfo.setOutPath(s); } else if (infraPictureInfo.getImgType() == 3) { + //无人机红外图 //sdk版本调用x86_32 //float[][] imageTem = djService.getImageTem(coordinate.getFilePath()); - Long channelId = infraPictureInfo.getChannelId(); - BasedataEqpBookChannel basedataEqpBookChannel = basedataEqpBookChannelMapper.selectBasedataEqpBookChannelByChannelId(channelId); - int firstX = 1; - int firstY = 1; - int secondX = 639; - int secondY = 511; - int imgWidth = 640; - int imgHeight = 512; - if (basedataEqpBookChannel!=null) { - if (basedataEqpBookChannel.getChannelContent() !=null) { - String[] parts = basedataEqpBookChannel.getChannelContent().split(","); - // 解析坐标 - firstX = Integer.parseInt(parts[0]); - firstY = Integer.parseInt(parts[1]); - secondX = Integer.parseInt(parts[2]); - secondY = Integer.parseInt(parts[3]); - imgHeight = Integer.parseInt(parts[4]); - imgWidth = Integer.parseInt(parts[5]); - } - } else { - log.info("设置标注点位不存在!"); - } - List coordinates = new ArrayList<>(); - coordinates.add(new Coordinate(firstX, firstY, secondX, secondY)); - infraPictureInfo.setImgWidth(imgWidth); - infraPictureInfo.setImgHeight(imgHeight); - infraPictureInfo.setCoordinates(coordinates); - //调用华软接口 String protocol = hrFtpUrl.substring(0, 6); // "ftp://" String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/" @@ -1353,7 +1207,7 @@ public class HikVisionServiceImpl implements HikVisionService { String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]"; - float[][] imageTem=new float[0][]; + float[][] imageTem = new float[0][]; if (isLoginHr) { //可以登陆华软ftp imageTem = UploadFtpImage(hrUavUrl, null, ftpUrlName); @@ -1361,28 +1215,27 @@ public class HikVisionServiceImpl implements HikVisionService { infraredInfo.setTemperatureMatrix(imageTem); } else { //不能调用华软接口,使用本地csv - log.info("温度解析错误,接口无法调用!"); try { imageTem = exceptionHandling(); infraredInfo.setTemperatureMatrix(imageTem); } catch (IOException e) { e.printStackTrace(); + log.error("温度解析错误,接口无法调用!" + e); } } - String s = ImageOverlaysUav(infraPictureInfo, infraredInfo); + String s = ImageOverlays(infraPictureInfo, infraredInfo); infraredInfo.setOutPath(s); - }else{ + } else { //华软ftp不能登录,使用本地csv - log.info("温度解析错误.ftp无法登陆!"); try { imageTem = exceptionHandling(); infraredInfo.setTemperatureMatrix(imageTem); } catch (IOException e) { e.printStackTrace(); + log.error("温度解析错误,ftp无法登陆!"+ e); } - String s = ImageOverlaysUav(infraPictureInfo, infraredInfo); + String s = ImageOverlays(infraPictureInfo, infraredInfo); infraredInfo.setOutPath(s); - } } return infraredInfo;