Spaces:
Running
Running
srivatsavdamaraju
commited on
Update templates/depthmap.html
Browse files- templates/depthmap.html +24 -20
templates/depthmap.html
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
<!-- templates/index.html -->
|
2 |
<!DOCTYPE html>
|
3 |
<html lang="en">
|
4 |
<head>
|
@@ -13,6 +12,7 @@
|
|
13 |
<script>
|
14 |
const video = document.getElementById('video');
|
15 |
const output = document.getElementById('output');
|
|
|
16 |
|
17 |
// Access the webcam
|
18 |
navigator.mediaDevices.getUserMedia({ video: true })
|
@@ -20,26 +20,30 @@
|
|
20 |
video.srcObject = stream;
|
21 |
|
22 |
setInterval(() => {
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
const
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
})
|
44 |
.catch(error => {
|
45 |
console.error("Error accessing webcam: ", error);
|
|
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
|
|
12 |
<script>
|
13 |
const video = document.getElementById('video');
|
14 |
const output = document.getElementById('output');
|
15 |
+
let frameCount = 0;
|
16 |
|
17 |
// Access the webcam
|
18 |
navigator.mediaDevices.getUserMedia({ video: true })
|
|
|
20 |
video.srcObject = stream;
|
21 |
|
22 |
setInterval(() => {
|
23 |
+
frameCount++;
|
24 |
+
// Only process every 3rd frame
|
25 |
+
if (frameCount % 3 === 0) {
|
26 |
+
const canvas = document.createElement('canvas');
|
27 |
+
canvas.width = 640;
|
28 |
+
canvas.height = 480;
|
29 |
+
const ctx = canvas.getContext('2d');
|
30 |
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
31 |
+
canvas.toBlob(blob => {
|
32 |
+
const formData = new FormData();
|
33 |
+
formData.append('frame', blob, 'frame.jpg');
|
34 |
|
35 |
+
// Send the frame to the Flask server
|
36 |
+
fetch('/video_feed', {
|
37 |
+
method: 'POST',
|
38 |
+
body: formData
|
39 |
+
})
|
40 |
+
.then(response => response.blob())
|
41 |
+
.then(imageBlob => {
|
42 |
+
output.src = URL.createObjectURL(imageBlob);
|
43 |
+
});
|
44 |
+
}, 'image/jpeg', 0.95);
|
45 |
+
}
|
46 |
+
}, 100); // Adjust interval as needed
|
47 |
})
|
48 |
.catch(error => {
|
49 |
console.error("Error accessing webcam: ", error);
|