|
|
|
@ -7,10 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.inspect.simulator.constant.AlgConstants; |
|
|
|
import com.inspect.simulator.domain.Infrared.Coordinate; |
|
|
|
import com.inspect.simulator.domain.Infrared.InfraPictureInfo; |
|
|
|
import com.inspect.simulator.domain.Infrared.InfraredBox; |
|
|
|
import com.inspect.simulator.domain.Infrared.InfraredInfo; |
|
|
|
import com.inspect.simulator.domain.Infrared.*; |
|
|
|
import com.inspect.simulator.domain.algorithm.in.AnalyseReqItem; |
|
|
|
import com.inspect.simulator.domain.algorithm.in.AnalyseRequest; |
|
|
|
import com.inspect.simulator.domain.algorithm.out.AnalyseResItem; |
|
|
|
@ -667,6 +664,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
String fileName = file.getName(); |
|
|
|
String pureName = fileName.substring(0, fileName.lastIndexOf('.')); |
|
|
|
String filename = picPath; |
|
|
|
log.info("filename图片路径:{}", filename); |
|
|
|
String outputPath = picPath + pureName + "_" + markPicName + ".jpg"; |
|
|
|
//判断路径是否存在 |
|
|
|
File filePath = new File(filename); |
|
|
|
@ -863,7 +861,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
//矩阵标注 |
|
|
|
if (c.getSecondX() != null && c.getSecondY() != null) { |
|
|
|
// 标注矩形(每两个点确定一个矩形) |
|
|
|
g2d.setColor(Color.GREEN); |
|
|
|
g2d.setColor(Color.WHITE); |
|
|
|
int x1 = c.getFirstX(); |
|
|
|
int y1 = c.getFirstY(); |
|
|
|
int x2 = c.getSecondX(); |
|
|
|
@ -889,6 +887,9 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
|
|
|
|
InfraredInfo drawStringMatrix = matrixTemperatureShow(c, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix()); |
|
|
|
infraredInfo.setFrameMax(Math.round(drawStringMatrix.getFrameMax() * 100) / 100f); |
|
|
|
Integer maxTempX = drawStringMatrix.getMaxTempX(); |
|
|
|
Integer maxTempY = drawStringMatrix.getMaxTempY(); |
|
|
|
log.info("最高温度值坐标点:" + "maxTempX:" + maxTempX + " maxTempY:" + maxTempY); |
|
|
|
// 添加矩形标签 |
|
|
|
String line1 = "平均温度:" + String.format("%.2f", drawStringMatrix.getFrameAverage()); |
|
|
|
String line2 = "最高温度:" + String.format("%.2f", drawStringMatrix.getFrameMax()); |
|
|
|
@ -896,24 +897,75 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
g2d.drawString(line1, rectX + 5, rectY + 15); |
|
|
|
g2d.drawString(line2, rectX + 5, rectY + 30); |
|
|
|
g2d.drawString(line3, rectX + 5, rectY + 45); |
|
|
|
|
|
|
|
|
|
|
|
// 在最高温度点画一个空心圆(红色边框) |
|
|
|
if (maxTempX != null && maxTempY != null) { |
|
|
|
log.info("画最高温度的点,坐标:x={}, y={}", maxTempX, maxTempY); |
|
|
|
|
|
|
|
// 边界检查 |
|
|
|
if (maxTempX >= 0 && maxTempX < originalImage.getWidth() && |
|
|
|
maxTempY >= 0 && maxTempY < originalImage.getHeight()) { |
|
|
|
|
|
|
|
// 设置醒目的颜色 |
|
|
|
g2d.setColor(Color.RED); |
|
|
|
g2d.setStroke(new BasicStroke(5)); |
|
|
|
|
|
|
|
// 画空心圆 |
|
|
|
int circleDiameter = 8; |
|
|
|
g2d.drawOval(maxTempX - circleDiameter / 2, maxTempY - circleDiameter / 2, |
|
|
|
circleDiameter, circleDiameter); |
|
|
|
|
|
|
|
// 画十字标记 |
|
|
|
g2d.drawLine(maxTempX - 3, maxTempY, maxTempX + 3, maxTempY); |
|
|
|
g2d.drawLine(maxTempX, maxTempY - 3, maxTempX, maxTempY + 3); |
|
|
|
|
|
|
|
log.info("成功绘制最高温度点标记"); |
|
|
|
} else { |
|
|
|
log.warn("最高温度点坐标超出图像范围:x={}, y={}", maxTempX, maxTempY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
float[][] temperatureMatrix = infraredInfo.getTemperatureMatrix(); |
|
|
|
String csvData = convertMatrixToCsv(temperatureMatrix); |
|
|
|
InputStream csvStream = new ByteArrayInputStream(csvData.getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
|
|
String csvPath = picPath +pureName +".csv"; |
|
|
|
log.info("保存csv文件:{}", csvPath); |
|
|
|
picFtp(csvPath, csvStream, ftpUrlAddress, ftpUrlPort, ftpUrlAccount, ftpUrlPwd); |
|
|
|
} |
|
|
|
g2d.dispose(); |
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(annotatedImage, "jpg", os); |
|
|
|
InputStream inputStream = new ByteArrayInputStream(os.toByteArray()); |
|
|
|
|
|
|
|
|
|
|
|
picFtp(outputPath, inputStream, ftpUrlAddress, ftpUrlPort, ftpUrlAccount, ftpUrlPwd); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
log.info("处理图片时出错: " + e.getMessage()); |
|
|
|
log.info("处理图片时出错: " + e.getMessage()); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return outputPath; |
|
|
|
} |
|
|
|
|
|
|
|
//二维数组转 CSV |
|
|
|
private static String convertMatrixToCsv(float[][] matrix) { |
|
|
|
StringBuilder csvBuilder = new StringBuilder(); |
|
|
|
for (float[] row : matrix) { |
|
|
|
for (int i = 0; i < row.length; i++) { |
|
|
|
csvBuilder.append(row[i]); |
|
|
|
if (i < row.length - 1) { |
|
|
|
csvBuilder.append(","); |
|
|
|
} |
|
|
|
} |
|
|
|
csvBuilder.append("\n"); |
|
|
|
} |
|
|
|
return csvBuilder.toString(); |
|
|
|
} |
|
|
|
//调用华软接口获取csv文件 |
|
|
|
public float[][] UploadFtpImage(String url, String type, String image) { |
|
|
|
log.info("imageName" + image); |
|
|
|
@ -1390,7 +1442,17 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
//相机反算红外 |
|
|
|
InputStream inputStreamPath = downloadFtp(imagePath); |
|
|
|
|
|
|
|
float[][] matrix = tempCount.countTemp(inputStreamPath, 61.20, 7.10);//图,最高值,最低值 |
|
|
|
//调取实时测温温度 |
|
|
|
//传值,相机 ip |
|
|
|
TemperatureData temperatureData = TemperatureMeasurement(); |
|
|
|
|
|
|
|
String minTemperature = temperatureData.getMinTemperature(); |
|
|
|
String maxTemperature = temperatureData.getMaxTemperature(); |
|
|
|
log.info("[INFRARED] 最高温度值:{}", maxTemperature); |
|
|
|
log.info("[INFRARED] 最低温度值:{}", minTemperature); |
|
|
|
|
|
|
|
float[][] matrix = tempCount.countTemp(inputStreamPath, Double.valueOf(minTemperature), Double.valueOf(maxTemperature));//图,最高值,最低值 |
|
|
|
// float[][] matrix = tempCount.countTemp(inputStreamPath, 20.2,60.5);//图,最高值,最低值 |
|
|
|
infraredInfo.setTemperatureMatrix(matrix); |
|
|
|
//画框标注 |
|
|
|
String s = ImageOverlays(infraPictureInfo, infraredInfo); |
|
|
|
@ -1496,6 +1558,67 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
return infraredInfo; |
|
|
|
} |
|
|
|
|
|
|
|
public TemperatureData TemperatureMeasurement(){ |
|
|
|
TemperatureData temperatureData =new TemperatureData(); |
|
|
|
OkHttpClient client = new OkHttpClient.Builder() |
|
|
|
.connectTimeout(5, TimeUnit.SECONDS) // 连接超时5秒 |
|
|
|
.readTimeout(10, TimeUnit.SECONDS) // 读取超时10秒 |
|
|
|
.writeTimeout(5, TimeUnit.SECONDS) // 写入超时5秒 |
|
|
|
.retryOnConnectionFailure(false) // 禁用自动重试 |
|
|
|
.build(); |
|
|
|
|
|
|
|
// 构造 JSON 请求体 |
|
|
|
MediaType JSON = MediaType.parse("application/json; charset=utf-8"); |
|
|
|
String jsonBody = "{\"ip\":\"192.168.1.70\",\"port\":\"8000\",\"userName\":\"admin\",\"password\":\"AA123456\"}"; |
|
|
|
RequestBody body = RequestBody.create(JSON,jsonBody); |
|
|
|
try { |
|
|
|
// 构建 multipart 请求体 |
|
|
|
// RequestBody requestBody = new MultipartBody.Builder() |
|
|
|
// .setType(MultipartBody.FORM) |
|
|
|
// .addFormDataPart("ip", "192.168.1.195") |
|
|
|
// .addFormDataPart("port", "8000") |
|
|
|
// .addFormDataPart("username", "admin") |
|
|
|
// .addFormDataPart("password", "htjc2018") |
|
|
|
// .build(); |
|
|
|
|
|
|
|
// 构建请求 |
|
|
|
Request request = new Request.Builder() |
|
|
|
.url("http://192.168.4.248:8080/hw/cameraHong") |
|
|
|
.post(body) |
|
|
|
.addHeader("Content-Type", "application/json") |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
Response response = client.newCall(request).execute(); |
|
|
|
if (!response.isSuccessful()) { |
|
|
|
log.error("请求测温接口失败,状态码: " + response.code()); |
|
|
|
} |
|
|
|
String responseBody = response.body() != null ? response.body().string() : null; |
|
|
|
|
|
|
|
// 解析 JSON 并提取 image_raw_flow |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
JsonNode jsonArray = mapper.readTree(responseBody); |
|
|
|
if (jsonArray.isEmpty()) { |
|
|
|
throw new RuntimeException("JSON数组为空"); |
|
|
|
} |
|
|
|
JsonNode firstItem = jsonArray.get("data"); |
|
|
|
JsonNode maxTemperature = firstItem.get("maxTemperature"); |
|
|
|
JsonNode minTemperature = firstItem.get("minTemperature"); |
|
|
|
JsonNode avgTemperature = firstItem.get("avgTemperature"); |
|
|
|
JsonNode temperatureDiff = firstItem.get("temperatureDiff"); |
|
|
|
JsonNode channel = firstItem.get("channel"); |
|
|
|
JsonNode ruleId = firstItem.get("ruleId"); |
|
|
|
|
|
|
|
|
|
|
|
temperatureData.setMaxTemperature(maxTemperature.toString()); |
|
|
|
temperatureData.setMinTemperature(minTemperature.toString()); |
|
|
|
System.out.println("firstItem: " + firstItem); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return temperatureData; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public InputStream downloadCsv(String filePath) { |
|
|
|
|