Create templates/index.html
Browse files- templates/index.html +51 -0
templates/index.html
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>YOLOv8 Object Detection</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<h1>Webcam Object Detection with YOLOv8</h1>
|
| 8 |
+
<video id="video" width="640" height="480" autoplay></video>
|
| 9 |
+
<canvas id="canvas" style="display:none;"></canvas>
|
| 10 |
+
<br>
|
| 11 |
+
<img id="output" width="640" height="480" />
|
| 12 |
+
|
| 13 |
+
<script>
|
| 14 |
+
const video = document.getElementById('video');
|
| 15 |
+
const canvas = document.getElementById('canvas');
|
| 16 |
+
const ctx = canvas.getContext('2d');
|
| 17 |
+
const output = document.getElementById('output');
|
| 18 |
+
|
| 19 |
+
// Start webcam
|
| 20 |
+
navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
|
| 21 |
+
video.srcObject = stream;
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
// Send a frame every second to backend (flipped)
|
| 25 |
+
setInterval(() => {
|
| 26 |
+
canvas.width = video.videoWidth;
|
| 27 |
+
canvas.height = video.videoHeight;
|
| 28 |
+
|
| 29 |
+
// Flip the canvas horizontally
|
| 30 |
+
ctx.save();
|
| 31 |
+
ctx.scale(-1, 1);
|
| 32 |
+
ctx.drawImage(video, -canvas.width, 0, canvas.width, canvas.height);
|
| 33 |
+
ctx.restore();
|
| 34 |
+
|
| 35 |
+
const dataURL = canvas.toDataURL('image/jpeg');
|
| 36 |
+
|
| 37 |
+
fetch('/upload_frame', {
|
| 38 |
+
method: 'POST',
|
| 39 |
+
headers: { 'Content-Type': 'application/json' },
|
| 40 |
+
body: JSON.stringify({ image: dataURL })
|
| 41 |
+
})
|
| 42 |
+
.then(response => response.json())
|
| 43 |
+
.then(data => {
|
| 44 |
+
if (data.image) {
|
| 45 |
+
output.src = data.image;
|
| 46 |
+
}
|
| 47 |
+
});
|
| 48 |
+
}, 1000);
|
| 49 |
+
</script>
|
| 50 |
+
</body>
|
| 51 |
+
</html>
|