From f6a73563fb22d0f1b5756af0a7d5e4fad19903d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Sun, 13 Feb 2022 17:49:49 +0200 Subject: [PATCH] Better handling for missing cameras --- camtiler.py | 9 +++++---- docker-compose.yml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/camtiler.py b/camtiler.py index 24c7e28..d62a8c9 100755 --- a/camtiler.py +++ b/camtiler.py @@ -75,8 +75,7 @@ MERGED_SUBSAMPLE=3 TIMEOUT = 5.0 # Blank frame -BLANK = np.full((720 // MERGED_SUBSAMPLE, 1280 // MERGED_SUBSAMPLE, 3), 0) - +BLANK = np.full((720, 1280, 3), 0) def tilera(iterable, filler): hstacking = ceil(len(iterable) ** 0.5) @@ -89,7 +88,10 @@ def tilera(iterable, filler): try: frame = iterable[i + hstacking * j] except IndexError: + frame = None + if frame is None: frame = filler + frame = frame[::MERGED_SUBSAMPLE, ::MERGED_SUBSAMPLE] if not first_frame: row.append(np.full((len(frame), 1, 3), 0)) @@ -150,7 +152,7 @@ async def stream_wrapper(request): async def stream_tiled(response): while True: frames = [value for key, value in sorted(app.ctx.frames.items())] - img = tilera(frames, np.vstack([BLANK, np.zeros((30, 1280 // MERGED_SUBSAMPLE, 3))])) + img = tilera(frames, BLANK) _, jpeg = cv2.imencode(".jpg", img, (cv2.IMWRITE_JPEG_QUALITY, 80)) data = STREAM_RESPONSE + jpeg.tobytes() await response.write(data) @@ -165,7 +167,6 @@ async def stream_wrapper(request): @app.listener('before_server_start') async def setup_db(app, loop): - app.ctx.last_frame = None app.ctx.event_frame = asyncio.Event() app.ctx.frames = {} app.ctx.avg = None diff --git a/docker-compose.yml b/docker-compose.yml index 7ceddf4..b0d1a0a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: build: context: . entrypoint: /app/camtiler.py - command: http://127.0.0.1:8080?action=stream http://127.0.0.2:8080?action=stream http://127.0.0.3:8080?action=stream http://127.0.0.4:8080?action=stream + command: http://127.0.0.1:8080?action=stream http://127.0.0.2:8080?action=stream http://127.0.0.3:8080?action=stream http://127.0.0.4:1234 mjpg-streamer: network_mode: host