import cv2 import socket import zstandard as zstd import struct import time from utils import resize_with_padding SERVER_IP = '127.0.0.1' SERVER_PORT = 9999 # Socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((SERVER_IP, SERVER_PORT)) # Kompresor Zstd compressor = zstd.ZstdCompressor(level=10) cap = cv2.VideoCapture(0) # kamerka total_bytes_sent = 0 start_time = time.time() JPEG_QUALITY = 25 # 0-100, im mniejsza, tym większa kompresja try: while True: ret, frame = cap.read() if not ret: break frame = resize_with_padding(frame) # Konwersja do JPEG _, buffer = cv2.imencode('.jpg', frame, [cv2.IMWRITE_JPEG_QUALITY, JPEG_QUALITY]) data = buffer.tobytes() # Wysyłanie długości + danych sock.sendall(struct.pack('!I', len(data))) sock.sendall(data) total_bytes_sent += len(data) elapsed = time.time() - start_time if elapsed >= 1.0: print(f"Upload speed: {total_bytes_sent * 8 / 1e6:.2f} Mbps") # w megabitach total_bytes_sent = 0 start_time = time.time() finally: cap.release() sock.close()