Progress Clean Up
This commit is contained in:
@@ -3,44 +3,47 @@ import time
|
|||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
treashold = float(5)
|
treashold = float(os.getenv('FACE_TRASHOLD', '0,5'))
|
||||||
sever = os.getenv('API_ROOT', 'localhost')
|
sever = os.getenv('API_ROOT', 'localhost')
|
||||||
root_api_url = 'http://{}/local'.format(sever)
|
root_api_url = 'http://{}/local'.format(sever)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get('{}/detections/anonymize'.format(root_api_url))
|
while True:
|
||||||
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
r = requests.get('{}/anonymize'.format(root_api_url))
|
||||||
|
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
||||||
|
|
||||||
for detection in r.json():
|
for detection in r.json():
|
||||||
img_path = "/data/{}".format(detection.filename)
|
img_path = "/data/{}".format(detection.source_image_path)
|
||||||
img = cv2.imread(img_path)
|
img = cv2.imread(img_path)
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
faces, rejects, weights = face_cascade.detectMultiScale3(gray, 1.1, 4, outputRejectLevels = 1)
|
faces, rejects, weights = face_cascade.detectMultiScale3(gray, 1.1, 4, outputRejectLevels = 1)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for (x, y, w, h) in faces:
|
for (x, y, w, h) in faces:
|
||||||
confidence = float(weights[i])
|
confidence = float(weights[i])
|
||||||
if (confidence > treashold):
|
if (confidence > treashold):
|
||||||
face_roi = img[y:y+h, x:x+w]
|
face_roi = img[y:y+h, x:x+w]
|
||||||
blurred_face = cv2.GaussianBlur(face_roi, (99, 99), 20)
|
blurred_face = cv2.GaussianBlur(face_roi, (99, 99), 20)
|
||||||
img[y:y+h, x:x+w] = blurred_face
|
img[y:y+h, x:x+w] = blurred_face
|
||||||
|
|
||||||
print(weights[i])
|
print(weights[i])
|
||||||
text = "{}".format(weights[i])
|
text = "{}".format(weights[i])
|
||||||
#cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 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)
|
#cv2.putText(img, text, (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
|
||||||
|
|
||||||
i = i +1
|
i = i +1
|
||||||
|
|
||||||
extension = img_path[img_path.index(".")+1:]
|
extension = img_path[img_path.index(".")+1:]
|
||||||
new_img_path = img_path.replace(extension, ('_anonym{}'.format(extension)))
|
new_img_path = img_path.replace(extension, ('_anonym{}'.format(extension)))
|
||||||
cv2.imwrite(new_img_path, img)
|
cv2.imwrite(new_img_path, img)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"detection_id": detection.id,
|
"id": detection.id,
|
||||||
"detection_path": new_img_path
|
"source_image_path": new_img_path
|
||||||
}
|
}
|
||||||
response = requests.post('{}/detections/anonymized'.format(root_api_url), json=data)
|
response = requests.post('{}/anonymize'.format(root_api_url), json=data)
|
||||||
|
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("An exception occurred")
|
print("An exception occurred")
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user