forked from dltmdgh1994/Driver-Protection-Service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmotion_pub.py
More file actions
40 lines (29 loc) · 908 Bytes
/
Copy pathEmotion_pub.py
File metadata and controls
40 lines (29 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import paho.mqtt.publish as publish
import cv2
import time
import json
import base64
with open('../key.json', 'r') as f:
json_data = json.load(f)
cap = cv2.VideoCapture('C:/Users/s_csmscox/jupyterSave/eye_blink/ych.mp4')
total_start = time.time()
frame = 0
while True:
ret, img = cap.read()
start = time.time()
if not ret:
break
# if frame % 2 == 0:
img = cv2.resize(img, dsize=(0, 0), fx=0.5, fy=0.5)
cv2.imwrite('output.jpg', img)
f = open("output.jpg", "rb")
file = f.read()
byteArr = base64.b64encode(file)
# byteArr = base64.b64encode(img)
MQTT_MSG = json.dumps({"byteArr": byteArr.decode('utf-8'), "user_id": frame})
publish.single("Emotion/img", MQTT_MSG, hostname=json_data["EC2"]["AI_IP"])
print("", frame)
print(time.time() - start)
time.sleep(0.005)
frame += 1
print("total_time :", time.time() - total_start)