|
|
|
@ -28,6 +28,9 @@ import com.inspect.simulator.tempCount.TempCount; |
|
|
|
import com.inspect.simulator.utils.sftp.SftpClient; |
|
|
|
import okhttp3.*; |
|
|
|
import org.apache.commons.compress.utils.IOUtils; |
|
|
|
import org.apache.commons.csv.CSVFormat; |
|
|
|
import org.apache.commons.csv.CSVParser; |
|
|
|
import org.apache.commons.csv.CSVRecord; |
|
|
|
import org.apache.commons.net.ftp.FTP; |
|
|
|
import org.apache.commons.net.ftp.FTPClient; |
|
|
|
import org.apache.commons.net.ftp.FTPSClient; |
|
|
|
@ -42,6 +45,8 @@ import javax.imageio.ImageIO; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.*; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.nio.ByteBuffer; |
|
|
|
import java.nio.ByteOrder; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
@ -70,7 +75,8 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
private String picPath; |
|
|
|
|
|
|
|
// @Value("${file.hrUavUrl:test}") |
|
|
|
private String hrUavUrl = "http://192.168.4.167:2000/"; |
|
|
|
// private String hrUavUrl = "http://192.168.4.167:2000/"; |
|
|
|
private String hrUavUrl = "http://192.168.4.160:2000/"; |
|
|
|
|
|
|
|
// @Value("${file.hrFtpUrl:test}") |
|
|
|
private String hrFtpUrl = "ftp://ftpuser:atia2018@192.168.4.129:10012/"; |
|
|
|
@ -675,7 +681,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
if (c.getFirstX() != null && c.getFirstY() != null && c.getSecondX() == null && c.getSecondY() == null) { |
|
|
|
g2d.setFont(font); |
|
|
|
// 标注点坐标 |
|
|
|
g2d.setColor(Color.GREEN); |
|
|
|
g2d.setColor(Color.WHITE); |
|
|
|
int x = c.getFirstX(); |
|
|
|
int y = c.getFirstY(); |
|
|
|
|
|
|
|
@ -694,7 +700,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(); |
|
|
|
@ -842,7 +848,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
.writeTimeout(5, TimeUnit.SECONDS) // 写入超时5秒 |
|
|
|
.retryOnConnectionFailure(false) // 禁用自动重试 |
|
|
|
.build(); |
|
|
|
|
|
|
|
log.info("UploadFtpImage, client: {}", client); |
|
|
|
float[][] floats = new float[0][]; |
|
|
|
try { |
|
|
|
// 构建 multipart 请求体 |
|
|
|
@ -866,7 +872,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
|
|
|
|
// 执行请求并处理响应 |
|
|
|
try (Response response = client.newCall(request).execute()) { |
|
|
|
|
|
|
|
log.info("UploadFtpImage, response: {}", response); |
|
|
|
if (!response.isSuccessful() && response.code() != 4006) { |
|
|
|
throw new IOException("请求失败,HTTP状态码: " + response.code()); |
|
|
|
} |
|
|
|
@ -887,7 +893,8 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
} |
|
|
|
JsonNode firstItem = jsonArray.get(0); |
|
|
|
String imageRawFlow = firstItem.get("image_raw_flow").asText(); |
|
|
|
floats = parseCsvFromFtp(imageRawFlow); |
|
|
|
log.info("imageRawFlow" + imageRawFlow); |
|
|
|
floats = parseCsvFromFtp2(imageRawFlow); |
|
|
|
|
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
@ -969,9 +976,66 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//从ftp获取csv流转换成二维数组 |
|
|
|
|
|
|
|
private float[][] parseCsvFromFtp2(String csvUrl) throws IOException, URISyntaxException { |
|
|
|
log.info("连接ftp,获取csv文件"); |
|
|
|
InputStream inputStream = null; |
|
|
|
FTPSClient ftps = null; |
|
|
|
CSVParser csvParser = null; |
|
|
|
try { |
|
|
|
ftps = new FTPSClient(true); |
|
|
|
ftps.connect(ftpUrlAddress, ftpUrlPort); |
|
|
|
boolean loginRes = ftps.login(ftpUrlAccount, ftpUrlPwd); |
|
|
|
if (loginRes) { |
|
|
|
log.info("[FTP] LOGIN SUCCESS: {}", ftpUrlAddress); |
|
|
|
} |
|
|
|
ftps.setFileType(2); |
|
|
|
ftps.enterLocalPassiveMode(); |
|
|
|
ftps.setControlEncoding("UTF-8"); |
|
|
|
ftps.setFileTransferMode(10); |
|
|
|
ftps.execPROT("P"); |
|
|
|
// |
|
|
|
URI uri = new URI(csvUrl); |
|
|
|
String filePath = uri.getPath(); |
|
|
|
log.info("[FTP] DOWNLOAD: {}", filePath); |
|
|
|
inputStream = ftps.retrieveFileStream(filePath); |
|
|
|
if (inputStream == null) { |
|
|
|
log.error("[FTP] DOWNLOAD FAIL, EMPTY STREAM: {}", filePath); |
|
|
|
|
|
|
|
} |
|
|
|
Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); |
|
|
|
csvParser = CSVFormat.DEFAULT.parse(reader); |
|
|
|
List<CSVRecord> records = csvParser.getRecords(); |
|
|
|
|
|
|
|
// 7. 转换为 float[][] |
|
|
|
float[][] result = new float[records.size()][]; |
|
|
|
for (int i = 0; i < records.size(); i++) { |
|
|
|
CSVRecord record = records.get(i); |
|
|
|
result[i] = new float[record.size()]; |
|
|
|
for (int j = 0; j < record.size(); j++) { |
|
|
|
result[i][j] = Float.parseFloat(record.get(j)); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} finally { |
|
|
|
// 8. 确保资源关闭 |
|
|
|
IOUtils.closeQuietly(csvParser); |
|
|
|
IOUtils.closeQuietly(inputStream); |
|
|
|
if (ftps != null && ftps.isConnected()) { |
|
|
|
try { |
|
|
|
ftps.logout(); |
|
|
|
ftps.disconnect(); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("FTP 断开连接失败", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//上传图片到ftp |
|
|
|
public void picFtp(String newPath, InputStream originalPath, String ftpUrlAddress, Integer ftpUrlPort, String ftpUrlAccount, String ftpUrlPwd) { |
|
|
|
public void picFtp(String newPath, InputStream originalPath, String ftpUrlAddress, Integer ftpUrlPort, String |
|
|
|
ftpUrlAccount, String ftpUrlPwd) { |
|
|
|
FTPSClient ftps = null; |
|
|
|
try { |
|
|
|
ftps = new FTPSClient(true); |
|
|
|
@ -988,7 +1052,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
System.err.println("上传失败!FTP 返回: " + ftps.getReplyString()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("error" + e); |
|
|
|
} finally { |
|
|
|
// 5. 关闭资源 |
|
|
|
try { |
|
|
|
@ -998,13 +1062,14 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
ftps.disconnect(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("error" + e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//华软上传图片到ftp |
|
|
|
public boolean pic2Ftp(String newPath, InputStream originalPath, String ftpUrlAddress, Integer ftpUrlPort, String ftpUrlAccount, String ftpUrlPwd) { |
|
|
|
public boolean pic2Ftp(String newPath, InputStream originalPath, String ftpUrlAddress, Integer |
|
|
|
ftpUrlPort, String ftpUrlAccount, String ftpUrlPwd) { |
|
|
|
FTPClient ftps = new FTPClient(); |
|
|
|
ftps.setConnectTimeout(2000); // 连接超时3秒 |
|
|
|
ftps.setDataTimeout(2000); // 数据传输超时3秒 |
|
|
|
@ -1041,7 +1106,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
// ftps.disconnect(); |
|
|
|
// } |
|
|
|
} catch (IOException e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
log.error("error" + e); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1068,6 +1133,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
|
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("error" + e); |
|
|
|
} |
|
|
|
return inputStream; |
|
|
|
} |
|
|
|
@ -1237,7 +1303,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
infraredInfo.setOutPath(s); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("error" + e); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (AlgConstants.INFRA_CAMERA_REVERSE.equals(imageType)) { |
|
|
|
@ -1288,7 +1354,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
imageTem = exceptionHandling(); |
|
|
|
infraredInfo.setTemperatureMatrix(imageTem); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("error" + e); |
|
|
|
log.error("温度解析错误,接口无法调用!"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1300,7 +1366,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
imageTem = exceptionHandling(); |
|
|
|
infraredInfo.setTemperatureMatrix(imageTem); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("error" + e); |
|
|
|
log.error("温度解析错误,ftp无法登陆!" + e); |
|
|
|
} |
|
|
|
String s = ImageOverlays(infraPictureInfo, infraredInfo); |
|
|
|
@ -1308,7 +1374,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
} |
|
|
|
} else { |
|
|
|
String imageName = Paths.get(imagePath).getFileName().toString(); |
|
|
|
String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + imagePath + "\"]"; |
|
|
|
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) { |
|
|
|
|