This commit is contained in:
Jonatan Rek
2024-10-01 16:54:00 +02:00
parent 2cfa1cc9b7
commit 9a2afed1f1
4 changed files with 40 additions and 8 deletions
+1 -1
View File
@@ -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"]
+25
View File
@@ -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: {}
```
+14 -7
View File
@@ -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)
View File