-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
46 lines (37 loc) · 1.02 KB
/
client.py
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
41
42
43
44
45
46
import cv2
import numpy as np
import socket
import sys
import pickle
import struct
import io
import json
import pickle
import image_convert
import tensorflow as tf
cap = cv2.VideoCapture(0)
clientsocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clientsocket.connect(('localhost', 8089))
while(cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame, (480, 320))
# Canny
# frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# print(frame.shape)
# frame = cv2.Canny(frame, 100, 200)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = frame.reshape(1, 320, 480, 3)
# global graph
with tf.Graph().as_default():
frame = image_convert.model.predict(frame)
frame = frame.reshape(320, 480)
frame = frame * 255
# memfile = io.BytesIO()
# np.save(memfile, frame)
# memfile.seek(0)
# data = json.dumps(memfile.read().decode('latin-1'))
data = pickle.dumps(frame)
clientsocket.sendall(struct.pack("L", len(data)) + data)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()