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):
|
async def predict_face(websocket: WebSocket):
|
||||||
await websocket.accept()
|
await websocket.accept()
|
||||||
|
|
||||||
#last = time.time()
|
last = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
jpg_bytes = await websocket.receive_bytes()
|
jpg_bytes = await websocket.receive_bytes()
|
||||||
|
|
||||||
#if time.time() - last < 1:
|
if time.time() - last < 1 / 2:
|
||||||
#continue
|
continue
|
||||||
|
|
||||||
#last = time.time()
|
last = time.time()
|
||||||
with sem_ai:
|
with sem_ai:
|
||||||
|
|
||||||
np_arr = np.frombuffer(jpg_bytes, np.uint8)
|
np_arr = np.frombuffer(jpg_bytes, np.uint8)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ function Object_Detection() {
|
|||||||
const socketRef = useRef(null);
|
const socketRef = useRef(null);
|
||||||
const [running, setRunning] = useState(false);
|
const [running, setRunning] = useState(false);
|
||||||
const streamRef = useRef(null);
|
const streamRef = useRef(null);
|
||||||
|
const sendImageIntervall = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (canvasRefBBox.current) {
|
if (canvasRefBBox.current) {
|
||||||
@@ -125,14 +126,19 @@ function Object_Detection() {
|
|||||||
if (!canvas) return;
|
if (!canvas) return;
|
||||||
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
sendImage();
|
sendImageIntervall.current = setInterval(sendImage, 1000 / 2);
|
||||||
}
|
}
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
bboxes.current = JSON.parse(event.data).bboxes;
|
bboxes.current = JSON.parse(event.data).bboxes;
|
||||||
drawBBox();
|
drawBBox();
|
||||||
sendImage();
|
|
||||||
}
|
}
|
||||||
socket.onerror = console.error;
|
socket.onerror = () => {
|
||||||
|
console.log("Websocket Error");
|
||||||
|
printDefault();
|
||||||
|
setRunning(false);
|
||||||
|
|
||||||
|
endWebcam();
|
||||||
|
}
|
||||||
socket.onclose = () => {
|
socket.onclose = () => {
|
||||||
console.log("Disconnected");
|
console.log("Disconnected");
|
||||||
printDefault();
|
printDefault();
|
||||||
@@ -165,6 +171,10 @@ function Object_Detection() {
|
|||||||
if (streamRef.current) {
|
if (streamRef.current) {
|
||||||
streamRef.current.getTracks().forEach(track => track.stop());
|
streamRef.current.getTracks().forEach(track => track.stop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sendImageIntervall.current){
|
||||||
|
clearInterval(sendImageIntervall.current);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user