Better handling for missing cameras

This commit is contained in:
Lauri Võsandi 2022-02-13 17:49:49 +02:00 committed by Lauri Võsandi
parent 9bf1145ac1
commit f6a73563fb
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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