video_monitor/app/analysis/__init__.py
2026-08-30 22:23:12 +08:00

31 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Monitor · 视频分析层阶段1
模块构成:
- frames 从 ZLMediaKit 输出的 RTSP 流取帧OpenCV VideoCapture
- motion 运动检测OpenCV 背景减除)
- detector 目标检测ONNX Runtime缺模型时优雅降级
- tracker 单摄像头目标跟踪(轻量 IoU 关联)
- pipeline 单摄像头流水线:取帧 → 运动 → 检测 → 跟踪 → 事件
- worker_pool 多路共享的检测器进程池
- manager 全局分析管理器(启动/停止每路 pipeline单例
设计原则:
- 全部用 Python 实现,不引入 C++ 服务。
- 运动门控:仅在有运动的区域跑检测,显著降低 CPU/GPU 占用。
- 与 ZLMediaKit 解耦:通过 ZLM 输出的 RTSP URL 取帧ZLM 仅负责协议接入。
- 优雅降级:未安装 opencv/numpy/onnxruntime 或未配置模型时Web 层Zone/Review/
Timeline/TrackedObject仍可正常使用"启动分析"会提示依赖不可用。
为避免在 Django 启动期就拉起 OpenCV/ONNX 等较重依赖,本包不在此处 eager 导入
AnalysisManager请通过 get_manager() 按需获取。
"""
def get_manager():
"""懒加载并返回全局 AnalysisManager 单例"""
from app.analysis.manager import AnalysisManager
return AnalysisManager()
__all__ = ["get_manager"]