Update face_analyzer.py
This commit is contained in:
parent
85a828d366
commit
2a2a3b30ce
|
@ -3,17 +3,34 @@ import cv2
|
||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
cam = cv2.VideoCapture(1)
|
import threading
|
||||||
|
import time
|
||||||
|
cam = cv2.VideoCapture(0)
|
||||||
|
|
||||||
|
global img
|
||||||
|
global frame_ready
|
||||||
|
frame_ready = False
|
||||||
|
|
||||||
|
def read_webcam():
|
||||||
|
global img
|
||||||
|
global frame_ready
|
||||||
while True:
|
while True:
|
||||||
ret, img = cam.read()
|
ret, img = cam.read()
|
||||||
|
frame_ready = True
|
||||||
|
|
||||||
|
threading.Thread(target=read_webcam).start()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
while not frame_ready:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
ret, jpg_buffer = cv2.imencode('.jpg',img)
|
ret, jpg_buffer = cv2.imencode('.jpg',img)
|
||||||
b64_img = base64.b64encode(jpg_buffer)
|
b64_img = base64.b64encode(jpg_buffer)
|
||||||
data = {"image":b64_img.decode("utf-8")}
|
data = {"image":b64_img.decode("utf-8")}
|
||||||
res = requests.post("https://racist.siwatsystem.com/process_image",json=data)
|
res = requests.post("https://racist.siwatsystem.com/process_image",json=data)
|
||||||
res = res.content.decode("utf-8")
|
res = res.content.decode("utf-8")
|
||||||
res = json.loads(res)
|
res = json.loads(res)
|
||||||
#print(req)
|
print(res)
|
||||||
if len(res) >0:
|
if len(res) >0:
|
||||||
if (res[0]['dominant_race']=="asian"):
|
if (res[0]['dominant_race']=="asian"):
|
||||||
print("Ching Chong")
|
print("Ching Chong")
|
||||||
|
|
Loading…
Reference in New Issue