changed bboxes
This commit is contained in:
@@ -8,7 +8,6 @@ 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 bboxes = useRef(null)
|
|
||||||
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);
|
||||||
@@ -25,22 +24,20 @@ function Object_Detection() {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const drawBBox = () => {
|
const drawBBox = (bboxes) => {
|
||||||
const video = videoRef.current;
|
|
||||||
const canvas = canvasRefBBox.current;
|
const canvas = canvasRefBBox.current;
|
||||||
if (!canvas) return;
|
if (!canvas) return;
|
||||||
|
|
||||||
const ctx = ctxRefBBox.current;
|
const ctx = ctxRefBBox.current;
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
if (!canvas) return;
|
|
||||||
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
ctx.strokeStyle = "red";
|
ctx.strokeStyle = "red";
|
||||||
ctx.lineWidth = 1;
|
ctx.lineWidth = 1;
|
||||||
|
|
||||||
if (bboxes.current) {
|
if (bboxes) {
|
||||||
bboxes.current.forEach(edge => {
|
bboxes.forEach(edge => {
|
||||||
const x1 = Math.max(edge[0], 0);
|
const x1 = Math.max(edge[0], 0);
|
||||||
const y1 = Math.max(edge[1], 0);
|
const y1 = Math.max(edge[1], 0);
|
||||||
const x2 = Math.min(edge[2], canvas.width);
|
const x2 = Math.min(edge[2], canvas.width);
|
||||||
@@ -129,8 +126,7 @@ function Object_Detection() {
|
|||||||
sendImageIntervall.current = setInterval(sendImage, 1000 / 2);
|
sendImageIntervall.current = setInterval(sendImage, 1000 / 2);
|
||||||
}
|
}
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
bboxes.current = JSON.parse(event.data).bboxes;
|
drawBBox(JSON.parse(event.data).bboxes);
|
||||||
drawBBox();
|
|
||||||
}
|
}
|
||||||
socket.onerror = () => {
|
socket.onerror = () => {
|
||||||
console.log("Websocket Error");
|
console.log("Websocket Error");
|
||||||
@@ -162,8 +158,6 @@ function Object_Detection() {
|
|||||||
socketRef.current = null;
|
socketRef.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bboxes.current = null;
|
|
||||||
|
|
||||||
if (videoRef.current) {
|
if (videoRef.current) {
|
||||||
videoRef.current.srcObject = null;
|
videoRef.current.srcObject = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user