-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_cv.py
55 lines (34 loc) · 1.01 KB
/
server_cv.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
47
48
49
50
51
52
53
54
from numpysocket import NumpySocket
import cv2
import time
import threading
print('ata')
#host_ip = '192.168.1.143' # change me
#host_ip = '172.27.3.3'
host_ip = '192.168.1.143'
cap = cv2.VideoCapture(0)
npSocket = NumpySocket()
npSocket.startServer(host_ip, 9999)
time.sleep(2)
thread_socket = NumpySocket()
thread_socket.startServer(host_ip, 9900)
recieve_socket = NumpySocket()
recieve_socket.startClient(9001)
def thread_function(my_socket, data):
my_socket.sendNumpy(data)
# Read until video is completed
n_frame = 0
while(cap.isOpened()):
#print('h')
ret, frame = cap.read()
#print(frame, ret)
#ref_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame_resize = frame[::2, ::2]
n_frame +=1
npSocket.sendNumpy(frame_resize[:120])
th = threading.Thread(target=thread_function, args=(thread_socket, frame_resize[120:], ))
th.start()
recieve_socket.recieveAck()
# When everything done, release the video capture object
npSocket.endServer()
cap.release()