33 Commits
Author SHA1 Message Date
JonatanRek e4c46f8b8c v 2024-12-24 00:43:44 +01:00
JonatanRek 9f5c64e25e version 2024-12-23 14:04:29 +01:00
JonatanRek ace946f0c8 Merge pull request 'Used retina' (#1) from Retina into main
Reviewed-on: #1
2024-12-23 13:03:38 +00:00
Imendin 89915f8aae Used retina 2024-12-15 12:07:05 +01:00
JonatanRek 1bad92e40d Fixes 2024-10-05 23:22:40 +02:00
JonatanRek 74dbc8163a Fix 2024-10-05 23:16:33 +02:00
JonatanRek c5bce29178 Fix 2024-10-05 22:42:39 +02:00
JonatanRek f87f5d0a77 Fix 2024-10-05 22:38:58 +02:00
JonatanRek 474a30752f Fix 2024-10-05 22:35:16 +02:00
JonatanRek 86ec596902 Final FIx 2024-10-05 22:29:35 +02:00
JonatanRek 45292746da Fixes 2024-10-05 22:28:19 +02:00
JonatanRek 75ad53082a Fixes 2024-10-05 22:21:48 +02:00
JonatanRek 5a5fc5e840 Fix 2024-10-05 22:17:23 +02:00
JonatanRek 74f0c2904d Fix 2024-10-05 22:14:40 +02:00
JonatanRek cfe5454c76 Add Debug Messages 2024-10-05 22:14:32 +02:00
JonatanRek 410c485541 Fix 2024-10-05 22:10:38 +02:00
JonatanRek 87e5768da4 Fix 2024-10-05 22:09:49 +02:00
JonatanRek 3ffdef8ced Fix 2024-10-05 22:06:05 +02:00
JonatanRek 6512c00800 Fix 2024-10-05 22:04:39 +02:00
JonatanRek 346ec95a3a Fix 2024-10-05 22:02:26 +02:00
JonatanRek bb9cefbbe4 xFic 2024-10-05 21:59:53 +02:00
JonatanRek 2b1d8fe587 Fix 2024-10-05 21:59:16 +02:00
JonatanRek e3b32d8e2a Fix 2024-10-05 21:54:33 +02:00
JonatanRek 588581f8b7 Test 2024-10-05 21:42:00 +02:00
JonatanRek 6d27f51c7c Test 2024-10-05 21:40:15 +02:00
JonatanRek bd6cb64117 Test 2024-10-05 21:37:46 +02:00
JonatanRek a2da806d65 Test 2024-10-05 21:36:00 +02:00
JonatanRek b01768d2bb Fix 2024-10-05 21:34:41 +02:00
JonatanRek 1105875803 Fix 2024-10-05 21:32:40 +02:00
JonatanRek ca0af74495 Fix Docker 2024-10-05 21:25:45 +02:00
JonatanRek fe091bd8ec Fix Docker 2024-10-05 21:24:26 +02:00
JonatanRek 4e2efc2b08 Fix 2024-10-05 21:22:48 +02:00
JonatanRek fbcdb9b6fa Absolut Path 2024-10-05 21:20:57 +02:00
6 changed files with 81 additions and 28 deletions
+2 -1
View File
@@ -1 +1,2 @@
.venv
.venv
.conda
+15 -2
View File
@@ -1,5 +1,16 @@
# Use PHP with Apache as the base image
FROM python:3.9-slim
FROM python:latest
ENV PYTHONUNBUFFERED=1
# Install Additional System Dependencies
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y \
libgl1
# Clear cache
RUN apt-get autoremove
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
#Copy Project
COPY . /app
@@ -8,4 +19,6 @@ COPY . /app
RUN pip install --no-cache-dir -r /app/requirements.txt
# Start Anonimization
CMD ["python", "/app/app.py"]
CMD ["python", "-u", "/app/app.py"]
WORKDIR /app
+6 -2
View File
@@ -2,12 +2,12 @@
#### Docker Build - Powershell (One Line)
```powershell
$tag = ("0.0.2").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
$tag = ("0.0.4").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
export TAG="0.0.4" && 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
@@ -22,4 +22,8 @@ services:
volumes:
- ${PWD}/app_data/:/app/data/
networks: {}
```
```python
pip3 install -r requirements.txt
```
+52 -22
View File
@@ -3,61 +3,91 @@ import time
import os
import requests
import json
from retinaface import RetinaFace
treashold = float(os.getenv('FACE_TRASHOLD', '0.5'))
treashold = float(os.getenv('FACE_TRASHOLD', '0.9'))
sever = os.getenv('API_ROOT', 'localhost:8000')
root_api_url = 'http://{}/local'.format(sever)
base_path = '/data/'
base_path = '/app/data/'
print("API_ROOT: " + str(root_api_url), flush=True)
print("FACE_TRASHOLD: " + str(treashold), flush=True)
try:
while True:
print("LOOP Started !!!", flush=True)
r = requests.get('{}/anonymize'.format(root_api_url))
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
# print(r.text, flush=True)
response = r.json()
for detection in response:
print(str(detection['id']) + " Anonymization Started", flush=True)
img_path = "{}{}".format(base_path, detection['source_image_path'])
#print(img_path, flush=True)
#Skip Non existing files
if (not os.path.exists(img_path)):
continue
img = cv2.imread(img_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces, rejects, weights = face_cascade.detectMultiScale3(gray, 1.1, 4, outputRejectLevels = 1)
faces = RetinaFace.detect_faces(img, treashold)
#Count faces is null dont anonimize file
if (len(faces) < 0):
print(str(len(faces)) + " Faces Found" , flush=True)
if (len(faces) <= 0):
data = {
"id": detection['id'],
"source_image_path": img_path.replace(base_path,""),
"face_found": 0,
}
response = requests.post('{}/anonymize'.format(root_api_url), json=data)
print(str(detection['id']) + " Anonymized 0 faces" , flush=True)
continue
i = 0
for (x, y, w, h) in faces:
confidence = float(weights[i])
if (confidence > treashold):
face_roi = img[y:y+h, x:x+w]
blurred_face = cv2.GaussianBlur(face_roi, (99, 99), 50)
img[y:y+h, x:x+w] = blurred_face
print(weights[i])
text = "{}".format(weights[i])
#cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
#cv2.putText(img, text, (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
i = 0
for (key) in faces:
confidence = faces[key]["score"]
print(str(confidence) + " Faces Confidence" , flush=True)
x1, y1 = min(faces[key]["facial_area"][0], faces[key]["facial_area"][2]) - 2, min(faces[key]["facial_area"][1], faces[key]["facial_area"][3]) - 2
x2, y2 = max(faces[key]["facial_area"][0], faces[key]["facial_area"][2]) + 2, max(faces[key]["facial_area"][1], faces[key]["facial_area"][3]) + 2
x1, x2 = max(x1, 0), min(x2, img.shape[1])
y1, y2 = max(y1, 0), min(y2, img.shape[0])
face_roi = img[y1:y2, x1:x2]
blurred_face = cv2.GaussianBlur(face_roi, (99, 99), 50)
img[y1:y2, x1:x2] = blurred_face
print("Faces Anonymized" , flush=True)
i = i +1
#cv2.imshow("test_img", img)
#cv2.waitKey(0)
extension = img_path[img_path.index(".")+1:]
new_img_path = img_path.replace((".{}".format(extension)), ('_anonym.{}'.format(extension)))
new_img_path = img_path
if (not img_path.endswith(('_anonym.{}'.format(extension)))):
new_img_path = img_path.replace((".{}".format(extension)), ('_anonym.{}'.format(extension)))
else:
print("Path already anonymized !!!")
cv2.imwrite(new_img_path, img)
data = {
"id": detection['id'],
"source_image_path": new_img_path.replace(base_path,"")
"source_image_path": new_img_path.replace(base_path,""),
"face_found": len(faces),
}
response = requests.post('{}/anonymize'.format(root_api_url), json=data)
print(str(detection['id']) + " Anonymized" , flush=True)
time.sleep(10)
print("sleep", flush=True)
time.sleep(900)
except Exception as e:
print("An exception occurred")
print("An exception occurred", flush=True)
print(str(e), flush=True)
data = {"trace": str(e)}
response = requests.post('{}/log'.format(root_api_url), json=data)
+4 -1
View File
@@ -1,2 +1,5 @@
opencv-python
requests
numpy
requests
retina-face
tf-keras
+2
View File
@@ -0,0 +1,2 @@
echo "Starting..."
python3 /app/app.py