srivatsavdamaraju commited on
Commit
4025aa8
1 Parent(s): 79632d8

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +62 -0
templates/index.html ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Webcam Streaming with Flask-SocketIO</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.1.3/socket.io.min.js"></script>
8
+ <style>
9
+ body {
10
+ text-align: center;
11
+ font-family: Arial, sans-serif;
12
+ }
13
+
14
+ img {
15
+ width: 80%;
16
+ max-width: 640px;
17
+ height: auto;
18
+ }
19
+
20
+ #videoCanvas {
21
+ width: 100%;
22
+ max-width: 640px;
23
+ border: 1px solid #ccc;
24
+ }
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <h1>Live Webcam Feed</h1>
29
+ <canvas id="videoCanvas"></canvas>
30
+ <script>
31
+ var socket = io.connect('http://127.0.0.1:5000'); // Connect to the Flask server
32
+
33
+ // When the connection is established, log a message
34
+ socket.on('connect', function() {
35
+ console.log("Connected to server!");
36
+ });
37
+
38
+ // When the server sends a video frame
39
+ socket.on('display_frame', function(data) {
40
+ console.log("Received video frame from server");
41
+
42
+ // Check if the data contains the 'image' field
43
+ if (data && data.image) {
44
+ var image = new Image();
45
+ image.src = 'data:image/jpeg;base64,' + data.image;
46
+ image.onload = function() {
47
+ var canvas = document.getElementById('videoCanvas');
48
+ var context = canvas.getContext('2d');
49
+ context.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas before drawing the new frame
50
+ context.drawImage(image, 0, 0, canvas.width, canvas.height); // Draw the frame on the canvas
51
+ };
52
+ } else {
53
+ console.error("Invalid frame data received:", data);
54
+ }
55
+ });
56
+
57
+ socket.on('disconnect', function() {
58
+ console.log("Disconnected from server");
59
+ });
60
+ </script>
61
+ </body>
62
+ </html>