stm32-fmt-code/access_control_python/camera_test.py

33 lines
747 B
Python

import numpy as np
import cv2
import base64
import requests
# #Capture Image
# cam = cv2.VideoCapture(1)
# ret, img = cam.read()
# #Save Image
# cv2.imwrite("cam_test_img_pre.jpg",img)
#Load Image
img = cv2.imread("cam_test_img_pre.jpg")
#Encode Image
ret, jpg_buffer = cv2.imencode('.jpg',img)
b64_img = base64.b64encode(jpg_buffer)
#Send Image to Server
api_endpoint = "https://racist.siwatsystem.com/process_image"
api_endpoint = "http://localhost:5000/identify_face"
data = {"image":b64_img.decode("utf-8")}
req = requests.post(api_endpoint,json=data)
print(req.content)
#Decode Image
img_nparr = np.frombuffer(base64.b64decode(b64_img),np.uint8)
img = cv2.imdecode(img_nparr,cv2.IMREAD_COLOR)
cv2.imwrite("cam_test_img_post.jpg",img)