From a6fb31fdd4276ea7a7eb370ed13f2388ebdd9fd9 Mon Sep 17 00:00:00 2001 From: 86156 <823267011@qq.com> Date: Sun, 28 Sep 2025 11:51:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thread/MediaTransferFlvByJavacv.java | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/ruoyi-video/src/main/java/com/ruoyi/video/thread/MediaTransferFlvByJavacv.java b/ruoyi-video/src/main/java/com/ruoyi/video/thread/MediaTransferFlvByJavacv.java index 6e74c2a..fa00c34 100644 --- a/ruoyi-video/src/main/java/com/ruoyi/video/thread/MediaTransferFlvByJavacv.java +++ b/ruoyi-video/src/main/java/com/ruoyi/video/thread/MediaTransferFlvByJavacv.java @@ -369,8 +369,11 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable long lastDetectionTime = 0; List currentDetections = Collections.emptyList(); // 当前显示的检测结果 - // 避免递归和栈溢出的关键:不使用递归调用,使用循环 - // 避免过深的方法调用链 + // 检测计数器和性能统计 + int totalDetections = 0; + int successfulDetections = 0; + long totalDetectionTime = 0; + for (; running && grabberStatus && recorderStatus; ) { try { if (transferFlag) { @@ -428,10 +431,52 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable if (detectionMat != null && !detectionMat.empty()) { // 执行检测 try { + // 打印检测开始信息 + log.info("===== 开始执行检测 [{}] =====", new java.text.SimpleDateFormat("HH:mm:ss.SSS").format(new java.util.Date())); + totalDetections++; + + // 记录检测开始时间 + long detectionStartTime = System.currentTimeMillis(); + + // 执行检测 currentDetections = detector.detect(detectionMat); + + // 计算检测耗时 + long detectionTime = System.currentTimeMillis() - detectionStartTime; + totalDetectionTime += detectionTime; + successfulDetections++; + + // 更新最后检测时间 lastDetectionTime = currentTime; latestDetections.set(currentDetections); + // 打印检测结果 + StringBuilder detectionInfo = new StringBuilder(); + detectionInfo.append("\n===== 检测结果 =====\n"); + detectionInfo.append("检测耗时: ").append(detectionTime).append("ms\n"); + detectionInfo.append("检测目标数: ").append(currentDetections == null ? 0 : currentDetections.size()).append("\n"); + + if (currentDetections != null && !currentDetections.isEmpty()) { + detectionInfo.append("检测到的目标:\n"); + for (int i = 0; i < currentDetections.size(); i++) { + Detection det = currentDetections.get(i); + detectionInfo.append(" ").append(i+1).append(". "); + detectionInfo.append("类型: ").append(det.cls()); + detectionInfo.append(", 置信度: ").append(String.format("%.2f", det.conf())); + } + } else { + detectionInfo.append("未检测到目标\n"); + } + + // 打印检测统计 + detectionInfo.append("\n检测统计:\n"); + detectionInfo.append("总检测次数: ").append(totalDetections).append("\n"); + detectionInfo.append("成功检测次数: ").append(successfulDetections).append("\n"); + detectionInfo.append("平均检测时间: ").append(successfulDetections > 0 ? (totalDetectionTime / successfulDetections) : 0).append("ms\n"); + detectionInfo.append("===== 检测结束 =====\n"); + + log.info(detectionInfo.toString()); + // 窗口巡检回调 if (windowMode && detectionListener != null && currentJobId != null && currentDeviceId != null) { @@ -443,7 +488,7 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable } catch (Exception ignore) {} } } catch (Exception e) { - log.debug("检测异常: {}", e.getMessage()); + log.error("检测异常: {}", e.getMessage(), e); } finally { // 确保释放Mat try { @@ -453,7 +498,7 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable } } } catch (Exception e) { - log.debug("检测流程异常: {}", e.getMessage()); + log.error("检测流程异常: {}", e.getMessage(), e); } }