changed yolo design

This commit is contained in:
2026-05-30 19:29:43 +02:00
parent 66462c8f80
commit 4411fac977
4 changed files with 23 additions and 33 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ async def predict_face(websocket: WebSocket):
#if time.time() - last < 1: #if time.time() - last < 1:
#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)
+1 -1
View File
@@ -75,7 +75,7 @@ def use_webcam(grid, img_size):
prediction = model(image) prediction = model(image)
bboxes, grid_ob, grid_noob = convert_prediction(prediction.squeeze(0), image.squeeze(0), threshold=0.9) bboxes, grid_ob, grid_noob = convert_prediction(prediction.squeeze(0), image.squeeze(0), threshold=0.95)
for bbox in grid_noob: for bbox in grid_noob:
xmin = int(bbox[0] * scale_w) xmin = int(bbox[0] * scale_w)
+18 -28
View File
@@ -8,13 +8,8 @@ function Object_Detection() {
const ctxRefBBox = useRef(null); const ctxRefBBox = useRef(null);
const ctxRefSending = useRef(null); const ctxRefSending = useRef(null);
const [error, setError] = useState(false); const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const bboxes = useRef(null) const bboxes = useRef(null)
const socketRef = useRef(null); const socketRef = useRef(null);
const captureIntervalRef = useRef(null);
const drawIntervalRef = useRef(null);
const drawingRef = useRef(null);
const sendingRef = useRef(null);
const [running, setRunning] = useState(false); const [running, setRunning] = useState(false);
useEffect(() => { useEffect(() => {
@@ -68,7 +63,11 @@ function Object_Detection() {
if (bboxes.current) { if (bboxes.current) {
bboxes.current.forEach(edge => { bboxes.current.forEach(edge => {
ctx.strokeRect(edge[0], edge[1], edge[2] - edge[0], edge[3] - edge[1]); const x1 = Math.max(edge[0], 0);
const y1 = Math.max(edge[1], 0);
const x2 = Math.min(edge[2], canvas.width);
const y2 = Math.min(edge[3], canvas.height);
ctx.strokeRect(x1, y1, x2 - x1, y2 - y1);
}); });
} }
}; };
@@ -77,28 +76,20 @@ function Object_Detection() {
const video = videoRef.current; const video = videoRef.current;
const canvas = canvasRefSending.current; const canvas = canvasRefSending.current;
const canvasW = canvas.width;
const canvasH = canvas.height;
const ctx = ctxRefSending.current; const ctx = ctxRefSending.current;
if (!ctx) return; if (!ctx) return;
ctx.drawImage(video, 0, 0, canvasW, canvasH); ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.toBlob(async (blob) => { canvas.toBlob(async (blob) => {
if (!blob) return; if (!blob) return;
setLoading(true)
try { try {
socketRef.current?.send(blob) socketRef.current?.send(blob)
} catch (e) { } catch (e) {
setError(true); setError(true);
} }
finally { }, "image/jpeg", 1);
setLoading(false);
}
}, "image/jpeg", 0.9);
}; };
const printDefault = () => { const printDefault = () => {
@@ -125,16 +116,6 @@ function Object_Detection() {
socketRef.current = null; socketRef.current = null;
} }
if (drawingRef.current) {
clearInterval(drawingRef.current);
drawingRef.current = null;
}
if (sendingRef.current) {
clearInterval(sendingRef.current);
sendingRef.current = null;
}
bboxes.current = null; bboxes.current = null;
printDefault(); printDefault();
@@ -142,16 +123,25 @@ function Object_Detection() {
return; return;
} }
const video = videoRef.current;
const canvas = canvasRefBBox.current;
const ctx = ctxRefBBox.current;
if (!ctx) return;
ctx.clearRect(0, 0, canvas.width, canvas.height);
const socket = new WebSocket("wss://api.marvinkrausser.com/predict_face"); const socket = new WebSocket("wss://api.marvinkrausser.com/predict_face");
socketRef.current = socket; socketRef.current = socket;
socket.onopen = () => { socket.onopen = () => {
console.log("Connected"); console.log("Connected");
sendingRef.current = setInterval(sendImage, 100); sendImage();
} }
socket.onmessage = (event) => { socket.onmessage = (event) => {
drawBBox(); drawBBox();
bboxes.current = JSON.parse(event.data).bboxes; bboxes.current = JSON.parse(event.data).bboxes;
sendImage();
} }
socket.onerror = console.error; socket.onerror = console.error;
socket.onclose = () => console.log("Disconnected"); socket.onclose = () => console.log("Disconnected");
@@ -173,7 +163,7 @@ function Object_Detection() {
htmlFor="button-send" htmlFor="button-send"
className="custom-button" className="custom-button"
> >
Ask Expert {running? "End Detection" : "Start Detection"}
</label> </label>
</div> </div>
<div id={styles.container}> <div id={styles.container}>
+3 -3
View File
@@ -1,8 +1,8 @@
#container { #container {
margin: 0px; margin: 0px;
width: 500px; width: 80vw;
height: 500px; height: 70vh;
border: 10px #333 solid; background-color: black;
align-self: center; align-self: center;
position: relative; position: relative;
} }