Browse Source

边框像素加粗

master
wangxun 8 months ago
parent
commit
f332ee045f
1 changed files with 71 additions and 30 deletions
  1. +71
    -30
      src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java

+ 71
- 30
src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java View File

@ -670,7 +670,7 @@ public class HikVisionServiceImpl implements HikVisionService {
//矩阵标注
if (c.getSecondX() != null && c.getSecondY() != null) {
// 标注矩形每两个点确定一个矩形
g2d.setColor(Color.WHITE);
g2d.setColor(Color.GREEN);
int x1 = c.getFirstX();
int y1 = c.getFirstY();
int x2 = c.getSecondX();
@ -685,6 +685,9 @@ public class HikVisionServiceImpl implements HikVisionService {
int rectY = Math.min(y1, y2);
int width = Math.abs(x2 - x1);
int height = Math.abs(y2 - y1);
// 设置更粗的画笔加粗矩形边框
g2d.setStroke(new BasicStroke(3)); // 3像素宽
// 绘制矩形
g2d.drawRect(rectX, rectY, width, height);
infraPictureInfo.setFirstX(x1);
@ -710,7 +713,7 @@ public class HikVisionServiceImpl implements HikVisionService {
//矩阵标注
if (c.getSecondX() != null && c.getSecondY() != null) {
// 标注矩形每两个点确定一个矩形
g2d.setColor(Color.WHITE);
g2d.setColor(Color.GREEN);
int x1 = c.getFirstX();
int y1 = c.getFirstY();
int x2 = c.getSecondX();
@ -725,6 +728,8 @@ public class HikVisionServiceImpl implements HikVisionService {
int rectY = Math.min(y1, y2);
int width = Math.abs(x2 - x1);
int height = Math.abs(y2 - y1);
// 设置更粗的画笔加粗矩形边框
g2d.setStroke(new BasicStroke(3)); // 3像素宽
// 绘制矩形
g2d.drawRect(rectX, rectY, width, height);
@ -749,7 +754,7 @@ public class HikVisionServiceImpl implements HikVisionService {
//矩阵标注
if (c.getSecondX() != null && c.getSecondY() != null) {
// 标注矩形每两个点确定一个矩形
g2d.setColor(Color.WHITE);
g2d.setColor(Color.GREEN);
int x1 = c.getFirstX();
int y1 = c.getFirstY();
int x2 = c.getSecondX();
@ -764,6 +769,8 @@ public class HikVisionServiceImpl implements HikVisionService {
int rectY = Math.min(y1, y2);
int width = Math.abs(x2 - x1);
int height = Math.abs(y2 - y1);
// 设置更粗的画笔加粗矩形边框
g2d.setStroke(new BasicStroke(3)); // 3像素宽
// 绘制矩形
g2d.drawRect(rectX, rectY, width, height);
infraPictureInfo.setFirstX(x1);
@ -966,7 +973,6 @@ public class HikVisionServiceImpl implements HikVisionService {
//华软上传图片到ftp
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秒
ftps.setDefaultTimeout(2000); // 控制通道超时3秒
@ -1035,7 +1041,7 @@ public class HikVisionServiceImpl implements HikVisionService {
//异常处理返回本地csv
private float[][] exceptionHandling() throws IOException {
String localPath = picPath + "1.csv";
String localPath = "/1.csv";
InputStream inputStream = downloadFtp(localPath);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
@ -1144,6 +1150,11 @@ public class HikVisionServiceImpl implements HikVisionService {
log.info("进入红外图片接口!");
InfraredInfo infraredInfo = new InfraredInfo();
String imagePath = infraPictureInfo.getFilePath();
//输出路径
int lastSlashIndex = imagePath.lastIndexOf('/');
picPath = (lastSlashIndex >= 0) ? imagePath.substring(0, lastSlashIndex + 1) : "/";
InputStream inputStream = downloadFtp(imagePath);
int firstX = 1;
int firstY = 1;
@ -1170,11 +1181,26 @@ public class HikVisionServiceImpl implements HikVisionService {
infraPictureInfo.setCoordinates(coordinates);
final String imageType = infraPictureInfo.getImgType();
if (AlgConstants.INFRA_CAMERA_REVERSE.equals(imageType)) {
if (AlgConstants.INFRA_CAMERA.equals(imageType)) {
//相机红外
// byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath));
// infraredInfo = readDataHw(imageBytes, infraPictureInfo.getCoordinates().get(0));
byte[] imageBytes = new byte[0];
try {
//ftp下载图片流转byte[]
InputStream imgInputStream = downloadFtp(imagePath);
imageBytes = IOUtils.toByteArray(imgInputStream);
// imageBytes = Files.readAllBytes(Paths.get(imagePath));
//读取红外信息
infraredInfo = readDataHw(imageBytes, infraPictureInfo.getCoordinates().get(0));
//绘制框选标识
String s = ImageOverlays(infraPictureInfo, infraredInfo);
infraredInfo.setOutPath(s);
} catch (IOException e) {
e.printStackTrace();
}
} else if (AlgConstants.INFRA_CAMERA_REVERSE.equals(imageType)) {
//相机反算红外
InputStream inputStreamPath = downloadFtp(imagePath);
float[][] matrix = tempCount.countTemp(inputStreamPath, 61.20, 7.10);//最高值最低值
@ -1189,27 +1215,25 @@ public class HikVisionServiceImpl implements HikVisionService {
infraredInfo.setOutPath(s);
} else if (AlgConstants.INFRA_YU3.equals(imageType)) {
//无人机红外图
// sdk版本调用x64
if (!produceEnvironment) {
//调用华软接口
String protocol = hrFtpUrl.substring(0, 6); // "ftp://"
String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/"
String[] userAndHost = withoutProtocol.split("@");
if (userAndHost.length != 2) {
throw new IllegalArgumentException("URL 格式错误,缺少 @ 分隔符");
}
String[] userPass = userAndHost[0].split(":");
String username = userPass[0];
String password = userPass[1];
String hostPort = userAndHost[1].replace("/", ""); // 移除末尾的 "/"
String[] hostAndPort = hostPort.split(":");
String host = hostAndPort[0];
int port = Integer.parseInt(hostAndPort[1]);
String imageName = Paths.get(imagePath).getFileName().toString();
boolean isLoginHr = pic2Ftp(imageName, inputStream, host, port, username, password);
String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]";
// float[][] imageTem = djService.getImageTem("D:/projects/pic/hw/1.JPG");
//调用华软接口
String protocol = hrFtpUrl.substring(0, 6); // "ftp://"
String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/"
String[] userAndHost = withoutProtocol.split("@");
if (userAndHost.length != 2) {
throw new IllegalArgumentException("URL 格式错误,缺少 @ 分隔符");
}
String[] userPass = userAndHost[0].split(":");
String username = userPass[0];
String password = userPass[1];
String hostPort = userAndHost[1].replace("/", ""); // 移除末尾的 "/"
String[] hostAndPort = hostPort.split(":");
String host = hostAndPort[0];
int port = Integer.parseInt(hostAndPort[1]);
String imageName = Paths.get(imagePath).getFileName().toString();
boolean isLoginHr = pic2Ftp(imageName, inputStream, host, port, username, password);
String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]";
float[][] imageTem = new float[0][];
if (isLoginHr) {
@ -1244,8 +1268,8 @@ public class HikVisionServiceImpl implements HikVisionService {
} else {
String imageName = Paths.get(imagePath).getFileName().toString();
String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + "/" + imageName + "\"]";
float[][] floats =new float[0][];
floats =UploadFtpImage(hrUavUrl, null, ftpUrlName);
float[][] floats = new float[0][];
floats = UploadFtpImage(hrUavUrl, null, ftpUrlName);
if (floats != null && floats.length > 0 && floats[0].length > 0) {
infraredInfo.setTemperatureMatrix(floats);
} else {
@ -1262,6 +1286,23 @@ public class HikVisionServiceImpl implements HikVisionService {
}
}
} else if (infraPictureInfo.getImgType().equals("infra_yu3_sdk")) {
//无人机红外图 sdk版本调用x64
// try {
// float[][] imageTem = djService.getImageTem("D:/projects/pic/hw/1.JPG");
// for (int i = 0; i < imageTem.length; i++) {
// for (int j = 0; j < imageTem[i].length; j++) {
// System.out.printf("%6.2f ", imageTem[i][j]); // 保留2位小数固定宽度
// }
// System.out.println(); // 换行
// }
//
// } catch (IOException e) {
// e.printStackTrace();
// }
}
return infraredInfo;
}


Loading…
Cancel
Save