6116f0b982652c9a348c27d66b5a7a2d4f1f17d5
根本原因: 1. pipeline.py 中调用 register_algorithm 时未传入 roi_polygon,导致算法内 roi_polygon 为空 2. is_point_in_roi 函数在 roi_polygon 为空或点数 <3 时错误返回 True,使系统误判“有人在岗” 3. 因此即使 ROI 内无人,算法也永远不会进入离岗倒计时 修复措施: - 在注册算法时正确传递 ROI 多边形坐标 - 修正 is_point_in_roi:当 ROI 无效时应返回 False(无人) - 确保无检测框时仍能触发状态机超时逻辑
安保异常行为识别系统
项目概述
基于 YOLO + TensorRT 的安保异常行为识别系统,支持离岗检测和周界入侵检测。
快速开始
1. 安装依赖
pip install -r requirements.txt
2. 生成 TensorRT 引擎
python scripts/build_engine.py --model models/yolo11n.pt --fp16
3. 配置数据库
编辑 config.yaml 配置数据库连接。
4. 启动服务
python main.py
5. 访问前端
打开浏览器访问 http://localhost:3000
目录结构
project_root/
├── main.py # FastAPI 入口
├── config.yaml # 配置文件
├── requirements.txt # Python 依赖
├── inference/
│ ├── engine.py # TensorRT 引擎封装
│ ├── stream.py # RTSP 流处理
│ ├── pipeline.py # 推理主流程
│ ├── roi/
│ │ └── roi_filter.py # ROI 过滤
│ └── rules/
│ └── algorithms.py # 规则算法
├── db/
│ ├── models.py # SQLAlchemy ORM 模型
│ └── crud.py # 数据库操作
├── api/
│ ├── camera.py # 摄像头管理接口
│ ├── roi.py # ROI 管理接口
│ └── alarm.py # 告警管理接口
├── utils/
│ ├── logger.py # 日志工具
│ ├── helpers.py # 辅助函数
│ └── metrics.py # Prometheus 监控
├── frontend/ # React 前端
├── scripts/
│ └── build_engine.py # TensorRT 引擎构建脚本
├── tests/ # 单元测试
└── Dockerfile # Docker 配置
API 接口
摄像头管理
GET /api/cameras- 获取摄像头列表POST /api/cameras- 添加摄像头PUT /api/cameras/{id}- 更新摄像头DELETE /api/cameras/{id}- 删除摄像头
ROI 管理
GET /api/camera/{id}/rois- 获取摄像头 ROI 列表POST /api/camera/{id}/roi- 添加 ROIPUT /api/camera/{id}/roi/{roi_id}- 更新 ROIDELETE /api/camera/{id}/roi/{roi_id}- 删除 ROI
告警管理
GET /api/alarms- 获取告警列表GET /api/alarms/stats- 获取告警统计PUT /api/alarms/{id}- 更新告警状态POST /api/alarms/{id}/llm-check- 触发大模型检查
其他接口
GET /api/camera/{id}/snapshot- 获取实时截图GET /api/camera/{id}/detect- 获取带检测框的截图GET /api/pipeline/status- 获取 Pipeline 状态GET /health- 健康检查
配置说明
config.yaml
database:
dialect: "sqlite" # sqlite 或 mysql
name: "security_monitor"
model:
engine_path: "models/yolo11n_fp16_480.engine"
imgsz: [480, 480]
batch_size: 8
half: true
stream:
buffer_size: 2
reconnect_delay: 3.0
alert:
snapshot_path: "data/alerts"
cooldown_sec: 300
Docker 部署
docker-compose up -d
监控指标
系统暴露 Prometheus 格式的监控指标:
camera_count- 活跃摄像头数量camera_fps{camera_id="*"}- 各摄像头 FPSinference_latency_seconds{camera_id="*"}- 推理延迟alert_total{camera_id="*", event_type="*"}- 告警总数event_queue_size- 事件队列大小
Description
Languages
Python
73.1%
TypeScript
25.2%
CSS
1.3%
Dockerfile
0.4%