Better handling for missing cameras
This commit is contained in:
parent
9bf1145ac1
commit
f6a73563fb
@ -75,8 +75,7 @@ MERGED_SUBSAMPLE=3
|
|||||||
TIMEOUT = 5.0
|
TIMEOUT = 5.0
|
||||||
|
|
||||||
# Blank frame
|
# Blank frame
|
||||||
BLANK = np.full((720 // MERGED_SUBSAMPLE, 1280 // MERGED_SUBSAMPLE, 3), 0)
|
BLANK = np.full((720, 1280, 3), 0)
|
||||||
|
|
||||||
|
|
||||||
def tilera(iterable, filler):
|
def tilera(iterable, filler):
|
||||||
hstacking = ceil(len(iterable) ** 0.5)
|
hstacking = ceil(len(iterable) ** 0.5)
|
||||||
@ -89,7 +88,10 @@ def tilera(iterable, filler):
|
|||||||
try:
|
try:
|
||||||
frame = iterable[i + hstacking * j]
|
frame = iterable[i + hstacking * j]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
frame = None
|
||||||
|
if frame is None:
|
||||||
frame = filler
|
frame = filler
|
||||||
|
frame = frame[::MERGED_SUBSAMPLE, ::MERGED_SUBSAMPLE]
|
||||||
|
|
||||||
if not first_frame:
|
if not first_frame:
|
||||||
row.append(np.full((len(frame), 1, 3), 0))
|
row.append(np.full((len(frame), 1, 3), 0))
|
||||||
@ -150,7 +152,7 @@ async def stream_wrapper(request):
|
|||||||
async def stream_tiled(response):
|
async def stream_tiled(response):
|
||||||
while True:
|
while True:
|
||||||
frames = [value for key, value in sorted(app.ctx.frames.items())]
|
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))
|
_, jpeg = cv2.imencode(".jpg", img, (cv2.IMWRITE_JPEG_QUALITY, 80))
|
||||||
data = STREAM_RESPONSE + jpeg.tobytes()
|
data = STREAM_RESPONSE + jpeg.tobytes()
|
||||||
await response.write(data)
|
await response.write(data)
|
||||||
@ -165,7 +167,6 @@ async def stream_wrapper(request):
|
|||||||
|
|
||||||
@app.listener('before_server_start')
|
@app.listener('before_server_start')
|
||||||
async def setup_db(app, loop):
|
async def setup_db(app, loop):
|
||||||
app.ctx.last_frame = None
|
|
||||||
app.ctx.event_frame = asyncio.Event()
|
app.ctx.event_frame = asyncio.Event()
|
||||||
app.ctx.frames = {}
|
app.ctx.frames = {}
|
||||||
app.ctx.avg = None
|
app.ctx.avg = None
|
||||||
|
@ -10,7 +10,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
entrypoint: /app/camtiler.py
|
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:
|
mjpg-streamer:
|
||||||
network_mode: host
|
network_mode: host
|
||||||
|
Loading…
Reference in New Issue
Block a user