diff --git a/api/src/production/server.py b/api/src/production/server.py index 88b7023..ce40939 100644 --- a/api/src/production/server.py +++ b/api/src/production/server.py @@ -45,7 +45,8 @@ MAX_FRAME_BYTES = 1 * 1024 * 1024 MAX_IMAGE_PIXELS = 20_000_000 MAX_WEBSOCKETS = 3 MAX_WEBSOCKETS_PER_IP = 1 -FACE_MIN_INTERVAL = 1 / 2.1 +FACE_MAX_FPS = float(os.getenv("FACE_MAX_FPS", "5.5")) # per websocket connection +FACE_MIN_INTERVAL = 1 / FACE_MAX_FPS DECODE_DRAFT_SIZE = (256, 256) # JPEG decodes at reduced scale, still larger than the 64px model input torch.set_num_threads(TORCH_THREADS) diff --git a/website/src/Object_Detection.jsx b/website/src/Object_Detection.jsx index c8f1383..63c6761 100644 --- a/website/src/Object_Detection.jsx +++ b/website/src/Object_Detection.jsx @@ -3,6 +3,11 @@ import { useRef, useEffect, useState } from 'react' const FRAME_QUALITY = 0.7; +// How many frames per second are sent to the API. The server drops frames +// arriving faster than ~2.1/s (FACE_MAX_FPS in server.py), so values +// above that have no effect unless the server limit is raised too. +const FRAMES_PER_SECOND = 5; + function Object_Detection() { const videoRef = useRef(null); const canvasRefBBox = useRef(null); @@ -125,7 +130,7 @@ function Object_Detection() { if (!canvas) return; ctx.clearRect(0, 0, canvas.width, canvas.height); - sendImageIntervall.current = setInterval(sendImage, 1000 / 2); + sendImageIntervall.current = setInterval(sendImage, 1000 / FRAMES_PER_SECOND); } socket.onmessage = (event) => { drawBBox(JSON.parse(event.data).bboxes);