forked from Github/frigate
Compare commits
49 Commits
v0.1.0
...
v0.2.2-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a3afe14bf | ||
|
|
01f058a482 | ||
|
|
d899ef158e | ||
|
|
39d64f7ba7 | ||
|
|
f148eb5a7b | ||
|
|
297e2f1c0c | ||
|
|
e818744d81 | ||
|
|
ceedfae993 | ||
|
|
e13563770d | ||
|
|
a659019d1a | ||
|
|
ba71927d53 | ||
|
|
04fed31eac | ||
|
|
ebaa8fac01 | ||
|
|
2ec45cd1b6 | ||
|
|
700bd1e3ef | ||
|
|
c9e9f7a735 | ||
|
|
aea4dc8724 | ||
|
|
12d5007b90 | ||
|
|
8970e73f75 | ||
|
|
1ba006b24f | ||
|
|
4a58f16637 | ||
|
|
436b876b24 | ||
|
|
a770ab7f69 | ||
|
|
806acaf445 | ||
|
|
c653567cc1 | ||
|
|
8fee8f86a2 | ||
|
|
59a4b0e650 | ||
|
|
834a3df0bc | ||
|
|
c41b104997 | ||
|
|
7028b05856 | ||
|
|
2d22a04391 | ||
|
|
baa587028b | ||
|
|
2b51dc3e5b | ||
|
|
9f8278ea8f | ||
|
|
56b9c754f5 | ||
|
|
5c4f5ef3f0 | ||
|
|
8c924896c5 | ||
|
|
2c2f0044b9 | ||
|
|
874e9085a7 | ||
|
|
e791d6646b | ||
|
|
3019b0218c | ||
|
|
6900e140d5 | ||
|
|
911c1b2bfa | ||
|
|
f4587462cf | ||
|
|
cac1faa8ac | ||
|
|
9525bae5a3 | ||
|
|
dbcfd109f6 | ||
|
|
f95d8b6210 | ||
|
|
4dacf02ef9 |
@@ -1 +1,6 @@
|
|||||||
README.md
|
README.md
|
||||||
|
diagram.png
|
||||||
|
.gitignore
|
||||||
|
debug
|
||||||
|
config/
|
||||||
|
*.pyc
|
||||||
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ko_fi: blakeblackshear
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
debug
|
debug
|
||||||
|
.vscode
|
||||||
|
config/config.yml
|
||||||
136
Dockerfile
136
Dockerfile
@@ -1,71 +1,70 @@
|
|||||||
FROM ubuntu:16.04
|
FROM ubuntu:18.04
|
||||||
|
|
||||||
# Install system packages
|
ARG DEVICE
|
||||||
RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y python3 \
|
|
||||||
python3-dev \
|
# Install packages for apt repo
|
||||||
python-pil \
|
RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y \
|
||||||
python-lxml \
|
apt-transport-https \
|
||||||
python-tk \
|
ca-certificates \
|
||||||
|
curl \
|
||||||
|
wget \
|
||||||
|
gnupg-agent \
|
||||||
|
dirmngr \
|
||||||
|
software-properties-common \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY scripts/install_odroid_repo.sh .
|
||||||
|
|
||||||
|
RUN if [ "$DEVICE" = "odroid" ]; then \
|
||||||
|
sh /install_odroid_repo.sh; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y \
|
||||||
|
python3 \
|
||||||
|
# OpenCV dependencies
|
||||||
|
ffmpeg \
|
||||||
build-essential \
|
build-essential \
|
||||||
cmake \
|
cmake \
|
||||||
git \
|
unzip \
|
||||||
libgtk2.0-dev \
|
pkg-config \
|
||||||
pkg-config \
|
|
||||||
libavcodec-dev \
|
|
||||||
libavformat-dev \
|
|
||||||
libswscale-dev \
|
|
||||||
libtbb2 \
|
|
||||||
libtbb-dev \
|
|
||||||
libjpeg-dev \
|
libjpeg-dev \
|
||||||
libpng-dev \
|
libpng-dev \
|
||||||
libtiff-dev \
|
libtiff-dev \
|
||||||
libjasper-dev \
|
libavcodec-dev \
|
||||||
libdc1394-22-dev \
|
libavformat-dev \
|
||||||
x11-apps \
|
libswscale-dev \
|
||||||
wget \
|
libv4l-dev \
|
||||||
vim \
|
libxvidcore-dev \
|
||||||
ffmpeg \
|
libx264-dev \
|
||||||
unzip \
|
libgtk-3-dev \
|
||||||
libusb-1.0-0-dev \
|
libatlas-base-dev \
|
||||||
python3-setuptools \
|
gfortran \
|
||||||
|
python3-dev \
|
||||||
|
# Coral USB Python API Dependencies
|
||||||
|
libusb-1.0-0 \
|
||||||
|
python3-pip \
|
||||||
|
python3-pil \
|
||||||
python3-numpy \
|
python3-numpy \
|
||||||
zlib1g-dev \
|
libc++1 \
|
||||||
libgoogle-glog-dev \
|
libc++abi1 \
|
||||||
swig \
|
libunwind8 \
|
||||||
libunwind-dev \
|
libgcc1 \
|
||||||
libc++-dev \
|
# VAAPI drivers for Intel hardware accel
|
||||||
libc++abi-dev \
|
libva-drm2 libva2 i965-va-driver vainfo \
|
||||||
build-essential \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install core packages
|
# Install core packages
|
||||||
RUN wget -q -O /tmp/get-pip.py --no-check-certificate https://bootstrap.pypa.io/get-pip.py && python3 /tmp/get-pip.py
|
RUN wget -q -O /tmp/get-pip.py --no-check-certificate https://bootstrap.pypa.io/get-pip.py && python3 /tmp/get-pip.py
|
||||||
RUN pip install -U pip \
|
RUN pip install -U pip \
|
||||||
numpy \
|
numpy \
|
||||||
pillow \
|
|
||||||
matplotlib \
|
|
||||||
notebook \
|
|
||||||
Flask \
|
Flask \
|
||||||
imutils \
|
|
||||||
paho-mqtt \
|
paho-mqtt \
|
||||||
PyYAML
|
PyYAML
|
||||||
|
|
||||||
# Install tensorflow models object detection
|
|
||||||
RUN GIT_SSL_NO_VERIFY=true git clone -q https://github.com/tensorflow/models /usr/local/lib/python3.5/dist-packages/tensorflow/models
|
|
||||||
RUN wget -q -P /usr/local/src/ --no-check-certificate https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-python-3.5.1.tar.gz
|
|
||||||
|
|
||||||
# Download & build protobuf-python
|
|
||||||
RUN cd /usr/local/src/ \
|
|
||||||
&& tar xf protobuf-python-3.5.1.tar.gz \
|
|
||||||
&& rm protobuf-python-3.5.1.tar.gz \
|
|
||||||
&& cd /usr/local/src/protobuf-3.5.1/ \
|
|
||||||
&& ./configure \
|
|
||||||
&& make \
|
|
||||||
&& make install \
|
|
||||||
&& ldconfig \
|
|
||||||
&& rm -rf /usr/local/src/protobuf-3.5.1/
|
|
||||||
|
|
||||||
# Download & build OpenCV
|
# Download & build OpenCV
|
||||||
|
# TODO: use multistage build to reduce image size:
|
||||||
|
# https://medium.com/@denismakogon/pain-and-gain-running-opencv-application-with-golang-and-docker-on-alpine-3-7-435aa11c7aec
|
||||||
|
# https://www.merixstudio.com/blog/docker-multi-stage-builds-python-development/
|
||||||
RUN wget -q -P /usr/local/src/ --no-check-certificate https://github.com/opencv/opencv/archive/4.0.1.zip
|
RUN wget -q -P /usr/local/src/ --no-check-certificate https://github.com/opencv/opencv/archive/4.0.1.zip
|
||||||
RUN cd /usr/local/src/ \
|
RUN cd /usr/local/src/ \
|
||||||
&& unzip 4.0.1.zip \
|
&& unzip 4.0.1.zip \
|
||||||
@@ -76,32 +75,35 @@ RUN cd /usr/local/src/ \
|
|||||||
&& cmake -D CMAKE_INSTALL_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/ .. \
|
&& cmake -D CMAKE_INSTALL_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/ .. \
|
||||||
&& make -j4 \
|
&& make -j4 \
|
||||||
&& make install \
|
&& make install \
|
||||||
|
&& ldconfig \
|
||||||
&& rm -rf /usr/local/src/opencv-4.0.1
|
&& rm -rf /usr/local/src/opencv-4.0.1
|
||||||
|
|
||||||
# Download and install EdgeTPU libraries
|
# Download and install EdgeTPU libraries for Coral
|
||||||
RUN wget -q -O edgetpu_api.tar.gz --no-check-certificate http://storage.googleapis.com/cloud-iot-edge-pretrained-models/edgetpu_api.tar.gz
|
RUN wget https://dl.google.com/coral/edgetpu_api/edgetpu_api_latest.tar.gz -O edgetpu_api.tar.gz --trust-server-names \
|
||||||
|
&& tar xzf edgetpu_api.tar.gz
|
||||||
|
|
||||||
RUN tar xzf edgetpu_api.tar.gz \
|
COPY scripts/install_edgetpu_api.sh edgetpu_api/install.sh
|
||||||
&& cd python-tflite-source \
|
|
||||||
&& cp -p libedgetpu/libedgetpu_x86_64.so /lib/x86_64-linux-gnu/libedgetpu.so \
|
RUN cd edgetpu_api \
|
||||||
&& cp edgetpu/swig/compiled_so/_edgetpu_cpp_wrapper_x86_64.so edgetpu/swig/_edgetpu_cpp_wrapper.so \
|
&& /bin/bash install.sh
|
||||||
&& cp edgetpu/swig/compiled_so/edgetpu_cpp_wrapper.py edgetpu/swig/ \
|
|
||||||
&& python3 setup.py develop --user
|
# Copy a python 3.6 version
|
||||||
|
RUN cd /usr/local/lib/python3.6/dist-packages/edgetpu/swig/ \
|
||||||
|
&& ln -s _edgetpu_cpp_wrapper.cpython-35m-arm-linux-gnueabihf.so _edgetpu_cpp_wrapper.cpython-36m-arm-linux-gnueabihf.so
|
||||||
|
|
||||||
|
# symlink the model and labels
|
||||||
|
RUN wget https://dl.google.com/coral/canned_models/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite -O mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --trust-server-names
|
||||||
|
RUN wget https://dl.google.com/coral/canned_models/coco_labels.txt -O coco_labels.txt --trust-server-names
|
||||||
|
RUN ln -s mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite /frozen_inference_graph.pb
|
||||||
|
RUN ln -s /coco_labels.txt /label_map.pbtext
|
||||||
|
|
||||||
# Minimize image size
|
# Minimize image size
|
||||||
RUN (apt-get autoremove -y; \
|
RUN (apt-get autoremove -y; \
|
||||||
apt-get autoclean -y)
|
apt-get autoclean -y)
|
||||||
|
|
||||||
# symlink the model and labels
|
|
||||||
RUN ln -s /python-tflite-source/edgetpu/test_data/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite /frozen_inference_graph.pb
|
|
||||||
RUN ln -s /python-tflite-source/edgetpu/test_data/coco_labels.txt /label_map.pbtext
|
|
||||||
|
|
||||||
# Set TF object detection available
|
|
||||||
ENV PYTHONPATH "$PYTHONPATH:/usr/local/lib/python3.5/dist-packages/tensorflow/models/research:/usr/local/lib/python3.5/dist-packages/tensorflow/models/research/slim"
|
|
||||||
RUN cd /usr/local/lib/python3.5/dist-packages/tensorflow/models/research && protoc object_detection/protos/*.proto --python_out=.
|
|
||||||
|
|
||||||
WORKDIR /opt/frigate/
|
WORKDIR /opt/frigate/
|
||||||
ADD frigate frigate/
|
ADD frigate frigate/
|
||||||
COPY detect_objects.py .
|
COPY detect_objects.py .
|
||||||
|
COPY benchmark.py .
|
||||||
|
|
||||||
CMD ["python3", "-u", "detect_objects.py"]
|
CMD ["python3", "-u", "detect_objects.py"]
|
||||||
|
|||||||
44
README.md
44
README.md
@@ -1,7 +1,9 @@
|
|||||||
# Frigate - Realtime Object Detection for RTSP Cameras
|
<a href='https://ko-fi.com/P5P7XGO9' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi4.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||||||
|
|
||||||
|
# Frigate - Realtime Object Detection for IP Cameras
|
||||||
**Note:** This version requires the use of a [Google Coral USB Accelerator](https://coral.withgoogle.com/products/accelerator/)
|
**Note:** This version requires the use of a [Google Coral USB Accelerator](https://coral.withgoogle.com/products/accelerator/)
|
||||||
|
|
||||||
Uses OpenCV and Tensorflow to perform realtime object detection locally for RTSP cameras. Designed for integration with HomeAssistant or others via MQTT.
|
Uses OpenCV and Tensorflow to perform realtime object detection locally for IP cameras. Designed for integration with HomeAssistant or others via MQTT.
|
||||||
|
|
||||||
- Leverages multiprocessing and threads heavily with an emphasis on realtime over processing every frame
|
- Leverages multiprocessing and threads heavily with an emphasis on realtime over processing every frame
|
||||||
- Allows you to define specific regions (squares) in the image to look for objects
|
- Allows you to define specific regions (squares) in the image to look for objects
|
||||||
@@ -30,8 +32,9 @@ docker run --rm \
|
|||||||
--privileged \
|
--privileged \
|
||||||
-v /dev/bus/usb:/dev/bus/usb \
|
-v /dev/bus/usb:/dev/bus/usb \
|
||||||
-v <path_to_config_dir>:/config:ro \
|
-v <path_to_config_dir>:/config:ro \
|
||||||
|
-v /etc/localtime:/etc/localtime:ro \
|
||||||
-p 5000:5000 \
|
-p 5000:5000 \
|
||||||
-e RTSP_PASSWORD='password' \
|
-e FRIGATE_RTSP_PASSWORD='password' \
|
||||||
frigate:latest
|
frigate:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -44,14 +47,15 @@ Example docker-compose:
|
|||||||
image: frigate:latest
|
image: frigate:latest
|
||||||
volumes:
|
volumes:
|
||||||
- /dev/bus/usb:/dev/bus/usb
|
- /dev/bus/usb:/dev/bus/usb
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
- <path_to_config>:/config
|
- <path_to_config>:/config
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "5000:5000"
|
||||||
environment:
|
environment:
|
||||||
RTSP_PASSWORD: "password"
|
FRIGATE_RTSP_PASSWORD: "password"
|
||||||
```
|
```
|
||||||
|
|
||||||
A `config.yml` file must exist in the `config` directory. See example [here](config/config.yml).
|
A `config.yml` file must exist in the `config` directory. See example [here](config/config.yml) and device specific info can be found [here](docs/DEVICES.md).
|
||||||
|
|
||||||
Access the mjpeg stream at `http://localhost:5000/<camera_name>` and the best person snapshot at `http://localhost:5000/<camera_name>/best_person.jpg`
|
Access the mjpeg stream at `http://localhost:5000/<camera_name>` and the best person snapshot at `http://localhost:5000/<camera_name>/best_person.jpg`
|
||||||
|
|
||||||
@@ -59,20 +63,40 @@ Access the mjpeg stream at `http://localhost:5000/<camera_name>` and the best pe
|
|||||||
```
|
```
|
||||||
camera:
|
camera:
|
||||||
- name: Camera Last Person
|
- name: Camera Last Person
|
||||||
platform: generic
|
platform: mqtt
|
||||||
still_image_url: http://<ip>:5000/<camera_name>/best_person.jpg
|
topic: frigate/<camera_name>/snapshot
|
||||||
|
|
||||||
sensor:
|
binary_sensor:
|
||||||
- name: Camera Person
|
- name: Camera Person
|
||||||
platform: mqtt
|
platform: mqtt
|
||||||
state_topic: "frigate/<camera_name>/objects"
|
state_topic: "frigate/<camera_name>/objects"
|
||||||
value_template: '{{ value_json.person }}'
|
value_template: '{{ value_json.person }}'
|
||||||
device_class: moving
|
device_class: motion
|
||||||
availability_topic: "frigate/available"
|
availability_topic: "frigate/available"
|
||||||
|
|
||||||
|
automation:
|
||||||
|
- alias: Alert me if a person is detected while armed away
|
||||||
|
trigger:
|
||||||
|
platform: state
|
||||||
|
entity_id: binary_sensor.camera_person
|
||||||
|
from: 'off'
|
||||||
|
to: 'on'
|
||||||
|
condition:
|
||||||
|
- condition: state
|
||||||
|
entity_id: alarm_control_panel.home_alarm
|
||||||
|
state: armed_away
|
||||||
|
action:
|
||||||
|
- service: notify.user_telegram
|
||||||
|
data:
|
||||||
|
message: "A person was detected."
|
||||||
|
data:
|
||||||
|
photo:
|
||||||
|
- url: http://<ip>:5000/<camera_name>/best_person.jpg
|
||||||
|
caption: A person was detected.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tips
|
## Tips
|
||||||
- Lower the framerate of the RTSP feed on the camera to reduce the CPU usage for capturing the feed
|
- Lower the framerate of the video feed on the camera to reduce the CPU usage for capturing the feed
|
||||||
|
|
||||||
## Future improvements
|
## Future improvements
|
||||||
- [x] Remove motion detection for now
|
- [x] Remove motion detection for now
|
||||||
|
|||||||
20
benchmark.py
Normal file
20
benchmark.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import statistics
|
||||||
|
import numpy as np
|
||||||
|
from edgetpu.detection.engine import DetectionEngine
|
||||||
|
|
||||||
|
# Path to frozen detection graph. This is the actual model that is used for the object detection.
|
||||||
|
PATH_TO_CKPT = '/frozen_inference_graph.pb'
|
||||||
|
|
||||||
|
# Load the edgetpu engine and labels
|
||||||
|
engine = DetectionEngine(PATH_TO_CKPT)
|
||||||
|
|
||||||
|
frame = np.zeros((300,300,3), np.uint8)
|
||||||
|
flattened_frame = np.expand_dims(frame, axis=0).flatten()
|
||||||
|
|
||||||
|
detection_times = []
|
||||||
|
|
||||||
|
for x in range(0, 1000):
|
||||||
|
objects = engine.DetectWithInputTensor(flattened_frame, threshold=0.1, top_k=3)
|
||||||
|
detection_times.append(engine.get_inference_time())
|
||||||
|
|
||||||
|
print("Average inference time: " + str(statistics.mean(detection_times)))
|
||||||
BIN
config/back-mask.bmp
Normal file
BIN
config/back-mask.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
110
config/config.example.yml
Normal file
110
config/config.example.yml
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
web_port: 5000
|
||||||
|
|
||||||
|
mqtt:
|
||||||
|
host: mqtt.server.com
|
||||||
|
topic_prefix: frigate
|
||||||
|
# client_id: frigate # Optional -- set to override default client id of 'frigate' if running multiple instances
|
||||||
|
# user: username # Optional -- Uncomment for use
|
||||||
|
# password: password # Optional -- Uncomment for use
|
||||||
|
|
||||||
|
#################
|
||||||
|
# Default ffmpeg args. Optional and can be overwritten per camera.
|
||||||
|
# Should work with most RTSP cameras that send h264 video
|
||||||
|
# Built from the properties below with:
|
||||||
|
# "ffmpeg" + global_args + input_args + "-i" + input + output_args
|
||||||
|
#################
|
||||||
|
# ffmpeg:
|
||||||
|
# global_args:
|
||||||
|
# - -hide_banner
|
||||||
|
# - -loglevel
|
||||||
|
# - panic
|
||||||
|
# hwaccel_args: []
|
||||||
|
# input_args:
|
||||||
|
# - -avoid_negative_ts
|
||||||
|
# - make_zero
|
||||||
|
# - -fflags
|
||||||
|
# - nobuffer
|
||||||
|
# - -flags
|
||||||
|
# - low_delay
|
||||||
|
# - -strict
|
||||||
|
# - experimental
|
||||||
|
# - -fflags
|
||||||
|
# - +genpts+discardcorrupt
|
||||||
|
# - -vsync
|
||||||
|
# - drop
|
||||||
|
# - -rtsp_transport
|
||||||
|
# - tcp
|
||||||
|
# - -stimeout
|
||||||
|
# - '5000000'
|
||||||
|
# - -use_wallclock_as_timestamps
|
||||||
|
# - '1'
|
||||||
|
# output_args:
|
||||||
|
# - -vf
|
||||||
|
# - mpdecimate
|
||||||
|
# - -f
|
||||||
|
# - rawvideo
|
||||||
|
# - -pix_fmt
|
||||||
|
# - rgb24
|
||||||
|
|
||||||
|
cameras:
|
||||||
|
back:
|
||||||
|
ffmpeg:
|
||||||
|
################
|
||||||
|
# Source passed to ffmpeg after the -i parameter. Supports anything compatible with OpenCV and FFmpeg.
|
||||||
|
# Environment variables that begin with 'FRIGATE_' may be referenced in {}
|
||||||
|
################
|
||||||
|
input: rtsp://viewer:{FRIGATE_RTSP_PASSWORD}@10.0.10.10:554/cam/realmonitor?channel=1&subtype=2
|
||||||
|
#################
|
||||||
|
# These values will override default values for just this camera
|
||||||
|
#################
|
||||||
|
# global_args: []
|
||||||
|
# hwaccel_args: []
|
||||||
|
# input_args: []
|
||||||
|
# output_args: []
|
||||||
|
|
||||||
|
################
|
||||||
|
## Optional mask. Must be the same dimensions as your video feed.
|
||||||
|
## The mask works by looking at the bottom center of the bounding box for the detected
|
||||||
|
## person in the image. If that pixel in the mask is a black pixel, it ignores it as a
|
||||||
|
## false positive. In my mask, the grass and driveway visible from my backdoor camera
|
||||||
|
## are white. The garage doors, sky, and trees (anywhere it would be impossible for a
|
||||||
|
## person to stand) are black.
|
||||||
|
################
|
||||||
|
# mask: back-mask.bmp
|
||||||
|
|
||||||
|
################
|
||||||
|
# Allows you to limit the framerate within frigate for cameras that do not support
|
||||||
|
# custom framerates. A value of 1 tells frigate to look at every frame, 2 every 2nd frame,
|
||||||
|
# 3 every 3rd frame, etc.
|
||||||
|
################
|
||||||
|
take_frame: 1
|
||||||
|
|
||||||
|
################
|
||||||
|
# size: size of the region in pixels
|
||||||
|
# x_offset/y_offset: position of the upper left corner of your region (top left of image is 0,0)
|
||||||
|
# min_person_area (optional): minimum width*height of the bounding box for the detected person
|
||||||
|
# max_person_area (optional): maximum width*height of the bounding box for the detected person
|
||||||
|
# threshold (optional): The minimum decimal percentage (50% hit = 0.5) for the confidence from tensorflow
|
||||||
|
# Tips: All regions are resized to 300x300 before detection because the model is trained on that size.
|
||||||
|
# Resizing regions takes CPU power. Ideally, all regions should be as close to 300x300 as possible.
|
||||||
|
# Defining a region that goes outside the bounds of the image will result in errors.
|
||||||
|
################
|
||||||
|
regions:
|
||||||
|
- size: 350
|
||||||
|
x_offset: 0
|
||||||
|
y_offset: 300
|
||||||
|
min_person_area: 5000
|
||||||
|
max_person_area: 100000
|
||||||
|
threshold: 0.5
|
||||||
|
- size: 400
|
||||||
|
x_offset: 350
|
||||||
|
y_offset: 250
|
||||||
|
min_person_area: 2000
|
||||||
|
max_person_area: 100000
|
||||||
|
threshold: 0.5
|
||||||
|
- size: 400
|
||||||
|
x_offset: 750
|
||||||
|
y_offset: 250
|
||||||
|
min_person_area: 2000
|
||||||
|
max_person_area: 100000
|
||||||
|
threshold: 0.5
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
web_port: 5000
|
|
||||||
|
|
||||||
mqtt:
|
|
||||||
host: mqtt.server.com
|
|
||||||
topic_prefix: frigate
|
|
||||||
|
|
||||||
cameras:
|
|
||||||
back:
|
|
||||||
rtsp:
|
|
||||||
user: viewer
|
|
||||||
host: 10.0.10.10
|
|
||||||
port: 554
|
|
||||||
# values that begin with a "$" will be replaced with environment variable
|
|
||||||
password: $RTSP_PASSWORD
|
|
||||||
path: /cam/realmonitor?channel=1&subtype=2
|
|
||||||
regions:
|
|
||||||
- size: 350
|
|
||||||
x_offset: 0
|
|
||||||
y_offset: 300
|
|
||||||
min_person_area: 5000
|
|
||||||
- size: 400
|
|
||||||
x_offset: 350
|
|
||||||
y_offset: 250
|
|
||||||
min_person_area: 2000
|
|
||||||
- size: 400
|
|
||||||
x_offset: 750
|
|
||||||
y_offset: 250
|
|
||||||
min_person_area: 2000
|
|
||||||
back2:
|
|
||||||
rtsp:
|
|
||||||
user: viewer
|
|
||||||
host: 10.0.10.10
|
|
||||||
port: 554
|
|
||||||
# values that begin with a "$" will be replaced with environment variable
|
|
||||||
password: $RTSP_PASSWORD
|
|
||||||
path: /cam/realmonitor?channel=1&subtype=2
|
|
||||||
regions:
|
|
||||||
- size: 350
|
|
||||||
x_offset: 0
|
|
||||||
y_offset: 300
|
|
||||||
min_person_area: 5000
|
|
||||||
- size: 400
|
|
||||||
x_offset: 350
|
|
||||||
y_offset: 250
|
|
||||||
min_person_area: 2000
|
|
||||||
- size: 400
|
|
||||||
x_offset: 750
|
|
||||||
y_offset: 250
|
|
||||||
min_person_area: 2000
|
|
||||||
@@ -17,6 +17,30 @@ MQTT_PORT = CONFIG.get('mqtt', {}).get('port', 1883)
|
|||||||
MQTT_TOPIC_PREFIX = CONFIG.get('mqtt', {}).get('topic_prefix', 'frigate')
|
MQTT_TOPIC_PREFIX = CONFIG.get('mqtt', {}).get('topic_prefix', 'frigate')
|
||||||
MQTT_USER = CONFIG.get('mqtt', {}).get('user')
|
MQTT_USER = CONFIG.get('mqtt', {}).get('user')
|
||||||
MQTT_PASS = CONFIG.get('mqtt', {}).get('password')
|
MQTT_PASS = CONFIG.get('mqtt', {}).get('password')
|
||||||
|
MQTT_CLIENT_ID = CONFIG.get('mqtt', {}).get('client_id', 'frigate')
|
||||||
|
|
||||||
|
# Set the default FFmpeg config
|
||||||
|
FFMPEG_CONFIG = CONFIG.get('ffmpeg', {})
|
||||||
|
FFMPEG_DEFAULT_CONFIG = {
|
||||||
|
'global_args': FFMPEG_CONFIG.get('global_args',
|
||||||
|
['-hide_banner','-loglevel','panic']),
|
||||||
|
'hwaccel_args': FFMPEG_CONFIG.get('hwaccel_args',
|
||||||
|
[]),
|
||||||
|
'input_args': FFMPEG_CONFIG.get('input_args',
|
||||||
|
['-avoid_negative_ts', 'make_zero',
|
||||||
|
'-fflags', 'nobuffer',
|
||||||
|
'-flags', 'low_delay',
|
||||||
|
'-strict', 'experimental',
|
||||||
|
'-fflags', '+genpts+discardcorrupt',
|
||||||
|
'-vsync', 'drop',
|
||||||
|
'-rtsp_transport', 'tcp',
|
||||||
|
'-stimeout', '5000000',
|
||||||
|
'-use_wallclock_as_timestamps', '1']),
|
||||||
|
'output_args': FFMPEG_CONFIG.get('output_args',
|
||||||
|
['-vf', 'mpdecimate',
|
||||||
|
'-f', 'rawvideo',
|
||||||
|
'-pix_fmt', 'rgb24'])
|
||||||
|
}
|
||||||
|
|
||||||
WEB_PORT = CONFIG.get('web_port', 5000)
|
WEB_PORT = CONFIG.get('web_port', 5000)
|
||||||
DEBUG = (CONFIG.get('debug', '0') == '1')
|
DEBUG = (CONFIG.get('debug', '0') == '1')
|
||||||
@@ -25,9 +49,18 @@ def main():
|
|||||||
# connect to mqtt and setup last will
|
# connect to mqtt and setup last will
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
print("On connect called")
|
print("On connect called")
|
||||||
|
if rc != 0:
|
||||||
|
if rc == 3:
|
||||||
|
print ("MQTT Server unavailable")
|
||||||
|
elif rc == 4:
|
||||||
|
print ("MQTT Bad username or password")
|
||||||
|
elif rc == 5:
|
||||||
|
print ("MQTT Not authorized")
|
||||||
|
else:
|
||||||
|
print ("Unable to connect to MQTT: Connection refused. Error code: " + str(rc))
|
||||||
# publish a message to signal that the service is running
|
# publish a message to signal that the service is running
|
||||||
client.publish(MQTT_TOPIC_PREFIX+'/available', 'online', retain=True)
|
client.publish(MQTT_TOPIC_PREFIX+'/available', 'online', retain=True)
|
||||||
client = mqtt.Client()
|
client = mqtt.Client(client_id=MQTT_CLIENT_ID)
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.will_set(MQTT_TOPIC_PREFIX+'/available', payload='offline', qos=1, retain=True)
|
client.will_set(MQTT_TOPIC_PREFIX+'/available', payload='offline', qos=1, retain=True)
|
||||||
if not MQTT_USER is None:
|
if not MQTT_USER is None:
|
||||||
@@ -41,7 +74,7 @@ def main():
|
|||||||
|
|
||||||
cameras = {}
|
cameras = {}
|
||||||
for name, config in CONFIG['cameras'].items():
|
for name, config in CONFIG['cameras'].items():
|
||||||
cameras[name] = Camera(name, config, prepped_frame_queue, client, MQTT_TOPIC_PREFIX)
|
cameras[name] = Camera(name, FFMPEG_DEFAULT_CONFIG, config, prepped_frame_queue, client, MQTT_TOPIC_PREFIX)
|
||||||
|
|
||||||
prepped_queue_processor = PreppedQueueProcessor(
|
prepped_queue_processor = PreppedQueueProcessor(
|
||||||
cameras,
|
cameras,
|
||||||
@@ -56,21 +89,32 @@ def main():
|
|||||||
# create a flask app that encodes frames a mjpeg on demand
|
# create a flask app that encodes frames a mjpeg on demand
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def ishealthy():
|
||||||
|
# return a healh
|
||||||
|
return "Frigate is running. Alive and healthy!"
|
||||||
|
|
||||||
@app.route('/<camera_name>/best_person.jpg')
|
@app.route('/<camera_name>/best_person.jpg')
|
||||||
def best_person(camera_name):
|
def best_person(camera_name):
|
||||||
best_person_frame = cameras[camera_name].get_best_person()
|
if camera_name in cameras:
|
||||||
if best_person_frame is None:
|
best_person_frame = cameras[camera_name].get_best_person()
|
||||||
best_person_frame = np.zeros((720,1280,3), np.uint8)
|
if best_person_frame is None:
|
||||||
ret, jpg = cv2.imencode('.jpg', best_person_frame)
|
best_person_frame = np.zeros((720,1280,3), np.uint8)
|
||||||
response = make_response(jpg.tobytes())
|
ret, jpg = cv2.imencode('.jpg', best_person_frame)
|
||||||
response.headers['Content-Type'] = 'image/jpg'
|
response = make_response(jpg.tobytes())
|
||||||
return response
|
response.headers['Content-Type'] = 'image/jpg'
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return f'Camera named {camera_name} not found', 404
|
||||||
|
|
||||||
@app.route('/<camera_name>')
|
@app.route('/<camera_name>')
|
||||||
def mjpeg_feed(camera_name):
|
def mjpeg_feed(camera_name):
|
||||||
# return a multipart response
|
if camera_name in cameras:
|
||||||
return Response(imagestream(camera_name),
|
# return a multipart response
|
||||||
mimetype='multipart/x-mixed-replace; boundary=frame')
|
return Response(imagestream(camera_name),
|
||||||
|
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||||
|
else:
|
||||||
|
return f'Camera named {camera_name} not found', 404
|
||||||
|
|
||||||
def imagestream(camera_name):
|
def imagestream(camera_name):
|
||||||
while True:
|
while True:
|
||||||
@@ -87,4 +131,4 @@ def main():
|
|||||||
camera.join()
|
camera.join()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
74
docs/DEVICES.md
Normal file
74
docs/DEVICES.md
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# Configuration Examples
|
||||||
|
|
||||||
|
### Default (most RTSP cameras)
|
||||||
|
This is the default ffmpeg command and should work with most RTSP cameras that send h264 video
|
||||||
|
```yaml
|
||||||
|
ffmpeg:
|
||||||
|
global_args:
|
||||||
|
- -hide_banner
|
||||||
|
- -loglevel
|
||||||
|
- panic
|
||||||
|
hwaccel_args: []
|
||||||
|
input_args:
|
||||||
|
- -avoid_negative_ts
|
||||||
|
- make_zero
|
||||||
|
- -fflags
|
||||||
|
- nobuffer
|
||||||
|
- -flags
|
||||||
|
- low_delay
|
||||||
|
- -strict
|
||||||
|
- experimental
|
||||||
|
- -fflags
|
||||||
|
- +genpts+discardcorrupt
|
||||||
|
- -vsync
|
||||||
|
- drop
|
||||||
|
- -rtsp_transport
|
||||||
|
- tcp
|
||||||
|
- -stimeout
|
||||||
|
- '5000000'
|
||||||
|
- -use_wallclock_as_timestamps
|
||||||
|
- '1'
|
||||||
|
output_args:
|
||||||
|
- -vf
|
||||||
|
- mpdecimate
|
||||||
|
- -f
|
||||||
|
- rawvideo
|
||||||
|
- -pix_fmt
|
||||||
|
- rgb24
|
||||||
|
```
|
||||||
|
|
||||||
|
### RTMP Cameras
|
||||||
|
The input parameters need to be adjusted for RTMP cameras
|
||||||
|
```yaml
|
||||||
|
ffmpeg:
|
||||||
|
input_args:
|
||||||
|
- -avoid_negative_ts
|
||||||
|
- make_zero
|
||||||
|
- -fflags
|
||||||
|
- nobuffer
|
||||||
|
- -flags
|
||||||
|
- low_delay
|
||||||
|
- -strict
|
||||||
|
- experimental
|
||||||
|
- -fflags
|
||||||
|
- +genpts+discardcorrupt
|
||||||
|
- -vsync
|
||||||
|
- drop
|
||||||
|
- -use_wallclock_as_timestamps
|
||||||
|
- '1'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Hardware Acceleration
|
||||||
|
|
||||||
|
Intel Quicksync
|
||||||
|
```yaml
|
||||||
|
ffmpeg:
|
||||||
|
hwaccel_args:
|
||||||
|
- -hwaccel
|
||||||
|
- vaapi
|
||||||
|
- -hwaccel_device
|
||||||
|
- /dev/dri/renderD128
|
||||||
|
- -hwaccel_output_format
|
||||||
|
- yuv420p
|
||||||
|
```
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import json
|
import json
|
||||||
|
import cv2
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
class MqttObjectPublisher(threading.Thread):
|
class MqttObjectPublisher(threading.Thread):
|
||||||
def __init__(self, client, topic_prefix, objects_parsed, detected_objects):
|
def __init__(self, client, topic_prefix, objects_parsed, detected_objects, best_person_frame):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.client = client
|
self.client = client
|
||||||
self.topic_prefix = topic_prefix
|
self.topic_prefix = topic_prefix
|
||||||
self.objects_parsed = objects_parsed
|
self.objects_parsed = objects_parsed
|
||||||
self._detected_objects = detected_objects
|
self._detected_objects = detected_objects
|
||||||
|
self.best_person_frame = best_person_frame
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
last_sent_payload = ""
|
last_sent_payload = ""
|
||||||
@@ -30,4 +32,10 @@ class MqttObjectPublisher(threading.Thread):
|
|||||||
new_payload = json.dumps(payload, sort_keys=True)
|
new_payload = json.dumps(payload, sort_keys=True)
|
||||||
if new_payload != last_sent_payload:
|
if new_payload != last_sent_payload:
|
||||||
last_sent_payload = new_payload
|
last_sent_payload = new_payload
|
||||||
self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False)
|
self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False)
|
||||||
|
# send the snapshot over mqtt as well
|
||||||
|
if not self.best_person_frame.best_frame is None:
|
||||||
|
ret, jpg = cv2.imencode('.jpg', self.best_person_frame.best_frame)
|
||||||
|
if ret:
|
||||||
|
jpg_bytes = jpg.tobytes()
|
||||||
|
self.client.publish(self.topic_prefix+'/snapshot', jpg_bytes, retain=True)
|
||||||
@@ -38,7 +38,9 @@ class PreppedQueueProcessor(threading.Thread):
|
|||||||
frame = self.prepped_frame_queue.get()
|
frame = self.prepped_frame_queue.get()
|
||||||
|
|
||||||
# Actual detection.
|
# Actual detection.
|
||||||
objects = self.engine.DetectWithInputTensor(frame['frame'], threshold=0.5, top_k=3)
|
objects = self.engine.DetectWithInputTensor(frame['frame'], threshold=frame['region_threshold'], top_k=3)
|
||||||
|
# print(self.engine.get_inference_time())
|
||||||
|
|
||||||
# parse and pass detected objects back to the camera
|
# parse and pass detected objects back to the camera
|
||||||
parsed_objects = []
|
parsed_objects = []
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
@@ -59,7 +61,7 @@ class PreppedQueueProcessor(threading.Thread):
|
|||||||
class FramePrepper(threading.Thread):
|
class FramePrepper(threading.Thread):
|
||||||
def __init__(self, camera_name, shared_frame, frame_time, frame_ready,
|
def __init__(self, camera_name, shared_frame, frame_time, frame_ready,
|
||||||
frame_lock,
|
frame_lock,
|
||||||
region_size, region_x_offset, region_y_offset,
|
region_size, region_x_offset, region_y_offset, region_threshold,
|
||||||
prepped_frame_queue):
|
prepped_frame_queue):
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
@@ -71,6 +73,7 @@ class FramePrepper(threading.Thread):
|
|||||||
self.region_size = region_size
|
self.region_size = region_size
|
||||||
self.region_x_offset = region_x_offset
|
self.region_x_offset = region_x_offset
|
||||||
self.region_y_offset = region_y_offset
|
self.region_y_offset = region_y_offset
|
||||||
|
self.region_threshold = region_threshold
|
||||||
self.prepped_frame_queue = prepped_frame_queue
|
self.prepped_frame_queue = prepped_frame_queue
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -88,13 +91,11 @@ class FramePrepper(threading.Thread):
|
|||||||
cropped_frame = self.shared_frame[self.region_y_offset:self.region_y_offset+self.region_size, self.region_x_offset:self.region_x_offset+self.region_size].copy()
|
cropped_frame = self.shared_frame[self.region_y_offset:self.region_y_offset+self.region_size, self.region_x_offset:self.region_x_offset+self.region_size].copy()
|
||||||
frame_time = self.frame_time.value
|
frame_time = self.frame_time.value
|
||||||
|
|
||||||
# convert to RGB
|
|
||||||
cropped_frame_rgb = cv2.cvtColor(cropped_frame, cv2.COLOR_BGR2RGB)
|
|
||||||
# Resize to 300x300 if needed
|
# Resize to 300x300 if needed
|
||||||
if cropped_frame_rgb.shape != (300, 300, 3):
|
if cropped_frame.shape != (300, 300, 3):
|
||||||
cropped_frame_rgb = cv2.resize(cropped_frame_rgb, dsize=(300, 300), interpolation=cv2.INTER_LINEAR)
|
cropped_frame = cv2.resize(cropped_frame, dsize=(300, 300), interpolation=cv2.INTER_LINEAR)
|
||||||
# Expand dimensions since the model expects images to have shape: [1, 300, 300, 3]
|
# Expand dimensions since the model expects images to have shape: [1, 300, 300, 3]
|
||||||
frame_expanded = np.expand_dims(cropped_frame_rgb, axis=0)
|
frame_expanded = np.expand_dims(cropped_frame, axis=0)
|
||||||
|
|
||||||
# add the frame to the queue
|
# add the frame to the queue
|
||||||
if not self.prepped_frame_queue.full():
|
if not self.prepped_frame_queue.full():
|
||||||
@@ -103,6 +104,7 @@ class FramePrepper(threading.Thread):
|
|||||||
'frame_time': frame_time,
|
'frame_time': frame_time,
|
||||||
'frame': frame_expanded.flatten().copy(),
|
'frame': frame_expanded.flatten().copy(),
|
||||||
'region_size': self.region_size,
|
'region_size': self.region_size,
|
||||||
|
'region_threshold': self.region_threshold,
|
||||||
'region_x_offset': self.region_x_offset,
|
'region_x_offset': self.region_x_offset,
|
||||||
'region_y_offset': self.region_y_offset
|
'region_y_offset': self.region_y_offset
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import time
|
|||||||
import datetime
|
import datetime
|
||||||
import threading
|
import threading
|
||||||
import cv2
|
import cv2
|
||||||
from object_detection.utils import visualization_utils as vis_util
|
from . util import draw_box_with_label
|
||||||
|
|
||||||
class ObjectCleaner(threading.Thread):
|
class ObjectCleaner(threading.Thread):
|
||||||
def __init__(self, objects_parsed, detected_objects):
|
def __init__(self, objects_parsed, detected_objects):
|
||||||
@@ -80,17 +80,13 @@ class BestPersonFrame(threading.Thread):
|
|||||||
|
|
||||||
if not self.best_person is None and self.best_person['frame_time'] in recent_frames:
|
if not self.best_person is None and self.best_person['frame_time'] in recent_frames:
|
||||||
best_frame = recent_frames[self.best_person['frame_time']]
|
best_frame = recent_frames[self.best_person['frame_time']]
|
||||||
best_frame = cv2.cvtColor(best_frame, cv2.COLOR_BGR2RGB)
|
|
||||||
# draw the bounding box on the frame
|
|
||||||
vis_util.draw_bounding_box_on_image_array(best_frame,
|
|
||||||
self.best_person['ymin'],
|
|
||||||
self.best_person['xmin'],
|
|
||||||
self.best_person['ymax'],
|
|
||||||
self.best_person['xmax'],
|
|
||||||
color='red',
|
|
||||||
thickness=2,
|
|
||||||
display_str_list=["{}: {}%".format(self.best_person['name'],int(self.best_person['score']*100))],
|
|
||||||
use_normalized_coordinates=False)
|
|
||||||
|
|
||||||
# convert back to BGR
|
label = "{}: {}% {}".format(self.best_person['name'],int(self.best_person['score']*100),int(self.best_person['area']))
|
||||||
|
draw_box_with_label(best_frame, self.best_person['xmin'], self.best_person['ymin'],
|
||||||
|
self.best_person['xmax'], self.best_person['ymax'], label)
|
||||||
|
|
||||||
|
# print a timestamp
|
||||||
|
time_to_show = datetime.datetime.fromtimestamp(self.best_person['frame_time']).strftime("%m/%d/%Y %H:%M:%S")
|
||||||
|
cv2.putText(best_frame, time_to_show, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, fontScale=.8, color=(255, 255, 255), thickness=2)
|
||||||
|
|
||||||
self.best_frame = cv2.cvtColor(best_frame, cv2.COLOR_RGB2BGR)
|
self.best_frame = cv2.cvtColor(best_frame, cv2.COLOR_RGB2BGR)
|
||||||
|
|||||||
@@ -1,5 +1,26 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
import cv2
|
||||||
|
|
||||||
# convert shared memory array into numpy array
|
# convert shared memory array into numpy array
|
||||||
def tonumpyarray(mp_arr):
|
def tonumpyarray(mp_arr):
|
||||||
return np.frombuffer(mp_arr.get_obj(), dtype=np.uint8)
|
return np.frombuffer(mp_arr.get_obj(), dtype=np.uint8)
|
||||||
|
|
||||||
|
def draw_box_with_label(frame, x_min, y_min, x_max, y_max, label):
|
||||||
|
color = (255,0,0)
|
||||||
|
cv2.rectangle(frame, (x_min, y_min),
|
||||||
|
(x_max, y_max),
|
||||||
|
color, 2)
|
||||||
|
font_scale = 0.5
|
||||||
|
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||||
|
# get the width and height of the text box
|
||||||
|
size = cv2.getTextSize(label, font, fontScale=font_scale, thickness=2)
|
||||||
|
text_width = size[0][0]
|
||||||
|
text_height = size[0][1]
|
||||||
|
line_height = text_height + size[1]
|
||||||
|
# set the text start position
|
||||||
|
text_offset_x = x_min
|
||||||
|
text_offset_y = 0 if y_min < line_height else y_min - (line_height+8)
|
||||||
|
# make the coords of the box with a small padding of two pixels
|
||||||
|
textbox_coords = ((text_offset_x, text_offset_y), (text_offset_x + text_width + 2, text_offset_y + line_height))
|
||||||
|
cv2.rectangle(frame, textbox_coords[0], textbox_coords[1], color, cv2.FILLED)
|
||||||
|
cv2.putText(frame, label, (text_offset_x, text_offset_y + line_height - 3), font, fontScale=font_scale, color=(0, 0, 0), thickness=2)
|
||||||
268
frigate/video.py
268
frigate/video.py
@@ -5,59 +5,13 @@ import cv2
|
|||||||
import threading
|
import threading
|
||||||
import ctypes
|
import ctypes
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
from object_detection.utils import visualization_utils as vis_util
|
import subprocess as sp
|
||||||
from . util import tonumpyarray
|
import numpy as np
|
||||||
|
from . util import tonumpyarray, draw_box_with_label
|
||||||
from . object_detection import FramePrepper
|
from . object_detection import FramePrepper
|
||||||
from . objects import ObjectCleaner, BestPersonFrame
|
from . objects import ObjectCleaner, BestPersonFrame
|
||||||
from . mqtt import MqttObjectPublisher
|
from . mqtt import MqttObjectPublisher
|
||||||
|
|
||||||
# fetch the frames as fast a possible and store current frame in a shared memory array
|
|
||||||
def fetch_frames(shared_arr, shared_frame_time, frame_lock, frame_ready, frame_shape, rtsp_url):
|
|
||||||
# convert shared memory array into numpy and shape into image array
|
|
||||||
arr = tonumpyarray(shared_arr).reshape(frame_shape)
|
|
||||||
|
|
||||||
# start the video capture
|
|
||||||
video = cv2.VideoCapture()
|
|
||||||
video.open(rtsp_url)
|
|
||||||
# keep the buffer small so we minimize old data
|
|
||||||
video.set(cv2.CAP_PROP_BUFFERSIZE,1)
|
|
||||||
|
|
||||||
bad_frame_counter = 0
|
|
||||||
while True:
|
|
||||||
# check if the video stream is still open, and reopen if needed
|
|
||||||
if not video.isOpened():
|
|
||||||
success = video.open(rtsp_url)
|
|
||||||
if not success:
|
|
||||||
time.sleep(1)
|
|
||||||
continue
|
|
||||||
# grab the frame, but dont decode it yet
|
|
||||||
ret = video.grab()
|
|
||||||
# snapshot the time the frame was grabbed
|
|
||||||
frame_time = datetime.datetime.now()
|
|
||||||
if ret:
|
|
||||||
# go ahead and decode the current frame
|
|
||||||
ret, frame = video.retrieve()
|
|
||||||
if ret:
|
|
||||||
# Lock access and update frame
|
|
||||||
with frame_lock:
|
|
||||||
arr[:] = frame
|
|
||||||
shared_frame_time.value = frame_time.timestamp()
|
|
||||||
# Notify with the condition that a new frame is ready
|
|
||||||
with frame_ready:
|
|
||||||
frame_ready.notify_all()
|
|
||||||
bad_frame_counter = 0
|
|
||||||
else:
|
|
||||||
print("Unable to decode frame")
|
|
||||||
bad_frame_counter += 1
|
|
||||||
else:
|
|
||||||
print("Unable to grab a frame")
|
|
||||||
bad_frame_counter += 1
|
|
||||||
|
|
||||||
if bad_frame_counter > 100:
|
|
||||||
video.release()
|
|
||||||
|
|
||||||
video.release()
|
|
||||||
|
|
||||||
# Stores 2 seconds worth of frames when motion is detected so they can be used for other threads
|
# Stores 2 seconds worth of frames when motion is detected so they can be used for other threads
|
||||||
class FrameTracker(threading.Thread):
|
class FrameTracker(threading.Thread):
|
||||||
def __init__(self, shared_frame, frame_time, frame_ready, frame_lock, recent_frames):
|
def __init__(self, shared_frame, frame_time, frame_ready, frame_lock, recent_frames):
|
||||||
@@ -92,40 +46,95 @@ class FrameTracker(threading.Thread):
|
|||||||
if (now - k) > 2:
|
if (now - k) > 2:
|
||||||
del self.recent_frames[k]
|
del self.recent_frames[k]
|
||||||
|
|
||||||
def get_frame_shape(rtsp_url):
|
def get_frame_shape(source):
|
||||||
# capture a single frame and check the frame shape so the correct array
|
# capture a single frame and check the frame shape so the correct array
|
||||||
# size can be allocated in memory
|
# size can be allocated in memory
|
||||||
video = cv2.VideoCapture(rtsp_url)
|
video = cv2.VideoCapture(source)
|
||||||
ret, frame = video.read()
|
ret, frame = video.read()
|
||||||
frame_shape = frame.shape
|
frame_shape = frame.shape
|
||||||
video.release()
|
video.release()
|
||||||
return frame_shape
|
return frame_shape
|
||||||
|
|
||||||
def get_rtsp_url(rtsp_config):
|
def get_ffmpeg_input(ffmpeg_input):
|
||||||
if (rtsp_config['password'].startswith('$')):
|
frigate_vars = {k: v for k, v in os.environ.items() if k.startswith('FRIGATE_')}
|
||||||
rtsp_config['password'] = os.getenv(rtsp_config['password'][1:])
|
return ffmpeg_input.format(**frigate_vars)
|
||||||
return 'rtsp://{}:{}@{}:{}{}'.format(rtsp_config['user'],
|
|
||||||
rtsp_config['password'], rtsp_config['host'], rtsp_config['port'],
|
class CameraWatchdog(threading.Thread):
|
||||||
rtsp_config['path'])
|
def __init__(self, camera):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.camera = camera
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# wait a bit before checking
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
if (datetime.datetime.now().timestamp() - self.camera.frame_time.value) > 10:
|
||||||
|
print("last frame is more than 10 seconds old, restarting camera capture...")
|
||||||
|
self.camera.start_or_restart_capture()
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
# Thread to read the stdout of the ffmpeg process and update the current frame
|
||||||
|
class CameraCapture(threading.Thread):
|
||||||
|
def __init__(self, camera):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.camera = camera
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
frame_num = 0
|
||||||
|
while True:
|
||||||
|
if self.camera.ffmpeg_process.poll() != None:
|
||||||
|
print("ffmpeg process is not running. exiting capture thread...")
|
||||||
|
break
|
||||||
|
|
||||||
|
raw_image = self.camera.ffmpeg_process.stdout.read(self.camera.frame_size)
|
||||||
|
|
||||||
|
if len(raw_image) == 0:
|
||||||
|
print("ffmpeg didnt return a frame. something is wrong. exiting capture thread...")
|
||||||
|
break
|
||||||
|
|
||||||
|
frame_num += 1
|
||||||
|
if (frame_num % self.camera.take_frame) != 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
with self.camera.frame_lock:
|
||||||
|
self.camera.frame_time.value = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
|
self.camera.current_frame[:] = (
|
||||||
|
np
|
||||||
|
.frombuffer(raw_image, np.uint8)
|
||||||
|
.reshape(self.camera.frame_shape)
|
||||||
|
)
|
||||||
|
# Notify with the condition that a new frame is ready
|
||||||
|
with self.camera.frame_ready:
|
||||||
|
self.camera.frame_ready.notify_all()
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
def __init__(self, name, config, prepped_frame_queue, mqtt_client, mqtt_prefix):
|
def __init__(self, name, ffmpeg_config, config, prepped_frame_queue, mqtt_client, mqtt_prefix):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.config = config
|
self.config = config
|
||||||
self.detected_objects = []
|
self.detected_objects = []
|
||||||
self.recent_frames = {}
|
self.recent_frames = {}
|
||||||
self.rtsp_url = get_rtsp_url(self.config['rtsp'])
|
|
||||||
|
self.ffmpeg = config.get('ffmpeg', {})
|
||||||
|
self.ffmpeg_input = get_ffmpeg_input(self.ffmpeg['input'])
|
||||||
|
self.ffmpeg_global_args = self.ffmpeg.get('global_args', ffmpeg_config['global_args'])
|
||||||
|
self.ffmpeg_hwaccel_args = self.ffmpeg.get('hwaccel_args', ffmpeg_config['hwaccel_args'])
|
||||||
|
self.ffmpeg_input_args = self.ffmpeg.get('input_args', ffmpeg_config['input_args'])
|
||||||
|
self.ffmpeg_output_args = self.ffmpeg.get('output_args', ffmpeg_config['output_args'])
|
||||||
|
|
||||||
|
self.take_frame = self.config.get('take_frame', 1)
|
||||||
self.regions = self.config['regions']
|
self.regions = self.config['regions']
|
||||||
self.frame_shape = get_frame_shape(self.rtsp_url)
|
self.frame_shape = get_frame_shape(self.ffmpeg_input)
|
||||||
|
self.frame_size = self.frame_shape[0] * self.frame_shape[1] * self.frame_shape[2]
|
||||||
self.mqtt_client = mqtt_client
|
self.mqtt_client = mqtt_client
|
||||||
self.mqtt_topic_prefix = '{}/{}'.format(mqtt_prefix, self.name)
|
self.mqtt_topic_prefix = '{}/{}'.format(mqtt_prefix, self.name)
|
||||||
|
|
||||||
# compute the flattened array length from the shape of the frame
|
# create a numpy array for the current frame in initialize to zeros
|
||||||
flat_array_length = self.frame_shape[0] * self.frame_shape[1] * self.frame_shape[2]
|
self.current_frame = np.zeros(self.frame_shape, np.uint8)
|
||||||
# create shared array for storing the full frame image data
|
|
||||||
self.shared_frame_array = mp.Array(ctypes.c_uint8, flat_array_length)
|
|
||||||
# create shared value for storing the frame_time
|
# create shared value for storing the frame_time
|
||||||
self.shared_frame_time = mp.Value('d', 0.0)
|
self.frame_time = mp.Value('d', 0.0)
|
||||||
# Lock to control access to the frame
|
# Lock to control access to the frame
|
||||||
self.frame_lock = mp.Lock()
|
self.frame_lock = mp.Lock()
|
||||||
# Condition for notifying that a new frame is ready
|
# Condition for notifying that a new frame is ready
|
||||||
@@ -133,29 +142,30 @@ class Camera:
|
|||||||
# Condition for notifying that objects were parsed
|
# Condition for notifying that objects were parsed
|
||||||
self.objects_parsed = mp.Condition()
|
self.objects_parsed = mp.Condition()
|
||||||
|
|
||||||
# shape current frame so it can be treated as a numpy image
|
self.ffmpeg_process = None
|
||||||
self.shared_frame_np = tonumpyarray(self.shared_frame_array).reshape(self.frame_shape)
|
self.capture_thread = None
|
||||||
|
|
||||||
# create the process to capture frames from the RTSP stream and store in a shared array
|
|
||||||
self.capture_process = mp.Process(target=fetch_frames, args=(self.shared_frame_array,
|
|
||||||
self.shared_frame_time, self.frame_lock, self.frame_ready, self.frame_shape, self.rtsp_url))
|
|
||||||
self.capture_process.daemon = True
|
|
||||||
|
|
||||||
# for each region, create a separate thread to resize the region and prep for detection
|
# for each region, create a separate thread to resize the region and prep for detection
|
||||||
self.detection_prep_threads = []
|
self.detection_prep_threads = []
|
||||||
for region in self.config['regions']:
|
for region in self.config['regions']:
|
||||||
|
# set a default threshold of 0.5 if not defined
|
||||||
|
if not 'threshold' in region:
|
||||||
|
region['threshold'] = 0.5
|
||||||
|
if not isinstance(region['threshold'], float):
|
||||||
|
print('Threshold is not a float. Setting to 0.5 default.')
|
||||||
|
region['threshold'] = 0.5
|
||||||
self.detection_prep_threads.append(FramePrepper(
|
self.detection_prep_threads.append(FramePrepper(
|
||||||
self.name,
|
self.name,
|
||||||
self.shared_frame_np,
|
self.current_frame,
|
||||||
self.shared_frame_time,
|
self.frame_time,
|
||||||
self.frame_ready,
|
self.frame_ready,
|
||||||
self.frame_lock,
|
self.frame_lock,
|
||||||
region['size'], region['x_offset'], region['y_offset'],
|
region['size'], region['x_offset'], region['y_offset'], region['threshold'],
|
||||||
prepped_frame_queue
|
prepped_frame_queue
|
||||||
))
|
))
|
||||||
|
|
||||||
# start a thread to store recent motion frames for processing
|
# start a thread to store recent motion frames for processing
|
||||||
self.frame_tracker = FrameTracker(self.shared_frame_np, self.shared_frame_time,
|
self.frame_tracker = FrameTracker(self.current_frame, self.frame_time,
|
||||||
self.frame_ready, self.frame_lock, self.recent_frames)
|
self.frame_ready, self.frame_lock, self.recent_frames)
|
||||||
self.frame_tracker.start()
|
self.frame_tracker.start()
|
||||||
|
|
||||||
@@ -168,28 +178,84 @@ class Camera:
|
|||||||
self.object_cleaner.start()
|
self.object_cleaner.start()
|
||||||
|
|
||||||
# start a thread to publish object scores (currently only person)
|
# start a thread to publish object scores (currently only person)
|
||||||
mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects)
|
mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects, self.best_person_frame)
|
||||||
mqtt_publisher.start()
|
mqtt_publisher.start()
|
||||||
|
|
||||||
|
# create a watchdog thread for capture process
|
||||||
|
self.watchdog = CameraWatchdog(self)
|
||||||
|
|
||||||
|
# load in the mask for person detection
|
||||||
|
if 'mask' in self.config:
|
||||||
|
self.mask = cv2.imread("/config/{}".format(self.config['mask']), cv2.IMREAD_GRAYSCALE)
|
||||||
|
else:
|
||||||
|
self.mask = None
|
||||||
|
|
||||||
|
if self.mask is None:
|
||||||
|
self.mask = np.zeros((self.frame_shape[0], self.frame_shape[1], 1), np.uint8)
|
||||||
|
self.mask[:] = 255
|
||||||
|
|
||||||
|
|
||||||
|
def start_or_restart_capture(self):
|
||||||
|
if not self.ffmpeg_process is None:
|
||||||
|
print("Terminating the existing ffmpeg process...")
|
||||||
|
self.ffmpeg_process.terminate()
|
||||||
|
try:
|
||||||
|
print("Waiting for ffmpeg to exit gracefully...")
|
||||||
|
self.ffmpeg_process.wait(timeout=30)
|
||||||
|
except sp.TimeoutExpired:
|
||||||
|
print("FFmpeg didnt exit. Force killing...")
|
||||||
|
self.ffmpeg_process.kill()
|
||||||
|
self.ffmpeg_process.wait()
|
||||||
|
|
||||||
|
print("Waiting for the capture thread to exit...")
|
||||||
|
self.capture_thread.join()
|
||||||
|
self.ffmpeg_process = None
|
||||||
|
self.capture_thread = None
|
||||||
|
|
||||||
|
# create the process to capture frames from the input stream and store in a shared array
|
||||||
|
print("Creating a new ffmpeg process...")
|
||||||
|
self.start_ffmpeg()
|
||||||
|
|
||||||
|
print("Creating a new capture thread...")
|
||||||
|
self.capture_thread = CameraCapture(self)
|
||||||
|
print("Starting a new capture thread...")
|
||||||
|
self.capture_thread.start()
|
||||||
|
|
||||||
|
def start_ffmpeg(self):
|
||||||
|
ffmpeg_cmd = (['ffmpeg'] +
|
||||||
|
self.ffmpeg_global_args +
|
||||||
|
self.ffmpeg_hwaccel_args +
|
||||||
|
self.ffmpeg_input_args +
|
||||||
|
['-i', self.ffmpeg_input] +
|
||||||
|
self.ffmpeg_output_args +
|
||||||
|
['pipe:'])
|
||||||
|
|
||||||
|
print(" ".join(ffmpeg_cmd))
|
||||||
|
|
||||||
|
self.ffmpeg_process = sp.Popen(ffmpeg_cmd, stdout = sp.PIPE, bufsize=self.frame_size)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.capture_process.start()
|
self.start_or_restart_capture()
|
||||||
# start the object detection prep threads
|
# start the object detection prep threads
|
||||||
for detection_prep_thread in self.detection_prep_threads:
|
for detection_prep_thread in self.detection_prep_threads:
|
||||||
detection_prep_thread.start()
|
detection_prep_thread.start()
|
||||||
|
self.watchdog.start()
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
self.capture_process.join()
|
self.capture_thread.join()
|
||||||
|
|
||||||
def get_capture_pid(self):
|
def get_capture_pid(self):
|
||||||
return self.capture_process.pid
|
return self.ffmpeg_process.pid
|
||||||
|
|
||||||
def add_objects(self, objects):
|
def add_objects(self, objects):
|
||||||
if len(objects) == 0:
|
if len(objects) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
|
# Store object area to use in bounding box labels
|
||||||
|
obj['area'] = (obj['xmax']-obj['xmin'])*(obj['ymax']-obj['ymin'])
|
||||||
|
|
||||||
if obj['name'] == 'person':
|
if obj['name'] == 'person':
|
||||||
person_area = (obj['xmax']-obj['xmin'])*(obj['ymax']-obj['ymin'])
|
|
||||||
# find the matching region
|
# find the matching region
|
||||||
region = None
|
region = None
|
||||||
for r in self.regions:
|
for r in self.regions:
|
||||||
@@ -204,7 +270,21 @@ class Camera:
|
|||||||
|
|
||||||
# if the min person area is larger than the
|
# if the min person area is larger than the
|
||||||
# detected person, don't add it to detected objects
|
# detected person, don't add it to detected objects
|
||||||
if region and region['min_person_area'] > person_area:
|
if region and 'min_person_area' in region and region['min_person_area'] > obj['area']:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# if the detected person is larger than the
|
||||||
|
# max person area, don't add it to detected objects
|
||||||
|
if region and 'max_person_area' in region and region['max_person_area'] < obj['area']:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# compute the coordinates of the person and make sure
|
||||||
|
# the location isnt outside the bounds of the image (can happen from rounding)
|
||||||
|
y_location = min(int(obj['ymax']), len(self.mask)-1)
|
||||||
|
x_location = min(int((obj['xmax']-obj['xmin'])/2.0)+obj['xmin'], len(self.mask[0])-1)
|
||||||
|
|
||||||
|
# if the person is in a masked location, continue
|
||||||
|
if self.mask[y_location][x_location] == [0]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.detected_objects.append(obj)
|
self.detected_objects.append(obj)
|
||||||
@@ -220,33 +300,29 @@ class Camera:
|
|||||||
detected_objects = self.detected_objects.copy()
|
detected_objects = self.detected_objects.copy()
|
||||||
# lock and make a copy of the current frame
|
# lock and make a copy of the current frame
|
||||||
with self.frame_lock:
|
with self.frame_lock:
|
||||||
frame = self.shared_frame_np.copy()
|
frame = self.current_frame.copy()
|
||||||
|
frame_time = self.frame_time.value
|
||||||
|
|
||||||
# convert to RGB for drawing
|
|
||||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
||||||
# draw the bounding boxes on the screen
|
# draw the bounding boxes on the screen
|
||||||
for obj in detected_objects:
|
for obj in detected_objects:
|
||||||
vis_util.draw_bounding_box_on_image_array(frame,
|
label = "{}: {}% {}".format(obj['name'],int(obj['score']*100),int(obj['area']))
|
||||||
obj['ymin'],
|
draw_box_with_label(frame, obj['xmin'], obj['ymin'], obj['xmax'], obj['ymax'], label)
|
||||||
obj['xmin'],
|
|
||||||
obj['ymax'],
|
|
||||||
obj['xmax'],
|
|
||||||
color='red',
|
|
||||||
thickness=2,
|
|
||||||
display_str_list=["{}: {}%".format(obj['name'],int(obj['score']*100))],
|
|
||||||
use_normalized_coordinates=False)
|
|
||||||
|
|
||||||
for region in self.regions:
|
for region in self.regions:
|
||||||
color = (255,255,255)
|
color = (255,255,255)
|
||||||
cv2.rectangle(frame, (region['x_offset'], region['y_offset']),
|
cv2.rectangle(frame, (region['x_offset'], region['y_offset']),
|
||||||
(region['x_offset']+region['size'], region['y_offset']+region['size']),
|
(region['x_offset']+region['size'], region['y_offset']+region['size']),
|
||||||
color, 2)
|
color, 2)
|
||||||
|
|
||||||
|
# print a timestamp
|
||||||
|
time_to_show = datetime.datetime.fromtimestamp(frame_time).strftime("%m/%d/%Y %H:%M:%S")
|
||||||
|
cv2.putText(frame, time_to_show, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, fontScale=.8, color=(255, 255, 255), thickness=2)
|
||||||
|
|
||||||
# convert back to BGR
|
# convert to BGR
|
||||||
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
50
scripts/install_edgetpu_api.sh
Normal file
50
scripts/install_edgetpu_api.sh
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CPU_ARCH=$(uname -m)
|
||||||
|
OS_VERSION=$(uname -v)
|
||||||
|
|
||||||
|
echo "CPU_ARCH ${CPU_ARCH}"
|
||||||
|
echo "OS_VERSION ${OS_VERSION}"
|
||||||
|
|
||||||
|
if [[ "${CPU_ARCH}" == "x86_64" ]]; then
|
||||||
|
echo "Recognized as Linux on x86_64."
|
||||||
|
LIBEDGETPU_SUFFIX=x86_64
|
||||||
|
HOST_GNU_TYPE=x86_64-linux-gnu
|
||||||
|
elif [[ "${CPU_ARCH}" == "armv7l" ]]; then
|
||||||
|
echo "Recognized as Linux on ARM32 platform."
|
||||||
|
LIBEDGETPU_SUFFIX=arm32
|
||||||
|
HOST_GNU_TYPE=arm-linux-gnueabihf
|
||||||
|
elif [[ "${CPU_ARCH}" == "aarch64" ]]; then
|
||||||
|
echo "Recognized as generic ARM64 platform."
|
||||||
|
LIBEDGETPU_SUFFIX=arm64
|
||||||
|
HOST_GNU_TYPE=aarch64-linux-gnu
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${HOST_GNU_TYPE}" ]]; then
|
||||||
|
echo "Your platform is not supported."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Using maximum operating frequency."
|
||||||
|
LIBEDGETPU_SRC="libedgetpu/libedgetpu_${LIBEDGETPU_SUFFIX}.so"
|
||||||
|
LIBEDGETPU_DST="/usr/lib/${HOST_GNU_TYPE}/libedgetpu.so.1.0"
|
||||||
|
|
||||||
|
# Runtime library.
|
||||||
|
echo "Installing Edge TPU runtime library [${LIBEDGETPU_DST}]..."
|
||||||
|
if [[ -f "${LIBEDGETPU_DST}" ]]; then
|
||||||
|
echo "File already exists. Replacing it..."
|
||||||
|
rm -f "${LIBEDGETPU_DST}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp -p "${LIBEDGETPU_SRC}" "${LIBEDGETPU_DST}"
|
||||||
|
ldconfig
|
||||||
|
echo "Done."
|
||||||
|
|
||||||
|
# Python API.
|
||||||
|
WHEEL=$(ls edgetpu-*-py3-none-any.whl 2>/dev/null)
|
||||||
|
if [[ $? == 0 ]]; then
|
||||||
|
echo "Installing Edge TPU Python API..."
|
||||||
|
python3 -m pip install --no-deps "${WHEEL}"
|
||||||
|
echo "Done."
|
||||||
|
fi
|
||||||
5
scripts/install_odroid_repo.sh
Normal file
5
scripts/install_odroid_repo.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D986B59D
|
||||||
|
|
||||||
|
echo "deb http://deb.odroid.in/5422-s bionic main" > /etc/apt/sources.list.d/odroid.list
|
||||||
Reference in New Issue
Block a user