Skip to main content

R2000でのFrigate NVRによる銃器検出

はじめに

Frigate NVRは、エッジでのAIファーストなリアルタイム映像解析のために設計されたオープンソースのネットワークビデオレコーダーです。Hailoを搭載したreComputer AIボックスに展開されたこのシステムは、複数のカメラストリームをローカルで取り込み、定量的物体検出モデルを実行し、ミリ秒以内にMQTTイベントを発信することで、クラウドの遅延と帯域幅コストを排除します。

この展開では、Frigateの既存のモデルライブラリを拡張し、ピストルとライフルの認識に特化してファインチューニングされたカスタムyolov11sモデルを追加しました。銃器が検出されると、Frigateのルールエンジンが即座にアラートをトリガーし、セキュリティチームに脅威がエスカレートする前にエリアを封鎖し、対応を調整するための貴重な数秒を与えます。

前提条件

ハードウェア要件

reComputer AI Industrial R2000reComputer AI R2000

Frigateの設定

PCIe設定の変更

config.txtを開く:

sudo nano /boot/firmware/config.txt

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

ymlファイルの作成

Docker ComposeがFrigateを実行できるようにfrigate.ymlファイルを作成します。

cd ~
sudo nano frigate.yml

以下は 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

ケースビデオをダウンロード:

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

Pull and run the project:

cd ~
sudo docker pull mjqx2023/frigate_seeed
docker compose -f frigate.yml up -d

AIボックスのWebブラウザでlocalhost:5000を開きます:

デバッグを開始するビデオの1つを選択し、表示ボックスを選択すると、結果が自動的に表示されます:

タブを切り替えて過去のテスト結果を表示します:

結果

銃を持っている人を検出すると、モデルがそれを識別して選択します。 デバッグモードに切り替え、表示ボックスを選択すると結果が自動的に表示されます。タブを切り替えて過去の検出結果を表示できます。

pir

その他の設定

その他のビデオソースの設定フレームレート設定
FrigateはRTSP、ビデオストリーミング、USBカメラをサポートしています。設定ファイルが設定されると、再起動後に有効になります。設定ファイルで各カメラの検出フレームレートを設定でき、再起動後に有効になります。
設定でRTSPパスを変更してRTSPカメラに接続するなどの設定オプションにアクセスできます。変更を行った後、右上の「Save & Restart」をクリックして変更を有効にします。page

技術サポート & 製品ディスカッション

弊社製品をお選びいただき、ありがとうございます!お客様の製品体験を可能な限りスムーズにするため、さまざまなサポートを提供いたします。異なる好みやニーズに対応するため、複数のコミュニケーションチャネルをご用意しております。

Loading Comments...