-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
39 lines (26 loc) · 1.04 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
import cv2
import requests
def send_video(client_id, server_ip, server_port=5000):
video_capture = cv2.VideoCapture(0)
while True:
ret, frame = video_capture.read()
if not ret:
print("Failed to capture frame")
break
_, img_encoded = cv2.imencode('.jpg', frame)
try:
response = requests.post(f'http://{server_ip}:{server_port}/upload_frame/{client_id}', files={'frame': img_encoded.tobytes()})
if response.status_code != 200:
print(f"Failed to send frame: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Error sending frame: {e}")
break
cv2.imshow(f'Client {client_id} - Captured Frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
client_id = 'client2'
server_ip = '192.168.45.207'
send_video(client_id, server_ip)