在R2000上使用Frigate NVR进行枪支检测
介绍
Frigate NVR 是一个开源网络视频录像机,专为AI优先的边缘实时视频分析而设计。部署在配备Hailo的reComputer AI盒子上,该系统在本地接收多个摄像头流,运行量化目标检测模型,并在毫秒内发出MQTT事件,消除了云延迟和带宽成本。
对于此部署,我们扩展了Frigate现有的模型库,并添加了一个专门针对手枪和步枪识别进行微调的自定义yolov11s模型。当检测到枪支时,Frigate的规则引擎立即触发警报,为安全团队提供宝贵的几秒钟时间来封锁区域并协调响应,防止威胁升级。
先决条件
硬件要求
配置Frigate
修改PCIe设置
打开config.txt
:
sudo nano /boot/firmware/config.txt
Add the following to config.txt
:
dtparam=pciex1_gen=3
dtoverlay=pciex1-compat-pi5,no-mip
然后使用 Ctrl+x
保存文件并重启 AI 盒子。
安装 Docker 和 hailo-all
sudo apt update
sudo apt install hailo-all
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
sudo apt install docker-compose-plugin
Creating a yml file
创建 frigate.yml
文件以便 Docker Compose 可以运行 Frigate。
cd ~
sudo nano frigate.yml
Here is an example of frigate.yml
:
services:
frigate-hailo:
container_name: frigate-hailo
privileged: true
restart: unless-stopped
image: ghcr.io/blakeblackshear/frigate:0.16.0-beta3-standard-arm64
shm_size: "512mb" # calculate on your own
stop_grace_period: 30s # allow enough time to shut down the various services
devices:
- /dev/hailo0:/dev/hailo0
- /dev/video19:/dev/video19 # USB camera (physical device)
- /dev/video20:/dev/video20 # USB camera backup device
volumes:
- /etc/localtime:/etc/localtime:ro
- ./config/:/config
- ./data/db/:/data/db
- ./data/storage:/media/frigate
- ./media:/media/frigate # Mapping local media files to the container
- type: tmpfs
target: /tmp/cache
tmpfs:
size: 1g
ports:
- 5000:5000
environment:
- FRIGATE_RTSP_PASSWORD=password
- LIBVA_DRIVER_NAME=i965
group_add:
- "44" # video group
Download the case video:
mkdir media && cd media
wget -c \
"https://files.seeedstudio.com/wiki/reComputer/Application/Firearm_Detection_With_Frigate_NVR_on_R2130/model_cache/yolov11s.hef"
下载 YOLO 模型并创建 config.yml:
cd .. && mkdir config && cd config && mkdir model_cache
cd model_cache && wget https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.14.0/hailo8/yolov8n.hef
cd .. && nano config.yml
以下是一个示例 config.yml:
database:
path: /data/db/frigate.db
go2rtc:
streams:
# USB camera streaming
usb_camera:
- "ffmpeg:/dev/video0#input=-f v4l2 -input_format mjpeg -video_size 640x480 -framerate 15"
# RTSP stream configuration
hikvision_main:
- "rtsp://admin:[email protected]:554/h264/ch1/main/av_stream"
# Video file streaming - close.mp4
video_files_close:
- "ffmpeg:/media/frigate/close.mp4"
# Video file streaming - close2.mp4
video_files_close2:
- "ffmpeg:/media/frigate/close2.mp4"
# Video file streaming - y4.mp4
video_files_y4:
- "ffmpeg:/media/frigate/y4.mp4"
# Video file streaming - y5.mp4
video_files_y5:
- "ffmpeg:/media/frigate/y5.mp4"
cameras:
# USB camera
usb_camera:
ffmpeg:
inputs:
- path: /dev/video0
input_args: -f v4l2 -input_format mjpeg -video_size 640x480 -framerate 15
roles:
- record
- detect
detect:
width: 640
height: 480
fps: 3
record:
enabled: true
retain:
days: 7
mode: motion
objects:
track:
- gun
filters:
gun:
min_area: 10
max_area: 100000
threshold: 0.25
# Video file camera - close.mp4
video_files_close:
ffmpeg:
inputs:
- path: /media/frigate/close.mp4
input_args: -stream_loop -1 -re
roles:
- detect
- record
detect:
width: 1280
height: 720
fps: 2
record:
enabled: false
retain:
days: 3
mode: all
objects:
track:
- gun
filters:
gun:
min_area: 20
max_area: 500000
threshold: 0.25
# Video file camera - close2.mp4
video_files_close2:
ffmpeg:
inputs:
- path: /media/frigate/close2.mp4
input_args: -stream_loop -1 -re
roles:
- detect
- record
detect:
width: 1280
height: 720
fps: 2
record:
enabled: false
retain:
days: 3
mode: all
objects:
track:
- gun
filters:
gun:
min_area: 20
max_area: 500000
threshold: 0.25
# Video file camera - y4.mp4
video_files_y4:
ffmpeg:
inputs:
- path: /media/frigate/y4.mp4
input_args: -stream_loop -1 -re
roles:
- detect
- record
detect:
width: 1280
height: 720
fps: 3
record:
enabled: true
retain:
days: 3
mode: all
objects:
track:
- gun
filters:
gun:
min_area: 10
max_area: 500000
threshold: 0.3
# Video file camera - y5.mp4
video_files_y5:
ffmpeg:
inputs:
- path: /media/frigate/y5.mp4
input_args: -stream_loop -1 -re
roles:
- detect
- record
detect:
width: 1280
height: 720
fps: 3
record:
enabled: true
retain:
days: 3
mode: all
objects:
track:
- gun
filters:
gun:
min_area: 10
max_area: 500000
threshold: 0.25
# RTSP IP camera - hikvision
hikvision_main:
ffmpeg:
inputs:
- path: rtsp://admin:[email protected]:554/h264/ch1/main/av_stream
input_args: -rtsp_transport tcp -avoid_negative_ts make_zero
roles:
- detect
- record
detect:
width: 1920
height: 1080
fps: 3
record:
enabled: true
retain:
days: 7
mode: motion
objects:
track:
- gun
filters:
gun:
min_area: 20
max_area: 500000
threshold: 0.25
mqtt:
enabled: false
objects:
track:
- gun
filters:
gun:
min_area: 10
max_area: 500000
threshold: 0.25
detectors:
hailo8l:
type: hailo8l
device: PCIe
model:
width: 640
height: 640
input_tensor: nhwc
input_pixel_format: rgb
input_dtype: int
model_type: yolo-generic
path: /config/model_cache/yolov11s.hef
labelmap:
0: person
1: gun
detect:
enabled: true
snapshots:
enabled: true
clean_copy: true
timestamp: true
bounding_box: true
crop: false
retain:
default: 14
quality: 95
record:
enabled: true
retain:
days: 30
mode: all
ui:
timezone: Asia/Shanghai
auth:
enabled: false
live:
height: 720
quality: 8
birdseye:
enabled: true
width: 1280
height: 720
quality: 8
mode: objects
version: 0.16-0
semantic_search:
enabled: false
reindex: false
model_size: small
face_recognition:
enabled: false
lpr:
enabled: false
Run the project
拉取并运行项目:
cd ~
sudo docker pull mjqx2023/frigate_seeed
docker compose -f frigate.yml up -d
然后在AI盒子的网页浏览器中打开 localhost:5000:

选择其中一个视频开始调试,选择显示框,结果将自动显示:


切换标签页查看过去的测试结果:

结果
当它看到有人持枪时,模型将识别并选中它。 切换到调试模式,选择显示框,结果将自动显示;切换标签页查看过去的检测结果。
其他配置
其他视频源配置 | 帧率配置 |
---|---|
Frigate 支持RTSP、视频流和USB摄像头。配置文件配置完成后,重启后生效。 | 配置文件可以配置每个摄像头的检测帧率,重启后生效。 |
您可以在设置中访问配置选项,例如更改RTSP路径以连接到RTSP摄像头。完成更改后,点击右上角的保存并重启以使更改生效。 | ![]() |
技术支持与产品讨论
感谢您选择我们的产品!我们在这里为您提供不同的支持,以确保您使用我们产品的体验尽可能顺畅。我们提供多种沟通渠道,以满足不同的偏好和需求。