diff --git a/app.py b/app.py index 0045508..e910cf9 100644 --- a/app.py +++ b/app.py @@ -3,15 +3,16 @@ import time import os import requests -img_path ="image.png" treashold = float(5) -sever = os.environ['API_ROOT'] +sever = os.getenv('API_ROOT', 'localhost') +root_api_url = 'http://{}/local'.format(sever) try: - r = requests.get('http://{}/local/detections/anonymize'.format(sever)) + r = requests.get('{}/detections/anonymize'.format(root_api_url)) face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') for detection in r.json(): + img_path = "/data/{}".format(detection.filename) img = cv2.imread(img_path) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces, rejects, weights = face_cascade.detectMultiScale3(gray, 1.1, 4, outputRejectLevels = 1) @@ -26,12 +27,22 @@ try: 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) + #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 = i +1 + + extension = img_path[img_path.index(".")+1:] + new_img_path = img_path.replace(extension, ('_anonym{}'.format(extension))) + cv2.imwrite(new_img_path, img) - cv2.imwrite(img_path, img) + data = { + "detection_id": detection.id, + "detection_path": new_img_path + } + response = requests.post('{}/detections/anonymized'.format(root_api_url), json=data) -except: - print("An exception occurred") \ No newline at end of file +except Exception as e: + print("An exception occurred") + data = {"trace": e.__traceback__,} + response = requests.post('{}/log'.format(root_api_url), json=data) \ No newline at end of file diff --git a/data_anonimized/.gitkeep b/data/.gitkeep similarity index 100% rename from data_anonimized/.gitkeep rename to data/.gitkeep diff --git a/data_raw/.gitkeep b/data_raw/.gitkeep deleted file mode 100644 index e69de29..0000000