feat(video): 添加视频分析配置和RTSP服务器启动脚本
- 在application.yml中添加视频分析相关配置项,包括AI检测开关、RTSP连接参数 - 新增detection-config.json模型配置文件,支持YOLO目标检测模型 - 优化RTSP流媒体传输配置,添加TCP/UDP传输协议支持和超时重试机制 -修复模型配置文件路径问题,从/resources/models/调整为/libs/models/ - 更新JavaCV和OpenCV依赖版本,提升视频处理性能 - 添加Windows和Linux平台的RTSP测试服务器启动脚本 - 默认关闭AI检测功能,避免启动时出现错误- 增强RTSP连接稳定性,添加更多兼容性选项
This commit is contained in:
@@ -181,7 +181,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
|
||||
// 初始化模型管理器
|
||||
if (modelManager == null) {
|
||||
modelManager = new ModelManager();
|
||||
URL json = getClass().getResource("/models/models.json");
|
||||
URL json = getClass().getResource("/libs/models/models.json");
|
||||
if (json != null) {
|
||||
modelManager.load(json);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable
|
||||
|
||||
/*** ====== 新增:推理相关字段 ====== ***/
|
||||
// 开关:是否启用检测(可对外提供 setter)
|
||||
private boolean enableDetection = true;
|
||||
private boolean enableDetection = false; // 默认关闭,避免启动错误
|
||||
|
||||
// 模型与推理
|
||||
private ModelManager modelManager;
|
||||
@@ -98,7 +98,12 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable
|
||||
private void initDetectors() throws Exception {
|
||||
if (!enableDetection) return;
|
||||
modelManager = new ModelManager();
|
||||
URL json = getClass().getResource("/models/models.json");
|
||||
URL json = getClass().getResource("/libs/models/models.json");
|
||||
if (json == null) {
|
||||
log.warn("模型配置文件未找到,禁用检测功能");
|
||||
enableDetection = false;
|
||||
return;
|
||||
}
|
||||
modelManager.load(json);
|
||||
|
||||
// 单模型: detector = modelManager.get("person-helmet");
|
||||
@@ -130,10 +135,14 @@ public class MediaTransferFlvByJavacv extends MediaTransfer implements Runnable
|
||||
grabber.setOption("loglevel", "error"); // 稳定后压低日志
|
||||
|
||||
if (cameraDto.getUrl().toLowerCase().startsWith("rtsp://")) {
|
||||
grabber.setOption("rtsp_transport", "tcp"); // 你要测 UDP 再改
|
||||
// 尝试TCP传输,如果失败则尝试UDP
|
||||
grabber.setOption("rtsp_transport", "tcp");
|
||||
grabber.setOption("allowed_media_types", "video");
|
||||
grabber.setOption("max_delay", "500000");
|
||||
grabber.setOption("user_agent", "Lavf/60");
|
||||
// 添加更多RTSP选项以提高兼容性
|
||||
grabber.setOption("rtsp_flags", "prefer_tcp");
|
||||
grabber.setOption("timeout", "10000000"); // 10秒超时
|
||||
} else if (cameraDto.getUrl().toLowerCase().startsWith("rtmp://")) {
|
||||
grabber.setOption("rtmp_buffer", "1000");
|
||||
} else if ("desktop".equalsIgnoreCase(cameraDto.getUrl())) {
|
||||
|
||||
33
ruoyi-video/src/main/resources/models/detection-config.json
Normal file
33
ruoyi-video/src/main/resources/models/detection-config.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"models": [
|
||||
{
|
||||
"name": "yolo",
|
||||
"type": "object_detection",
|
||||
"modelPath": "models/yolo.onnx",
|
||||
"configPath": "models/yolo.cfg",
|
||||
"weightsPath": "models/yolo.weights",
|
||||
"classNames": [
|
||||
"person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck",
|
||||
"boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench",
|
||||
"bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra",
|
||||
"giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
|
||||
"skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove",
|
||||
"skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup",
|
||||
"fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange",
|
||||
"broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "sofa",
|
||||
"pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse",
|
||||
"remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink",
|
||||
"refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier",
|
||||
"toothbrush"
|
||||
],
|
||||
"inputSize": {
|
||||
"width": 640,
|
||||
"height": 640
|
||||
},
|
||||
"threshold": 0.5,
|
||||
"nmsThreshold": 0.4
|
||||
}
|
||||
],
|
||||
"enabled": true,
|
||||
"defaultModel": "yolo"
|
||||
}
|
||||
Reference in New Issue
Block a user