Add dockerfile

This commit is contained in:
se1exin 2022-05-13 20:57:22 +10:00
parent 99cf61f0cf
commit 3d1208897b
No known key found for this signature in database
GPG Key ID: 8C5633201B25C57D
7 changed files with 45 additions and 13 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
venv
docker/
.idea

View File

@ -1,5 +1,15 @@
# CVZone MQTT Tracker # CVZone MQTT Tracker
## Run with docker
```
docker run \
--device /dev/video0 \
-e MQTT_ADDRESS="10.1.1.100" \
-e MQTT_PORT="1883" \
-e MQTT_CLIENT_ID="cvzone_tracker_01" \
-e MIN_FACE_SCORE="0.5" \
cvzone-mqtt-tracker:latest
```
## Install on Raspberry Pi ## Install on Raspberry Pi
*Required*: Raspberry Pi OS 64-bit *Required*: Raspberry Pi OS 64-bit

10
docker/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:3.7
RUN apt-get update \
&& apt-get install -y python3-opencv
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD python main.py

12
main.py
View File

@ -1,8 +1,16 @@
import os
from tracker import Tracker from tracker import Tracker
mqtt_address = os.environ.get("MQTT_ADDRESS", "10.1.1.100")
mqtt_port = int(os.environ.get("MQTT_PORT", 1883))
mqtt_client_id = os.environ.get("MQTT_CLIENT_ID", "cvzone_tracker_01")
min_face_score = float(os.environ.get("MIN_FACE_SCORE", 0.5))
tracker = Tracker( tracker = Tracker(
mqtt_address="10.1.1.100", mqtt_address=mqtt_address,
mqtt_client_id="cvzone_tracker_01", mqtt_port=mqtt_port,
mqtt_client_id=mqtt_client_id,
min_face_score=min_face_score,
show_img=False) show_img=False)
while True: while True:

View File

@ -1,3 +1,5 @@
cvzone==1.5.6 cvzone==1.5.6
mediapipe==0.8.10 mediapipe==0.8.9.1
opencv-contrib-python==4.5.5.64
opencv-python==4.5.5.64
paho-mqtt==1.6.1 paho-mqtt==1.6.1

View File

@ -1,6 +0,0 @@
cvzone==1.5.6
mediapipe==0.8.9.1
numpy==1.22.3
opencv-contrib-python==4.5.5.64
opencv-python==4.5.5.64
paho-mqtt==1.6.1

View File

@ -7,9 +7,16 @@ from debounce import debounce
class Tracker(object): class Tracker(object):
def __init__(self, mqtt_address="", mqtt_port=1883, mqtt_client_id="", show_img=False): def __init__(
self,
mqtt_address="",
mqtt_port=1883,
mqtt_client_id="",
min_face_score=0.5,
show_img=False):
self.show_img = show_img self.show_img = show_img
self.min_face_score = 0.5 self.min_face_score = min_face_score
self.cap = cv2.VideoCapture(0) self.cap = cv2.VideoCapture(0)
self.face_detector = FaceDetector() self.face_detector = FaceDetector()
self.img = None self.img = None
@ -56,8 +63,6 @@ class Tracker(object):
score = face_bboxs[0]["score"][0] score = face_bboxs[0]["score"][0]
return score >= self.min_face_score return score >= self.min_face_score
else:
print('Image not usable')
return False return False
def loop(self): def loop(self):