From 56edd90b6fda61e4ae6e4314bd01fbb11e57062b Mon Sep 17 00:00:00 2001 From: marvinkrausser Date: Fri, 29 May 2026 10:20:58 +0200 Subject: [PATCH] added webcam --- website/src/App.jsx | 2 + website/src/Menu.jsx | 1 + website/src/Object_Detection.jsx | 65 +++++++++++++++++++++++++ website/src/Object_Detection.module.css | 11 +++++ 4 files changed, 79 insertions(+) create mode 100644 website/src/Object_Detection.jsx create mode 100644 website/src/Object_Detection.module.css diff --git a/website/src/App.jsx b/website/src/App.jsx index b56de3a..1f77a6c 100644 --- a/website/src/App.jsx +++ b/website/src/App.jsx @@ -8,6 +8,7 @@ import Menu from './Menu' import Homepage from './Homepage'; import Bird_CNN from './Bird_CNN'; import Reviews from './Reviews.jsx'; +import Object_Detection from './Object_Detection.jsx'; function App() { @@ -17,6 +18,7 @@ function App() { } /> } /> + } /> } /> } /> diff --git a/website/src/Menu.jsx b/website/src/Menu.jsx index 772f057..1eb35a0 100644 --- a/website/src/Menu.jsx +++ b/website/src/Menu.jsx @@ -7,6 +7,7 @@ function Menu() { diff --git a/website/src/Object_Detection.jsx b/website/src/Object_Detection.jsx new file mode 100644 index 0000000..1dbd73e --- /dev/null +++ b/website/src/Object_Detection.jsx @@ -0,0 +1,65 @@ +import styles from './Object_Detection.module.css'; +import { useRef, useEffect } from 'react' + +function Object_Detection() { + const videoRef = useRef(null); + + useEffect(() => { + async function startWebcam() { + try { + const stream = await navigator.mediaDevices.getUserMedia({ + video: true, + audio: false, + }); + + if (videoRef.current) { + videoRef.current.srcObject = stream; + } + } catch (err) { + console.error("Error accessing webcam:", err); + } + } + + startWebcam(); + + return () => { + if (videoRef.current?.srcObject) { + const tracks = videoRef.current.srcObject.getTracks(); + tracks.forEach((track) => track.stop()); + } + }; + }, []); + + const captureImage = () => { + const video = videoRef.current; + const canvas = canvasRef.current; + + const width = video.videoWidth; + const height = video.videoHeight; + + canvas.width = width; + canvas.height = height; + + const ctx = canvas.getContext("2d"); + + ctx.drawImage(video, 0, 0, width, height); + + const dataUrl = canvas.toDataURL("image/png"); + + setImage(dataUrl); + }; + + + return ( +
+

Face Detection

+
+ +
+
+ ) +} + +export default Object_Detection; \ No newline at end of file diff --git a/website/src/Object_Detection.module.css b/website/src/Object_Detection.module.css new file mode 100644 index 0000000..36f0fcc --- /dev/null +++ b/website/src/Object_Detection.module.css @@ -0,0 +1,11 @@ +#container { + margin: 0px auto; + width: 520px; + height: 395px; + border: 10px #333 solid; +} +#videoElement { + width: 500px; + height: 375px; + background-color: #666; +} \ No newline at end of file