-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
44 lines (31 loc) · 1.1 KB
/
__init__.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 pickle
import struct
import socket
def main():
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('192.168.1.44', 9999) # Thay thế <IP_ADDRESS> bằng địa chỉ IP của máy chủ
client_socket.connect(server_address)
data = b""
payload_size = struct.calcsize("Q")
while True:
while len(data) < payload_size:
packet = client_socket.recv(4 * 1024) # Kích thước gói nhận
if not packet:
break
data += packet
packed_msg_size = data[:payload_size]
data = data[payload_size:]
msg_size = struct.unpack("Q", packed_msg_size)[0]
while len(data) < msg_size:
data += client_socket.recv(4 * 1024) # Kích thước gói nhận
frame_data = data[:msg_size]
data = data[msg_size:]
frame = pickle.loads(frame_data)
cv2.imshow('Camera IP', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
client_socket.close()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()