Skip to main content

基于Raspberry Pi 5的Frigate NVR

介绍

Frigate NVR 是一个开源网络视频录像机,专为使用AI模型进行实时目标检测而设计。与 Raspberry Pi 5 配合使用,可在边缘实现高效的视频监控。本指南将引导您完成安装和配置过程,以获得最佳设置。

官方 Frigate

准备硬件

推荐组件

reComputer AI R2130

另外,您还需要至少一个摄像头用于视频流传输。您可以参考推荐硬件查看推荐的摄像头。

安装Hailo PCIe驱动

步骤1:启用PCIe Gen 3

打开终端并运行以下命令。

sudo apt update
sudo raspi-config

在对话框中,选择 6 Advanced Options,然后选择 A8 PCIe Speed

6 Advanced Options A8 PCIe Speed

选择"Yes"以启用 PCIe Gen 3 模式。

Choose Yes

之后,点击"Finish"退出。

编辑 /boot/firmware/config.txt,在文件末尾添加以下行。

dtoverlay=pciex1-compat-pi5,no-mip

步骤 2:安装 Hailo PCIe 驱动程序

安装 dkms 包。安装 Hailo PCIe 驱动程序需要此包。

sudo apt update
sudo apt install dkms

Get Hailo PCIe Driver from GitHub.

git clone https://github.com/hailo-ai/hailort-drivers
cd hailort-drivers/linux/pcie
git checkout 24e7ff2fb58fab7029024c1a1d3f2d1914f56d7b

Then, install the Hailo PCIe driver.

sudo make install_dkms

After installation, download firmware for Hailo and copy it to the /lib/firmware/hailo directory.

cd ../..
./download_firmware.sh
sudo mkdir -p /lib/firmware/hailo
sudo cp hailo8_fw*.bin /lib/firmware/hailo/hailo8_fw.bin

为了避免 PCIe max_desc_page_size 问题,我们还需要在 /etc/modprobe.d/hailo_pci.conf 中创建一个规则,内容如下。

options hailo_pci force_desc_page_size=4096

Restart the system to take effect.

sudo reboot

系统重启后,Hailo PCIe 驱动程序安装成功。将创建 /dev/hailo0 设备。通过运行以下命令检查设备。

$ ls /dev/hailo*
/dev/hailo0

安装 Frigate NVR

在这一部分,我们假设您已经设置好摄像头并准备好使用 RTSP 协议以 1920x1080 分辨率进行流媒体传输。

  • 示例 RTSP URL:rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0

步骤 1:准备环境

  1. 更新您的系统:

    sudo apt update
  2. 安装 Docker:

    curl -fsSL get.docker.com | bash
    sudo usermod -aG docker $USER
  3. Reboot the system:

    sudo reboot

步骤 2:部署 Frigate

  1. 拉取 Frigate 镜像:

    前往 Package frigate,选择一个带有 -h8l 后缀的镜像。在这个例子中,我们选择 ghcr.io/blakeblackshear/frigate:0.15.0-rc2-h8l

    docker pull ghcr.io/blakeblackshear/frigate:0.15.0-rc2-h8l
  2. 创建 Docker Compose 文件:

    这是 frigate.yml 文件的示例,hailo0 设备是您在上一步中创建的设备,配置文件位于 ./config 目录中,数据文件位于 ./data 目录中:

    services:
    frigate-hailo:
    container_name: frigate-hailo
    privileged: true
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:0.15.0-rc2-h8l
    shm_size: 1024mb
    devices:
    - /dev/hailo0:/dev/hailo0
    volumes:
    - /etc/localtime:/etc/localtime:ro
    - ./config/:/config
    - ./data/db/:/data/db
    - ./data/storage:/media/frigate
    - type: tmpfs
    target: /tmp/cache
    tmpfs:
    size: 1g
    ports:
    - 5000:5000
  3. 编辑 Frigate 配置:

    这是 config/config.yml 文件的示例,用于 Frigate 应用程序:

    database:
    path: /data/db/frigate.db

    go2rtc:
    streams:
    home:
    - rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0

    cameras:
    home:
    ffmpeg:
    inputs:
    - path: rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0
    roles:
    - record
    - detect

    mqtt:
    enabled: False

    objects:
    track:
    - person
    - cat

    detectors:
    hailo8l:
    type: hailo8l
    device: PCIe

    model:
    width: 300
    height: 300
    model_type: ssd
    path: /config/model_cache/h8l_cache/ssd_mobilenet_v1.hef

    version: 0.15-1
  4. 启动 Docker 实例:

    docker compose -f frigate.yml up -d

    Frigate 启动并运行后,您可以通过 http://<your-raspberry-pi-ip>:5000 访问 Frigate Web UI 来检查摄像头流。

    frigate-web

Seeed Frigate

修改 PCIe 设置

打开 config.txt

sudo nano /boot/firmware/config.txt 

Add the following text to config.txt

dtparam=pciex1_gen=3
dtoverlay=pciex1-compat-pi5,no-mip

Then use Ctrl+x to save the file and reboot the AI box

Install docker and 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

Create yml file

Create frigate.yml for docker compose to run frigate

cd ~
sudo nano frigate.yml

Here is an example of frigate.yml

version: "3.9"
services:
frigate-hailo:
container_name: frigate-hailo
privileged: true
restart: unless-stopped
image: mjqx2023/frigate_seeed:latest
shm_size: 1024mb
environment:
- HAILO_MONITOR=1
devices:
- /dev/hailo0:/dev/hailo0
volumes:
- /etc/localtime:/etc/localtime:ro
- ./config/:/config
- ./data/db/:/data/db
- ./data/storage:/media/frigate
- type: tmpfs
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- 5000:5000
- 1984:1984
- 5002:5002
- 5003:5003

Download yolo model and create config.yml.

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

Here is an example of config.yml

database:
path: /data/db/frigate.db

go2rtc:
streams:
home:
- rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1
home1:
- rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1
yard:
- rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1
yard1:
- rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1

cameras:
home:
ffmpeg:
inputs:
- path: rtsp://127.0.0.1:8554/home
roles:
- detect

motion:
threshold: 45
contour_area: 60
improve_contrast: true

yard:
ffmpeg:
inputs:
- path: rtsp://127.0.0.1:8554/yard
roles:
- detect

motion:
threshold: 45
contour_area: 60
improve_contrast: true

home1:
ffmpeg:
inputs:
- path: rtsp://127.0.0.1:8554/home1
roles:
- detect


motion:
threshold: 45
contour_area: 60
improve_contrast: true

yard1:
ffmpeg:
inputs:
- path: rtsp://127.0.0.1:8554/yard1
roles:
- detect

motion:
threshold: 45
contour_area: 60
improve_contrast: true
mqtt:
enabled: false

objects:
track:
- person
- cat

detectors:
hailo8l:
type: hailo8l
device: PCIe

model:
width: 640
height: 640
path: /config/model_cache/yolov8n.hef

version: 0.16-0

camera_groups:
test:
order: 1
icon: LuAlignEndHorizontal
cameras:
- home
- home1
- yard
- yard1

Pull docker image and run frigate

Pull frigate_seeed image

cd ~
docker pull mjqx2023/frigate_seeed
docker compose -f frigate.yml start

然后在您的 AI 盒子网页浏览器中打开 localhost:5000frigate-web

技术支持与产品讨论

感谢您选择我们的产品!我们在这里为您提供不同的支持,以确保您使用我们产品的体验尽可能顺畅。我们提供多种沟通渠道,以满足不同的偏好和需求。

Loading Comments...