stm32-fmt-code/access_control_python/face_processing.py

36 lines
1002 B
Python
Raw Permalink Normal View History

2023-09-24 18:30:29 +00:00
import numpy as np
import cv2
import base64
import requests
import json
2023-09-24 18:47:30 +00:00
#api_server = "http://localhost:5000"
2023-09-30 08:23:10 +00:00
api_server = "http://192.168.0.239"
#api_server = "https://racist.siwatsystem.com"
2023-09-24 18:30:29 +00:00
def analyze_face(img):
endpoint = api_server +"/process_image"
ret, jpg_buffer = cv2.imencode('.jpg',img)
b64_img = base64.b64encode(jpg_buffer)
data = {"image":b64_img.decode("utf-8")}
req = requests.post(endpoint,json=data)
res = res.content.decode("utf-8")
2023-09-24 18:47:30 +00:00
try:
res = json.loads(res)
except:
pass
2023-09-24 18:30:29 +00:00
return res
def identify_face(img, target_condidence: float):
endpoint = api_server +"/identify_face"
ret, jpg_buffer = cv2.imencode('.jpg',img)
b64_img = base64.b64encode(jpg_buffer)
data = {"image":b64_img.decode("utf-8"),"target_confidence": target_condidence}
req = requests.post(endpoint,json=data)
res = req.content.decode("utf-8")
2023-09-24 18:47:30 +00:00
print(res)
try:
res = json.loads(res)
except:
pass
2023-09-24 18:30:29 +00:00
return res