Browse Source

无人机红外修改

master
hsc 6 months ago
parent
commit
8e9aae7834
1 changed files with 55 additions and 54 deletions
  1. +55
    -54
      src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java

+ 55
- 54
src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java View File

@ -2,17 +2,15 @@ package com.inspect.simulator.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.ContentType;
//import com.inspect.simulator.dj.service.DjService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
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.*;
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.algorithm.in.AnalyseReqItem;
import com.inspect.simulator.domain.algorithm.in.AnalyseRequest;
import com.inspect.simulator.domain.algorithm.out.AnalyseResItem;
@ -22,31 +20,20 @@ import com.inspect.simulator.domain.basedata.BasedataEqpBookChannel;
import com.inspect.simulator.domain.result.BasedataPatrolPoint;
import com.inspect.simulator.hikVision.utils.AjaxResult;
import com.inspect.simulator.hikVision.utils.StringUtils;
//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.mapper.BasedataPatrolPointMapper;
import com.inspect.simulator.mapper.InfraredBoxMapper;
import com.inspect.simulator.service.HikVisionService;
import com.inspect.simulator.service.remote.AnalysisRemoteService;
import com.inspect.simulator.tempCount.TempCount;
import com.inspect.simulator.tempCount.TemperatureStats;
import com.inspect.simulator.utils.HttpClientUtils;
import com.inspect.simulator.utils.sftp.SftpClient;
import com.sun.jna.ptr.IntByReference;
import okhttp3.*;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPSClient;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.aspectj.weaver.ast.Var;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@ -58,10 +45,11 @@ import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -81,26 +69,26 @@ public class HikVisionServiceImpl implements HikVisionService {
private String picPath;
@Value("${file.hrUavUrl:test}")
private String hrUavUrl;
// @Value("${file.hrUavUrl:test}")
private String hrUavUrl = "http://192.168.4.167:2000/";
@Value("${file.hrFtpUrl:test}")
private String hrFtpUrl;
// @Value("${file.hrFtpUrl:test}")
private String hrFtpUrl = "ftp://ftpuser:atia2018@192.168.4.129:10012/";
@Value("${file.ftpUrlAddress:test}")
private String ftpUrlAddress;
// @Value("${file.ftpUrlAddress:test}")
private String ftpUrlAddress = "192.168.4.129";
@Value("${file.ftpUrlAccount:test}")
private String ftpUrlAccount;
// @Value("${file.ftpUrlAccount:test}")
private String ftpUrlAccount = "ftpuser";
@Value("${file.ftpUrlPwd:test}")
private String ftpUrlPwd;
// @Value("${file.ftpUrlPwd:test}")
private String ftpUrlPwd = "atia2018";
@Value("${file.ftpUrlPort:10000}")
private Integer ftpUrlPort;
// @Value("${file.ftpUrlPort:10000}")
private Integer ftpUrlPort = 10012;
@Value("${file.produceEnvironment:true}")
private Boolean produceEnvironment;
// @Value("${file.produceEnvironment:true}")
private Boolean produceEnvironment = true;
@Resource
private SftpClient sftpClient;
@ -678,7 +666,8 @@ public class HikVisionServiceImpl implements HikVisionService {
g2d.drawImage(originalImage, 0, 0, null);
// 设置标注样式
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Font font = new Font("微软雅黑", Font.BOLD, 17);
// Font font = new Font("微软雅黑", Font.BOLD, 17);
Font font = new Font("WenQuanYi Zen Hei", Font.BOLD, 17);
final String imageType = infraPictureInfo.getImgType();
if (AlgConstants.INFRA_YU3.equals(imageType)) {
for (Coordinate c : coordinates) {
@ -842,7 +831,8 @@ public class HikVisionServiceImpl implements HikVisionService {
//调用华软接口获取csv文件
public float[][] UploadFtpImage(String url, String type, String image) {
log.info("imageName" + image);
log.info("hrUrl" + hrUavUrl);
type = "ftp";
// OkHttpClient client = new OkHttpClient();
@ -872,11 +862,17 @@ public class HikVisionServiceImpl implements HikVisionService {
.addHeader("Connection", "keep-alive")
.build();
log.info("UploadFtpImage, request: {}", request);
// 执行请求并处理响应
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
if (!response.isSuccessful() && response.code() != 4006) {
throw new IOException("请求失败,HTTP状态码: " + response.code());
}
// if (!response.isSuccessful()) {
// throw new IOException("请求失败,HTTP状态码: " + response.code());
// }
String responseBody = response.body() != null ? response.body().string() : null;
if (responseBody == null) {
@ -895,6 +891,7 @@ public class HikVisionServiceImpl implements HikVisionService {
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("FTP请求处理失败,尝试本地文件: " + e.getMessage());
//
return null;
@ -973,7 +970,6 @@ public class HikVisionServiceImpl implements HikVisionService {
}
//上传图片到ftp
public void picFtp(String newPath, InputStream originalPath, String ftpUrlAddress, Integer ftpUrlPort, String ftpUrlAccount, String ftpUrlPwd) {
FTPSClient ftps = null;
@ -1191,12 +1187,14 @@ public class HikVisionServiceImpl implements HikVisionService {
public InfraredInfo calculatePicture(InfraPictureInfo infraPictureInfo, String picData) {
log.info("进入红外图片接口!");
InfraredInfo infraredInfo = new InfraredInfo();
String imagePath = infraPictureInfo.getFilePath();
log.info("图片路径:{}", imagePath);
//输出路径
int lastSlashIndex = imagePath.lastIndexOf('/');
picPath = (lastSlashIndex >= 0) ? imagePath.substring(0, lastSlashIndex + 1) : "/";
log.info("输出图片路径:{}", picPath);
InputStream inputStream = downloadFtp(imagePath);
int firstX = 1;
@ -1310,11 +1308,13 @@ public class HikVisionServiceImpl implements HikVisionService {
}
} else {
String imageName = Paths.get(imagePath).getFileName().toString();
String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + "/" + imageName + "\"]";
String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + imagePath + "\"]";
float[][] floats = new float[0][];
floats = UploadFtpImage(hrUavUrl, null, ftpUrlName);
if (floats != null && floats.length > 0 && floats[0].length > 0) {
infraredInfo.setTemperatureMatrix(floats);
String s = ImageOverlays(infraPictureInfo, infraredInfo);
infraredInfo.setOutPath(s);
} else {
//不能调用华软接口使用本地csv
try {
@ -1382,7 +1382,7 @@ public class HikVisionServiceImpl implements HikVisionService {
if (inputStream != null) {
return inputStream;
}
}else{
} else {
log.error("调用华软接口失败,使用本地1.csv文件!");
inputStream = getClass().getClassLoader().getResourceAsStream("1.csv");
return inputStream;
@ -1391,7 +1391,7 @@ public class HikVisionServiceImpl implements HikVisionService {
//共用同一ftp
String imageName = Paths.get(filePath).getFileName().toString();
String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + "/" + imageName + "\"]";
inputStream = UploadFtpImageStream(hrUavUrl, ftpUrlName);
inputStream = UploadFtpImageStream(hrUavUrl, ftpUrlName);
if (inputStream != null) {
return inputStream;
@ -1432,9 +1432,10 @@ public class HikVisionServiceImpl implements HikVisionService {
return inputStream;
}
//调用华软接口获取csv文件转成流文件
public InputStream UploadFtpImageStream(String url, String image) {
InputStream inputStream=null;
InputStream inputStream = null;
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS) // 连接超时5秒
.readTimeout(10, TimeUnit.SECONDS) // 读取超时10秒
@ -1480,7 +1481,7 @@ public class HikVisionServiceImpl implements HikVisionService {
// byte[] ftpFileAsStream = getFtpFileAsStream("ftp://123.184.14.138:50021/1.csv");
if (ftpFileAsStream != null) {
inputStream=ftpFileAsStream;
inputStream = ftpFileAsStream;
}
}
} catch (Exception e) {
@ -1491,17 +1492,17 @@ public class HikVisionServiceImpl implements HikVisionService {
@Override
public int insertInfraredBoxList(InfraPictureInfo infraPictureInfo){
List<InfraredBox> infraredBoxes=new ArrayList<>();
if (StringUtils.isNotEmpty(infraPictureInfo.getImgName())){
public int insertInfraredBoxList(InfraPictureInfo infraPictureInfo) {
List<InfraredBox> infraredBoxes = new ArrayList<>();
if (StringUtils.isNotEmpty(infraPictureInfo.getImgName())) {
infraredBoxMapper.deleteInfraredBoxListByImgName(infraPictureInfo.getImgName());
for (int i = 0; i < infraPictureInfo.getCoordinates().size(); i++) {
InfraredBox box=new InfraredBox();
InfraredBox box = new InfraredBox();
box.setImgName(infraPictureInfo.getImgName());
box.setImgWidth(infraPictureInfo.getImgWidth());
box.setImgHeight(infraPictureInfo.getImgHeight());
String pointXy=infraPictureInfo.getCoordinates().get(i).getFirstX()+","+infraPictureInfo.getCoordinates().get(i).getFirstY()+","+
infraPictureInfo.getCoordinates().get(i).getSecondX()+","+infraPictureInfo.getCoordinates().get(i).getSecondY();
String pointXy = infraPictureInfo.getCoordinates().get(i).getFirstX() + "," + infraPictureInfo.getCoordinates().get(i).getFirstY() + "," +
infraPictureInfo.getCoordinates().get(i).getSecondX() + "," + infraPictureInfo.getCoordinates().get(i).getSecondY();
box.setPointsXy(pointXy);
box.setMaxValue(infraPictureInfo.getCoordinates().get(i).getMaxValue());
box.setMinValue(infraPictureInfo.getCoordinates().get(i).getMinValue());
@ -1512,17 +1513,17 @@ public class HikVisionServiceImpl implements HikVisionService {
infraredBoxes.add(box);
}
}
return infraredBoxMapper.insertInfraredBoxList(infraredBoxes);
return infraredBoxMapper.insertInfraredBoxList(infraredBoxes);
}
@Override
public int deleteInfraredBoxListByImgName(String imgName){
return infraredBoxMapper.deleteInfraredBoxListByImgName(imgName);
public int deleteInfraredBoxListByImgName(String imgName) {
return infraredBoxMapper.deleteInfraredBoxListByImgName(imgName);
}
@Override
public List<InfraredBox> selectInfraredBoxListByImgName(String imgName){
return infraredBoxMapper.selectInfraredBoxListByImgName(imgName);
public List<InfraredBox> selectInfraredBoxListByImgName(String imgName) {
return infraredBoxMapper.selectInfraredBoxListByImgName(imgName);
}
}

Loading…
Cancel
Save