Compare commits

..

5 Commits

Author SHA1 Message Date
Blake Blackshear
56b9c754f5 Update README.md 2019-06-18 06:19:13 -07:00
Blake Blackshear
5c4f5ef3f0 Create FUNDING.yml 2019-06-18 06:15:05 -07:00
Blake Blackshear
8c924896c5 Merge pull request #36 from drcrimzon/patch-1
Add MQTT connection error handling
2019-05-15 07:10:53 -05:00
Mike Wilkinson
2c2f0044b9 Remove error redundant check 2019-05-14 11:09:57 -04:00
Mike Wilkinson
874e9085a7 Add MQTT connection error handling 2019-05-14 08:34:14 -04:00
6 changed files with 99 additions and 65 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
ko_fi: blakeblackshear

View File

@@ -1,59 +1,70 @@
FROM ubuntu:18.04 FROM ubuntu:16.04
# Install packages for apt repo # Install system packages
RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y \ RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y python3 \
apt-transport-https \ python3-dev \
ca-certificates \ python-pil \
curl \ python-lxml \
wget \ python-tk \
gnupg-agent \
dirmngr \
software-properties-common
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D986B59D
RUN echo "deb http://deb.odroid.in/5422-s bionic main" > /etc/apt/sources.list.d/odroid.list
RUN apt-get -qq update && apt-get -qq install --no-install-recommends -y \
python3 \
# OpenCV dependencies
ffmpeg \
build-essential \ build-essential \
cmake \ cmake \
unzip \ git \
pkg-config \ libgtk2.0-dev \
pkg-config \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libtbb2 \
libtbb-dev \
libjpeg-dev \ libjpeg-dev \
libpng-dev \ libpng-dev \
libtiff-dev \ libtiff-dev \
libavcodec-dev \ libjasper-dev \
libavformat-dev \ libdc1394-22-dev \
libswscale-dev \ x11-apps \
libv4l-dev \ wget \
libxvidcore-dev \ vim \
libx264-dev \ ffmpeg \
libgtk-3-dev \ unzip \
libatlas-base-dev \ libusb-1.0-0-dev \
gfortran \ python3-setuptools \
python3-dev \
# Coral USB Python API Dependencies
libusb-1.0-0 \
python3-pip \
python3-pil \
python3-numpy \ python3-numpy \
libc++1 \ zlib1g-dev \
libc++abi1 \ libgoogle-glog-dev \
libunwind8 \ swig \
libgcc1 \ libunwind-dev \
libc++-dev \
libc++abi-dev \
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
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/ \
@@ -65,31 +76,30 @@ 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 for Coral # Download and install EdgeTPU libraries
RUN wget https://dl.google.com/coral/edgetpu_api/edgetpu_api_latest.tar.gz -O edgetpu_api.tar.gz --trust-server-names 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 tar xzf edgetpu_api.tar.gz \ RUN tar xzf edgetpu_api.tar.gz \
&& cd edgetpu_api \ && cd python-tflite-source \
&& cp -p libedgetpu/libedgetpu_arm32.so /usr/lib/arm-linux-gnueabihf/libedgetpu.so.1.0 \ && cp -p libedgetpu/libedgetpu_x86_64.so /lib/x86_64-linux-gnu/libedgetpu.so \
&& ldconfig \ && cp edgetpu/swig/compiled_so/_edgetpu_cpp_wrapper_x86_64.so edgetpu/swig/_edgetpu_cpp_wrapper.so \
&& python3 -m pip install --no-deps "$(ls edgetpu-*-py3-none-any.whl 2>/dev/null)" && cp edgetpu/swig/compiled_so/edgetpu_cpp_wrapper.py edgetpu/swig/ \
&& python3 setup.py develop --user
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 .

View File

@@ -1,3 +1,5 @@
<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 RTSP Cameras # Frigate - Realtime Object Detection for RTSP 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/)

View File

@@ -25,6 +25,15 @@ 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()
@@ -87,4 +96,4 @@ def main():
camera.join() camera.join()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -2,6 +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
class ObjectCleaner(threading.Thread): class ObjectCleaner(threading.Thread):
def __init__(self, objects_parsed, detected_objects): def __init__(self, objects_parsed, detected_objects):
@@ -81,10 +82,15 @@ class BestPersonFrame(threading.Thread):
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) best_frame = cv2.cvtColor(best_frame, cv2.COLOR_BGR2RGB)
# draw the bounding box on the frame # draw the bounding box on the frame
color = (255,0,0) vis_util.draw_bounding_box_on_image_array(best_frame,
cv2.rectangle(best_frame, (self.best_person['xmin'], self.best_person['ymin']), self.best_person['ymin'],
(self.best_person['xmax'], self.best_person['ymax']), self.best_person['xmin'],
color, 2) 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 # convert back to BGR
self.best_frame = cv2.cvtColor(best_frame, cv2.COLOR_RGB2BGR) self.best_frame = cv2.cvtColor(best_frame, cv2.COLOR_RGB2BGR)

View File

@@ -6,6 +6,7 @@ import threading
import ctypes import ctypes
import multiprocessing as mp import multiprocessing as mp
import numpy as np import numpy as np
from object_detection.utils import visualization_utils as vis_util
from . util import tonumpyarray from . util import tonumpyarray
from . object_detection import FramePrepper from . object_detection import FramePrepper
from . objects import ObjectCleaner, BestPersonFrame from . objects import ObjectCleaner, BestPersonFrame
@@ -282,10 +283,15 @@ class Camera:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 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:
color = (255,0,0) vis_util.draw_bounding_box_on_image_array(frame,
cv2.rectangle(frame, (obj['xmin'], obj['ymin']), obj['ymin'],
(obj['xmax'], obj['ymax']), obj['xmin'],
color, 2) 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)