added send intervall of 2 fps
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user