diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1790b20 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +venv +docker/ +.idea diff --git a/README.md b/README.md index 6cb9a50..09e6c67 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,15 @@ # 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 *Required*: Raspberry Pi OS 64-bit diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..6343102 --- /dev/null +++ b/docker/Dockerfile @@ -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 diff --git a/main.py b/main.py index 35e0440..7a2358a 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,16 @@ +import os 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( - mqtt_address="10.1.1.100", - mqtt_client_id="cvzone_tracker_01", + mqtt_address=mqtt_address, + mqtt_port=mqtt_port, + mqtt_client_id=mqtt_client_id, + min_face_score=min_face_score, show_img=False) while True: diff --git a/requirements.txt b/requirements.txt index b8cb76d..23627cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ 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 diff --git a/requirements_rpi.txt b/requirements_rpi.txt deleted file mode 100644 index fb6f762..0000000 --- a/requirements_rpi.txt +++ /dev/null @@ -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 diff --git a/tracker.py b/tracker.py index 645e5a9..fc46efd 100644 --- a/tracker.py +++ b/tracker.py @@ -7,9 +7,16 @@ from debounce import debounce 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.min_face_score = 0.5 + self.min_face_score = min_face_score self.cap = cv2.VideoCapture(0) self.face_detector = FaceDetector() self.img = None @@ -56,8 +63,6 @@ class Tracker(object): score = face_bboxs[0]["score"][0] return score >= self.min_face_score - else: - print('Image not usable') return False def loop(self):