depthmapflask / templates /depthmap.html
srivatsavdamaraju's picture
Create templates/depthmap.html
2328c21 verified
raw
history blame
1.82 kB
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webcam Stream</title>
</head>
<body>
<h1>Webcam Stream</h1>
<video id="video" width="640" height="480" autoplay></video>
<img id="output" src="" alt="Processed Frame" />
<script>
const video = document.getElementById('video');
const output = document.getElementById('output');
// Access the webcam
navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
video.srcObject = stream;
setInterval(() => {
const canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 480;
const ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.toBlob(blob => {
const formData = new FormData();
formData.append('frame', blob, 'frame.jpg');
// Send the frame to the Flask server
fetch('/video_feed', {
method: 'POST',
body: formData
})
.then(response => response.blob())
.then(imageBlob => {
output.src = URL.createObjectURL(imageBlob);
});
}, 'image/jpeg', 0.95);
}, 100); // Send every 100ms
})
.catch(error => {
console.error("Error accessing webcam: ", error);
});
</script>
</body>
</html>