|
|
|
|
@ -33,6 +33,8 @@ import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.Base64;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
@ -133,17 +135,24 @@ public class ScheduledTask {
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
// 进行单一背景检测
|
|
|
|
|
BackgroundDetector.DetectResult result = BackgroundDetector.detectBackground(imagePath2);
|
|
|
|
|
if("1".equals(result.value))
|
|
|
|
|
{
|
|
|
|
|
// 当前摄像头面对的是白墙,直接进行报警
|
|
|
|
|
handleAnalysisResult(blurDetection, imagePath2, result);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// BackgroundDetector.DetectResult result = BackgroundDetector.detectBackground(imagePath2);
|
|
|
|
|
// if("1".equals(result.value))
|
|
|
|
|
// {
|
|
|
|
|
// // 当前摄像头面对的是白墙,直接进行报警
|
|
|
|
|
// handleAnalysisResult(blurDetection, imagePath2, result);
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// 进行模糊图片对比
|
|
|
|
|
BlurDetectorV4.DetectResult detectResult = null;
|
|
|
|
|
if (isExists) {
|
|
|
|
|
// 基准图存在,使用双图对比功能
|
|
|
|
|
// 检查是否对着墙壁或者特征不明显的地方
|
|
|
|
|
BlurrinessComparator.DetectResult result = BlurrinessComparator.compareBlurriness(imagePath1, imagePath2);
|
|
|
|
|
if (result.value.equals("1")) {
|
|
|
|
|
// 当前摄像头面对的是白墙,直接进行报警
|
|
|
|
|
handleAnalysisResult(blurDetection, imagePath2, result);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
detectResult = BlurDetectorV4.doubleDetectBlur(imagePath1, imagePath2);
|
|
|
|
|
} else {
|
|
|
|
|
// 基准图不存在,使用单图对比功能
|
|
|
|
|
@ -162,7 +171,7 @@ public class ScheduledTask {
|
|
|
|
|
public record DetectResult(String desc,double score) {
|
|
|
|
|
}
|
|
|
|
|
// 分析背景检测结果并且报警
|
|
|
|
|
private void handleAnalysisResult(BlurDetection blurDetection, String imagePath, BackgroundDetector.DetectResult result) throws IOException {
|
|
|
|
|
private void handleAnalysisResult(BlurDetection blurDetection, String imagePath, BlurrinessComparator.DetectResult result) throws IOException {
|
|
|
|
|
Camera camera = cameraService.getById(blurDetection.getCameraId());
|
|
|
|
|
CameraAlarm cameraAlarm = new CameraAlarm();
|
|
|
|
|
cameraAlarm.setCameraId(camera.getId());
|
|
|
|
|
@ -174,7 +183,7 @@ public class ScheduledTask {
|
|
|
|
|
cameraAlarm.setCameraName(camera.getName());
|
|
|
|
|
cameraAlarm.setCaptureImage(imagePath);
|
|
|
|
|
DetectResult backgroundResult = new DetectResult(result.desc, result.score);
|
|
|
|
|
cameraAlarm.setAlgoResult(JsonUtils.toJsonString(result));
|
|
|
|
|
cameraAlarm.setAlgoResult(JsonUtils.toJsonString(backgroundResult));
|
|
|
|
|
cameraAlarm.setStatus(0);
|
|
|
|
|
cameraAlarmMapper.insert(cameraAlarm);
|
|
|
|
|
SocketMessage bean = new SocketMessage();
|
|
|
|
|
@ -190,17 +199,22 @@ public class ScheduledTask {
|
|
|
|
|
msg.setToPushAll(true);
|
|
|
|
|
websocketRedisService.sendServiceToWs(msg);
|
|
|
|
|
BoxAlarmReportDto reportDto = new BoxAlarmReportDto();
|
|
|
|
|
reportDto.setAlarmReportTime(LocalDateTime.now());
|
|
|
|
|
reportDto.setAlarmReportType(AlarmReportEnums.BLUR_ALARM.getAlarmDescription());
|
|
|
|
|
reportDto.setDescription("摄像头拍摄的图片出现模糊");
|
|
|
|
|
// 获取时间字符串
|
|
|
|
|
String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, timeFormatter);
|
|
|
|
|
// 转成时间戳(毫秒)
|
|
|
|
|
long timestamp = localDateTime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
|
|
|
|
|
reportDto.setAlarmTime(timestamp);
|
|
|
|
|
reportDto.setAlarmTypeDesc(AlarmReportEnums.BLUR_ALARM.getAlarmDescription());
|
|
|
|
|
byte[] CaptureFileContent = Files.readAllBytes(Paths.get(imagePath));
|
|
|
|
|
reportDto.setCaptureImage(Base64.getEncoder().encodeToString(CaptureFileContent));
|
|
|
|
|
reportDto.setUrl(blurDetection.getUrl());
|
|
|
|
|
reportDto.setAlarmImage(Base64.getEncoder().encodeToString(CaptureFileContent));
|
|
|
|
|
reportDto.setCameraName(camera.getName());
|
|
|
|
|
reportDto.setAlarmType(AlarmReportEnums.BLUR_ALARM.getAlarmCode());
|
|
|
|
|
reportDto.setCameraId(camera.getId());
|
|
|
|
|
reportDto.setCameraNo(camera.getCameraNo());
|
|
|
|
|
try {
|
|
|
|
|
forwardService.enrichAndForward(reportDto);
|
|
|
|
|
forwardService.enrichAndForward(blurDetection.getUrl(),reportDto);
|
|
|
|
|
}catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.error("模糊报警上报失败,摄像头 ID: {}, 相机编号:{}",
|
|
|
|
|
@ -248,21 +262,26 @@ public class ScheduledTask {
|
|
|
|
|
websocketRedisService.sendServiceToWs(msg);
|
|
|
|
|
// 统一处理报警信息后,将摄像头信息+报警信息上报给别人服务器
|
|
|
|
|
BoxAlarmReportDto reportDto = new BoxAlarmReportDto();
|
|
|
|
|
reportDto.setAlarmReportTime(LocalDateTime.now());
|
|
|
|
|
reportDto.setAlarmReportType(AlarmReportEnums.BLUR_ALARM.getAlarmDescription());
|
|
|
|
|
reportDto.setDescription("摄像头拍摄的图片出现模糊");
|
|
|
|
|
// 获取时间字符串
|
|
|
|
|
String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, timeFormatter);
|
|
|
|
|
// 转成时间戳(毫秒)
|
|
|
|
|
long timestamp = localDateTime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
|
|
|
|
|
reportDto.setAlarmTime(timestamp);
|
|
|
|
|
reportDto.setAlarmTypeDesc(AlarmReportEnums.BLUR_ALARM.getAlarmDescription());
|
|
|
|
|
if(isExists && imagePath1 !=null) {
|
|
|
|
|
byte[] BaseFileContent = Files.readAllBytes(Paths.get(imagePath1));
|
|
|
|
|
reportDto.setBaseImage(Base64.getEncoder().encodeToString(BaseFileContent));
|
|
|
|
|
}
|
|
|
|
|
byte[] CaptureFileContent = Files.readAllBytes(Paths.get(imagePath2));
|
|
|
|
|
reportDto.setCaptureImage(Base64.getEncoder().encodeToString(CaptureFileContent));
|
|
|
|
|
reportDto.setUrl(blurDetection.getUrl());
|
|
|
|
|
reportDto.setAlarmImage(Base64.getEncoder().encodeToString(CaptureFileContent));
|
|
|
|
|
reportDto.setCameraName(camera.getName());
|
|
|
|
|
reportDto.setAlarmType(AlarmReportEnums.BLUR_ALARM.getAlarmCode());
|
|
|
|
|
reportDto.setCameraId(camera.getId());
|
|
|
|
|
reportDto.setCameraNo(camera.getCameraNo());
|
|
|
|
|
try {
|
|
|
|
|
forwardService.enrichAndForward(reportDto);
|
|
|
|
|
forwardService.enrichAndForward(blurDetection.getUrl(),reportDto);
|
|
|
|
|
}catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.error("模糊报警上报失败,摄像头 ID: {}, 相机编号:{}",
|
|
|
|
|
@ -304,7 +323,7 @@ public class ScheduledTask {
|
|
|
|
|
if (ok) {
|
|
|
|
|
String filename = ImageNameUtils.generateFileName("CAPTURE", cameraId);
|
|
|
|
|
String image2 = manageNVR.capturePic(cameraId.intValue(), filename);
|
|
|
|
|
// String image2="D:\\work\\images\\CAPTURE_258_20260320170313838_4680425d.jpg";
|
|
|
|
|
//String image2="D:\\work\\images\\CAPTURE_258_20260331104152476_de86220b.jpg";
|
|
|
|
|
// 抓图合法性校验
|
|
|
|
|
if (image2 == null || image2.isBlank()) {
|
|
|
|
|
log.error("摄像机[{}] 抓拍失败,无法获取当前图片", cameraId);
|
|
|
|
|
@ -372,19 +391,24 @@ public class ScheduledTask {
|
|
|
|
|
websocketRedisService.sendServiceToWs(msg);
|
|
|
|
|
// 统一处理报警信息后,将摄像头信息+报警信息上报给别人服务器
|
|
|
|
|
BoxAlarmReportDto reportDto = new BoxAlarmReportDto();
|
|
|
|
|
reportDto.setAlarmReportTime(LocalDateTime.now());
|
|
|
|
|
reportDto.setAlarmReportType(AlarmReportEnums.DISPLACEMENT_ALARM.getAlarmDescription());
|
|
|
|
|
reportDto.setDescription("摄像头发生移位");
|
|
|
|
|
// 获取时间字符串
|
|
|
|
|
String timeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, timeFormatter);
|
|
|
|
|
// 转成时间戳(毫秒)
|
|
|
|
|
long timestamp = localDateTime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
|
|
|
|
|
reportDto.setAlarmTime(timestamp);
|
|
|
|
|
reportDto.setAlarmTypeDesc(AlarmReportEnums.DISPLACEMENT_ALARM.getAlarmDescription());
|
|
|
|
|
byte[] BaseFileContent = Files.readAllBytes(Paths.get(imagePath));
|
|
|
|
|
reportDto.setBaseImage(Base64.getEncoder().encodeToString(BaseFileContent));
|
|
|
|
|
byte[] CaptureFileContent = Files.readAllBytes(Paths.get(image2));
|
|
|
|
|
reportDto.setCaptureImage(Base64.getEncoder().encodeToString(CaptureFileContent));
|
|
|
|
|
reportDto.setUrl(preset.getPresetUrl());
|
|
|
|
|
reportDto.setAlarmImage(Base64.getEncoder().encodeToString(CaptureFileContent));
|
|
|
|
|
reportDto.setCameraName(camera.getName());
|
|
|
|
|
reportDto.setCameraId(camera.getId());
|
|
|
|
|
reportDto.setAlarmType(AlarmReportEnums.DISPLACEMENT_ALARM.getAlarmCode());
|
|
|
|
|
reportDto.setCameraNo(camera.getCameraNo());
|
|
|
|
|
try {
|
|
|
|
|
forwardService.enrichAndForward(reportDto);
|
|
|
|
|
forwardService.enrichAndForward(preset.getPresetUrl(),reportDto);
|
|
|
|
|
}catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.error("移位报警上报失败,摄像头 ID: {}, 相机编号:{}",
|
|
|
|
|
|