added send intervall of 2 fps

This commit is contained in:
2026-06-04 15:10:57 +02:00
parent 9dcc5915aa
commit 8a3d6319d3
2 changed files with 17 additions and 7 deletions
+4 -4
View File
@@ -97,16 +97,16 @@ async def predict(file: UploadFile = File(...)):
async def predict_face(websocket: WebSocket):
await websocket.accept()
#last = time.time()
last = time.time()
try:
while True:
jpg_bytes = await websocket.receive_bytes()
#if time.time() - last < 1:
#continue
if time.time() - last < 1 / 2:
continue
#last = time.time()
last = time.time()
with sem_ai:
np_arr = np.frombuffer(jpg_bytes, np.uint8)
+13 -3
View File
@@ -12,6 +12,7 @@ function Object_Detection() {
const socketRef = useRef(null);
const [running, setRunning] = useState(false);
const streamRef = useRef(null);
const sendImageIntervall = useRef(null);
useEffect(() => {
if (canvasRefBBox.current) {
@@ -125,14 +126,19 @@ function Object_Detection() {
if (!canvas) return;
ctx.clearRect(0, 0, canvas.width, canvas.height);
sendImage();
sendImageIntervall.current = setInterval(sendImage, 1000 / 2);
}
socket.onmessage = (event) => {
bboxes.current = JSON.parse(event.data).bboxes;
drawBBox();
sendImage();
}
socket.onerror = console.error;
socket.onerror = () => {
console.log("Websocket Error");
printDefault();
setRunning(false);
endWebcam();
}
socket.onclose = () => {
console.log("Disconnected");
printDefault();
@@ -165,6 +171,10 @@ function Object_Detection() {
if (streamRef.current) {
streamRef.current.getTracks().forEach(track => track.stop());
}
if(sendImageIntervall.current){
clearInterval(sendImageIntervall.current);
}
}
return (