From a8276a1b25bc59a4f7e1d12e912cdb7eb81bd7e2 Mon Sep 17 00:00:00 2001 From: ahmedmujtaba-gif Date: Thu, 16 Apr 2026 18:47:34 +0500 Subject: [PATCH] Server Push 0.3 --- camera_stream.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/camera_stream.py b/camera_stream.py index dbb2572..d7c1bc7 100644 --- a/camera_stream.py +++ b/camera_stream.py @@ -21,7 +21,7 @@ PASSWORD = os.getenv("password") # Dynamically find all camera_ip_N variables in environment CAMERA_IPS = [] -for i in range(1, 11): # Supports up to 10 cameras +for i in range(1, 101): # Supports up to 100 cameras ip = os.getenv(f"camera_ip_{i}") if ip and ip.strip(): CAMERA_IPS.append(ip.strip()) @@ -223,13 +223,31 @@ def _update_grid_frame(): time.sleep(0.1); continue n = len(frames) - if n == 1: grid = frames[0] - elif n == 2: grid = np.hstack(frames) - else: - row1 = np.hstack(frames[:2]) - if n == 3: row2 = np.hstack([frames[2], np.zeros_like(frames[0])]) - else: row2 = np.hstack(frames[2:4]) - grid = np.vstack([row1, row2]) + if n == 0: + time.sleep(0.1); continue + + # Calculate grid dimensions (rows/cols) + cols = int(np.ceil(np.sqrt(n))) + rows = int(np.ceil(n / cols)) + + # Determine cell size + # Use 320x240 for large grids to prevent the output frame from being too massive + cell_w, cell_h = 320, 240 + if n <= 1: cell_w, cell_h = 640, 480 + elif n <= 4: cell_w, cell_h = 480, 360 + + grid_rows = [] + for r in range(rows): + row_items = [] + for c in range(cols): + idx = r * cols + c + if idx < n: + row_items.append(cv2.resize(frames[idx], (cell_w, cell_h))) + else: + row_items.append(np.zeros((cell_h, cell_w, 3), dtype=np.uint8)) + grid_rows.append(np.hstack(row_items)) + + grid = np.vstack(grid_rows) with lock: state["grid_frame"] = grid