-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.py
executable file
·44 lines (34 loc) · 1.01 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
import cv2
import io
import socket
import struct
import time
import pickle
import numpy as np
import imutils
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# client_socket.connect(('0.tcp.ngrok.io', 19194))
client_socket.connect(('10.19.15.138', 8485))
cam = cv2.VideoCapture(0)
img_counter = 0
#encode to jpeg format
#encode param image quality 0 to 100. default:95
#if you want to shrink data size, choose low image quality.
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
while True:
ret, frame = cam.read()
# 影像縮放
frame = imutils.resize(frame, width=320)
# 鏡像
frame = cv2.flip(frame,180)
result, image = cv2.imencode('.jpg', frame, encode_param)
data = pickle.dumps(image, 0)
size = len(data)
if img_counter%10==0:
client_socket.sendall(struct.pack(">L", size) + data)
cv2.imshow('client',frame)
img_counter += 1
# 若按下 q 鍵則離開迴圈
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cam.release()