Create index.html
Browse files- index.html +47 -0
index.html
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Camera Input</title>
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<h1>Camera Input</h1>
|
| 10 |
+
<video id="video" width="640" height="480" autoplay></video>
|
| 11 |
+
<button id="captureButton">Capture Frame</button>
|
| 12 |
+
<script>
|
| 13 |
+
async function setupCamera() {
|
| 14 |
+
const video = document.getElementById('video');
|
| 15 |
+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 16 |
+
video.srcObject = stream;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
function captureFrame() {
|
| 20 |
+
const video = document.getElementById('video');
|
| 21 |
+
const canvas = document.createElement('canvas');
|
| 22 |
+
canvas.width = video.videoWidth;
|
| 23 |
+
canvas.height = video.videoHeight;
|
| 24 |
+
const context = canvas.getContext('2d');
|
| 25 |
+
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 26 |
+
const frame = canvas.toDataURL('image/jpeg');
|
| 27 |
+
sendFrameToBackend(frame);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
function sendFrameToBackend(frame) {
|
| 31 |
+
fetch('/process_frame', {
|
| 32 |
+
method: 'POST',
|
| 33 |
+
headers: {
|
| 34 |
+
'Content-Type': 'application/json'
|
| 35 |
+
},
|
| 36 |
+
body: JSON.stringify({ frame })
|
| 37 |
+
})
|
| 38 |
+
.then(response => response.json())
|
| 39 |
+
.then(data => console.log(data))
|
| 40 |
+
.catch(error => console.error('Error:', error));
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
document.getElementById('captureButton').addEventListener('click', captureFrame);
|
| 44 |
+
setupCamera();
|
| 45 |
+
</script>
|
| 46 |
+
</body>
|
| 47 |
+
</html>
|