diff --git a/Dockerfile b/Dockerfile index b2f7703..3b9be17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM python:3.9-slim COPY . /app # Install any needed dependencies specified in requirements.txt -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir -r /app/requirements.txt # Start Anonimization CMD ["python", "app.py"] diff --git a/README.md b/README.md index e69de29..3a09575 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,25 @@ +# VMS - Český Krumlov - Anonymizer + +#### Docker Build - Powershell (One Line) +```powershell +$tag = ("0.0.1").Trim(); git reset --hard; git pull origin master; git tag $tag; git push --tags; docker build -t git.steelants.cz/steelants/py_ck:$tag .; docker push git.steelants.cz/steelants/py_ck:$tag; docker build -t git.steelants.cz/steelants/py_ck:latest .; docker push git.steelants.cz/steelants/py_ck:latest +``` + +#### Docker Build - Bash (One Line) +```bash +export TAG="0.0.1" && sudo docker build -t git.steelants.cz/steelants/py_ck:"$TAG" . && sudo docker push git.steelants.cz/steelants/py_ck:"$TAG" && sudo docker build -t git.steelants.cz/steelants/py_ck:latest . && sudo docker push git.steelants.cz/steelants/py_ck:latest +``` + +#### Docker Stack Setup +```yaml +services: + ck-anonym: + image: git.steelants.cz/steelants/lar_py:latest + restart: unless-stopped + environment: + API_ROOT: http://ck:8080 + FACE_TRASHOLD: 0.5 + volumes: + - ${PWD}/app_data/:/app/data/ +networks: {} +``` \ No newline at end of file diff --git a/app.py b/app.py index e3523da..8e4d8c0 100644 --- a/app.py +++ b/app.py @@ -2,18 +2,25 @@ import cv2 import time import os import requests +import json -treashold = float(os.getenv('FACE_TRASHOLD', '0,5')) -sever = os.getenv('API_ROOT', 'localhost') +treashold = float(os.getenv('FACE_TRASHOLD', '0.5')) +sever = os.getenv('API_ROOT', 'localhost:8000') root_api_url = 'http://{}/local'.format(sever) try: while True: r = requests.get('{}/anonymize'.format(root_api_url)) face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') + response = r.json() + + for detection in response: + img_path = "/data/{}".format(detection['source_image_path']) + + #Skip Non existing files + if (not os.path.exists(img_path)): + continue - for detection in r.json(): - img_path = "/data/{}".format(detection.source_image_path) img = cv2.imread(img_path) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces, rejects, weights = face_cascade.detectMultiScale3(gray, 1.1, 4, outputRejectLevels = 1) @@ -38,14 +45,14 @@ try: cv2.imwrite(new_img_path, img) data = { - "id": detection.id, + "id": detection['id'], "source_image_path": new_img_path } response = requests.post('{}/anonymize'.format(root_api_url), json=data) - time.sleep(3) + time.sleep(900) except Exception as e: print("An exception occurred") - data = {"trace": e.__traceback__,} + data = {"trace": str(e)} response = requests.post('{}/log'.format(root_api_url), json=data) \ No newline at end of file diff --git a/start.sh b/start.sh deleted file mode 100644 index e69de29..0000000