2023-09-22 17:42:16 +00:00
|
|
|
import numpy as np
|
|
|
|
import cv2
|
2023-09-22 18:37:02 +00:00
|
|
|
import base64
|
|
|
|
import requests
|
2023-09-22 17:42:16 +00:00
|
|
|
|
2023-09-22 18:37:02 +00:00
|
|
|
#Capture Image
|
2023-09-22 17:42:16 +00:00
|
|
|
cam = cv2.VideoCapture(0)
|
2023-09-22 18:37:02 +00:00
|
|
|
ret, img = cam.read()
|
2023-09-22 17:42:16 +00:00
|
|
|
|
2023-09-22 18:37:02 +00:00
|
|
|
#Save Image
|
|
|
|
cv2.imwrite("cam_test_img_pre.jpg",img)
|
|
|
|
|
|
|
|
#Encode Image
|
|
|
|
ret, jpg_buffer = cv2.imencode('.jpg',img)
|
|
|
|
b64_img = base64.b64encode(jpg_buffer)
|
|
|
|
print(b64_img)
|
|
|
|
|
|
|
|
#Send Image to Server
|
|
|
|
data = {"image":b64_img.decode("utf-8")}
|
|
|
|
req = requests.post("http://localhost:5000/process_image",json=data)
|
|
|
|
|
|
|
|
#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)
|
2023-09-22 17:42:16 +00:00
|
|
|
|