srivatsavdamaraju commited on
Commit
cb2d9db
1 Parent(s): d31f188

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +74 -0
templates/index.html ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Live Depth Map</title>
7
+ <style>
8
+ #outputImage {
9
+ width: 640px;
10
+ height: 480px;
11
+ }
12
+ video {
13
+ width: 640px;
14
+ height: 480px;
15
+ display: block;
16
+ margin-bottom: 20px;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <h1>Live Depth Map</h1>
22
+ <video id="videoElement" autoplay playsinline></video>
23
+ <canvas id="canvasElement" style="display: none;"></canvas>
24
+ <img id="outputImage" alt="Processed Depth Map" />
25
+ <script>
26
+ async function startVideo() {
27
+ const video = document.getElementById('videoElement');
28
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true });
29
+ video.srcObject = stream;
30
+
31
+ video.addEventListener('play', async () => {
32
+ const canvas = document.getElementById('canvasElement');
33
+ const context = canvas.getContext('2d');
34
+ const outputImage = document.getElementById('outputImage');
35
+
36
+ canvas.width = video.videoWidth;
37
+ canvas.height = video.videoHeight;
38
+
39
+ async function processFrame() {
40
+ // Draw the current video frame on the canvas
41
+ context.drawImage(video, 0, 0, canvas.width, canvas.height);
42
+
43
+ // Convert canvas image to base64 format
44
+ const frameData = canvas.toDataURL('image/jpeg');
45
+
46
+ // Send the base64 data to Flask backend for processing
47
+ const response = await fetch('/process_frame', {
48
+ method: 'POST',
49
+ headers: {
50
+ 'Content-Type': 'application/json'
51
+ },
52
+ body: JSON.stringify({ image: frameData })
53
+ });
54
+
55
+ const result = await response.json();
56
+ const depthMapUrl = result.depth_map;
57
+
58
+ // Update the displayed image with the processed depth map
59
+ outputImage.src = depthMapUrl;
60
+
61
+ // Continue processing the next frame
62
+ requestAnimationFrame(processFrame);
63
+ }
64
+
65
+ // Start the frame processing loop
66
+ processFrame();
67
+ });
68
+ }
69
+
70
+ // Start capturing video once the page is loaded
71
+ window.onload = startVideo;
72
+ </script>
73
+ </body>
74
+ </html>