Browse Source

红外图谱信息页面调试绘制 点、框

master
wangxun 8 months ago
parent
commit
93be495e94
4 changed files with 49 additions and 72 deletions
  1. +5
    -5
      pom.xml
  2. +1
    -0
      src/main/java/com/inspect/simulator/controller/InfraredController.java
  3. +2
    -6
      src/main/java/com/inspect/simulator/domain/Infrared/Coordinate.java
  4. +41
    -61
      src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java

+ 5
- 5
pom.xml View File

@ -171,11 +171,11 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.7.17</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.data</groupId>-->
<!-- <artifactId>spring-data-redis</artifactId>-->
<!-- <version>2.7.17</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>


+ 1
- 0
src/main/java/com/inspect/simulator/controller/InfraredController.java View File

@ -48,6 +48,7 @@ public class InfraredController {
@PostMapping("/capturePicture")
@ResponseBody
public AjaxResult capturePicture(@RequestBody Coordinate coordinate) {
return hikVisionService.analyzeInfrared(coordinate);
}


+ 2
- 6
src/main/java/com/inspect/simulator/domain/Infrared/Coordinate.java View File

@ -17,15 +17,11 @@ public class Coordinate {
private String filePath;
//矩阵温度坐标
private Integer[][] matrixCoordinate;
//点温度坐标
private Integer[][] pointCoordinate;
//图片宽
private Integer imgWidth;
//图片高
private Integer imgHeight;
private Coordinate[] coordinates;
}

+ 41
- 61
src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java View File

@ -40,7 +40,7 @@ import java.util.Date;
import java.util.List;
/**
* 海康威视测试服务类
* 海康威视测试服务类
*/
@Service
public class HikVisionServiceImpl implements HikVisionService {
@ -107,7 +107,6 @@ public class HikVisionServiceImpl implements HikVisionService {
}
@Override
public AjaxResult cameraHongWaiHk(Camera camera) {
//红外图谱信息
@ -171,7 +170,7 @@ public class HikVisionServiceImpl implements HikVisionService {
System.out.println("获取数据");
FileOutputStream pic;
try {
String filename = picPath +"/pic/hw";
String filename = picPath + "/pic/hw/";
//判断路径是否存在
File filePath = new File(filename);
if (!filePath.exists()) {
@ -394,7 +393,7 @@ public class HikVisionServiceImpl implements HikVisionService {
// System.out.println();
// }
//绘制框选标识
if(coordinate!= null) {
if (coordinate != null) {
ImageOverlays(coordinate, infraredInfo);
}
} else {
@ -407,14 +406,14 @@ public class HikVisionServiceImpl implements HikVisionService {
}
//点测温
public InfraredInfo PointTemperatureShow(Coordinate coordinate,short width, short height,float[][] temperatureMatrix ){
public InfraredInfo PointTemperatureShow(Coordinate coordinate, short width, short height, float[][] temperatureMatrix) {
InfraredInfo infraredInfo = new InfraredInfo();
// 获取指定坐标的温度
if (ObjectUtil.isNotEmpty(coordinate.getFirstX())) {
//比例缩放像素 获取底图温度值
double xMultiple= (coordinate.getImgWidth().doubleValue()/width)* 100 / 100.0;
double yMultiple= (coordinate.getImgHeight().doubleValue()/height)* 100 / 100.0;
double xMultiple = (coordinate.getImgWidth().doubleValue() / width) * 100 / 100.0;
double yMultiple = (coordinate.getImgHeight().doubleValue() / height) * 100 / 100.0;
int x = (int) (coordinate.getFirstX() / xMultiple);
int y = (int) (coordinate.getFirstY() / yMultiple);
@ -432,14 +431,14 @@ public class HikVisionServiceImpl implements HikVisionService {
}
//框选温度值计算
public InfraredInfo matrixTemperatureShow(Coordinate coordinate,short width, short height, float[][] temperatureMatrix ){
public InfraredInfo matrixTemperatureShow(Coordinate coordinate, short width, short height, float[][] temperatureMatrix) {
InfraredInfo infraredInfo = new InfraredInfo();
//存储框选矩阵温度值
List<Float> values = new ArrayList<>();
if (ObjectUtil.isNotEmpty(coordinate.getFirstX()) && ObjectUtil.isNotEmpty(coordinate.getSecondX())) {
//倍数计算
double xMultiple= (coordinate.getImgWidth().doubleValue()/width)* 100 / 100.0;
double yMultiple= (coordinate.getImgHeight().doubleValue()/height)* 100 / 100.0;
double xMultiple = (coordinate.getImgWidth().doubleValue() / width) * 100 / 100.0;
double yMultiple = (coordinate.getImgHeight().doubleValue() / height) * 100 / 100.0;
//比例缩放像素 获取底图温度值
int x1 = (int) (coordinate.getFirstX() / xMultiple);
@ -531,30 +530,17 @@ public class HikVisionServiceImpl implements HikVisionService {
//图片标注
public String ImageOverlays( Coordinate coordinate ,InfraredInfo infraredInfo) {
Integer[][] pointCoordinate= coordinate.getPointCoordinate();
Integer[][] matrixCoordinate =coordinate.getMatrixCoordinate();
// //点坐标
// Integer[][] pointCoordinate = {
// {10, 20},
// {90, 40},
// {190, 130}
// };
// //矩阵坐标
// Integer[][] matrixCoordinate = {
// {11, 20},
// {90, 40},
// {50, 10},
// {200, 190}
// };
public String ImageOverlays(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();
// String imagePath = picPath+"/pic/hw/20250409141218PLAY_CELLPHONE_.jpg";
String outputPath = picPath+"/pic/hw/mark/"+markPicName+".jpg";
String outputPath = picPath + "/pic/hw/mark/" + markPicName + ".jpg";
try {
// 加载原始图片
BufferedImage originalImage = ImageIO.read(new File(imagePath));
@ -576,19 +562,20 @@ public class HikVisionServiceImpl implements HikVisionService {
// 设置标注样式
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Font font = new Font("Arial", Font.BOLD, 12);
g2d.setFont(font);
if ( pointCoordinate !=null && pointCoordinate.length >0) {
// 标注点坐标
g2d.setColor(Color.GREEN);
for (Integer[] point : pointCoordinate) {
int x = point[0];
int y = point[1];
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);
@ -598,20 +585,14 @@ public class HikVisionServiceImpl implements HikVisionService {
g2d.drawString("(" + String.format("%.2f", drawStringPoint.getPointTemperature()) + ")", x + 8, y - 8);
}
}
}
if ( matrixCoordinate !=null && matrixCoordinate.length >1 && matrixCoordinate.length % 2 == 0) {
// 标注矩形每两个点确定一个矩形
g2d.setColor(Color.RED);
for (int i = 0; i < matrixCoordinate.length; i += 2) {
if (i + 1 >= matrixCoordinate.length) break;
Integer[] point1 = matrixCoordinate[i];
Integer[] point2 = matrixCoordinate[i + 1];
int x1 = point1[0];
int y1 = point1[1];
int x2 = point2[0];
int y2 = point2[1];
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() &&
@ -629,17 +610,16 @@ public class HikVisionServiceImpl implements HikVisionService {
coordinate.setFirstY(y1);
coordinate.setSecondX(x2);
coordinate.setSecondY(y2);
InfraredInfo drawStringMatrix = matrixTemperatureShow(coordinate, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(),infraredInfo.getTemperatureMatrix());
InfraredInfo drawStringMatrix = matrixTemperatureShow(coordinate, infraredInfo.getMatrixWidth(), infraredInfo.getMatrixHeight(), infraredInfo.getTemperatureMatrix());
drawStringMatrix.getFrameAverage();
// 添加矩形标签
g2d.drawString("Age:" + String.format("%.2f", drawStringMatrix.getFrameAverage()) +
"Max:" + String.format("%.2f", drawStringMatrix.getFrameMax()) +
"Min:" + String.format("%.2f", drawStringMatrix.getFrameMin()) + (i / 2 + 1), rectX + 5, rectY + 15);
g2d.drawString("平均温度:" + String.format("%.2f", drawStringMatrix.getFrameAverage()) +
"最大温度:" + String.format("%.2f", drawStringMatrix.getFrameMax()) +
"最小温度:" + String.format("%.2f", drawStringMatrix.getFrameMin()), rectX + 5, rectY + 15);
}
}
g2d.dispose();
}
g2d.dispose();
// 保存标注后的图片
File outputFile = new File(outputPath);
// 确保输出目录存在
@ -660,10 +640,10 @@ public class HikVisionServiceImpl implements HikVisionService {
@Override
public AjaxResult uavInfrared(String apiUrl, String imageUrl, String coordinate) {
apiUrl = "http://192.168.3.81:1000";
imageUrl="http://192.168.3.81:8080/20230112/t001.jpg";
coordinate="[[0, 0, 100, 100], [150, 150, 300, 300]]";
imageUrl = "http://192.168.3.81:8080/20230112/t001.jpg";
coordinate = "[[0, 0, 100, 100], [150, 150, 300, 300]]";
InfraredInfo infraredInfo =new InfraredInfo();
InfraredInfo infraredInfo = new InfraredInfo();
HttpURLConnection connection = null;
try {
// 1. 创建URL对象
@ -712,7 +692,7 @@ public class HikVisionServiceImpl implements HikVisionService {
while ((line = reader.readLine()) != null) {
response.append(line);
}
String infraredData= response.toString();
String infraredData = response.toString();
}
} else {
return AjaxResult.error("请求失败,HTTP状态码: " + responseCode);
@ -725,7 +705,7 @@ public class HikVisionServiceImpl implements HikVisionService {
connection.disconnect();
}
}
return AjaxResult.success(infraredInfo);
return AjaxResult.success(infraredInfo);
}
private static void addFormField(PrintWriter writer, String boundary,


Loading…
Cancel
Save