stm32-fmt-code/access_control_python/face_analyzer.py

41 lines
979 B
Python
Raw Normal View History

2023-09-22 19:45:14 +00:00
import numpy as np
import cv2
import base64
import requests
import json
2023-09-22 19:59:24 +00:00
import threading
import time
2023-09-22 20:00:13 +00:00
cam = cv2.VideoCapture(1)
2023-09-22 19:59:24 +00:00
global img
global frame_ready
frame_ready = False
def read_webcam():
global img
global frame_ready
while True:
ret, img = cam.read()
frame_ready = True
threading.Thread(target=read_webcam).start()
2023-09-22 19:45:14 +00:00
while True:
2023-09-22 19:59:24 +00:00
while not frame_ready:
time.sleep(1)
2023-09-22 19:45:14 +00:00
ret, jpg_buffer = cv2.imencode('.jpg',img)
b64_img = base64.b64encode(jpg_buffer)
data = {"image":b64_img.decode("utf-8")}
res = requests.post("https://racist.siwatsystem.com/process_image",json=data)
res = res.content.decode("utf-8")
res = json.loads(res)
2023-09-22 20:00:56 +00:00
#print(res)
2023-09-22 19:45:14 +00:00
if len(res) >0:
if (res[0]['dominant_race']=="asian"):
print("Ching Chong")
elif(res[0]['dominant_race']=="black"):
print("CRIMINAL!!")
elif (res[0]['dominant_race']=="white"):
2023-09-22 19:59:24 +00:00
print("Ding Dong")