srivatsavdamaraju commited on
Commit
01985bb
·
verified ·
1 Parent(s): 184bff0

Update templates/depthmap.html

Browse files
Files changed (1) hide show
  1. 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
- const canvas = document.createElement('canvas');
24
- canvas.width = 640;
25
- canvas.height = 480;
26
- const ctx = canvas.getContext('2d');
27
- ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
28
- canvas.toBlob(blob => {
29
- const formData = new FormData();
30
- formData.append('frame', blob, 'frame.jpg');
 
 
 
31
 
32
- // Send the frame to the Flask server
33
- fetch('/video_feed', {
34
- method: 'POST',
35
- body: formData
36
- })
37
- .then(response => response.blob())
38
- .then(imageBlob => {
39
- output.src = URL.createObjectURL(imageBlob);
40
- });
41
- }, 'image/jpeg', 0.95);
42
- }, 100); // Send every 100ms
 
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);