HuggingFace-SK commited on
Commit
5dc78f1
·
1 Parent(s): 1be30b3

update gui

Browse files
Files changed (3) hide show
  1. static/index.js +10 -7
  2. static/style.css +73 -6
  3. templates/index.html +28 -8
static/index.js CHANGED
@@ -2,8 +2,7 @@ var video_facing_mode = "user"
2
  var res_h = 1200
3
  var res_w = 720
4
  var video = document.getElementById("webcam")
5
- var outputImage=document.getElementById("output_image")
6
- const canvasElement = document.getElementById("middleware_canvas");
7
  const canvasCtx = canvasElement.getContext("2d");
8
  var webcamRunning
9
  var pic_taken=false
@@ -15,12 +14,20 @@ const hasGetUserMedia = () => { var _a; return !!((_a = navigator.mediaDevices)
15
  // wants to activate it.
16
  if (hasGetUserMedia()) {
17
  document.getElementById("switch-camera").addEventListener("click", switch_camera);
 
18
  document.getElementById("take-pic").addEventListener("click", take_pic);
19
  clear_pic_btn.addEventListener("click", clear_pic);
20
  }
21
  else {
22
  console.warn("getUserMedia() is not supported by your browser");
23
  }
 
 
 
 
 
 
 
24
  async function switch_camera() {
25
  if (video_facing_mode == 'user') {
26
  webcamRunning = false
@@ -58,8 +65,6 @@ function img_load(){
58
 
59
  canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
60
  canvasCtx.drawImage(video, 0, 0, canvasElement.width, (video.videoHeight / video.videoWidth) * canvasElement.width)
61
- var image = canvasElement.toDataURL()
62
- outputImage.src= image
63
  if(pic_taken != true){
64
  setTimeout(function (){img_load()}, 10);
65
  }
@@ -69,8 +74,6 @@ function take_pic(){
69
  canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
70
  canvasCtx.drawImage(video, 0, 0, canvasElement.width, (video.videoHeight / video.videoWidth) * canvasElement.width)
71
  var image = canvasElement.toDataURL()
72
-
73
- outputImage.src= image
74
  console.log(image)
75
  send_frame(image);
76
  clear_pic_btn.style.display="inline"
@@ -124,7 +127,7 @@ function updateResolution() {
124
  }
125
 
126
  // Update the displayed resolution
127
- document.getElementById('currentResolution').innerText = `${width} x ${height} (${resolutionK}K)`;
128
  res_w=width
129
  res_h=height
130
  }
 
2
  var res_h = 1200
3
  var res_w = 720
4
  var video = document.getElementById("webcam")
5
+ const canvasElement = document.getElementById("output_canvas");
 
6
  const canvasCtx = canvasElement.getContext("2d");
7
  var webcamRunning
8
  var pic_taken=false
 
14
  // wants to activate it.
15
  if (hasGetUserMedia()) {
16
  document.getElementById("switch-camera").addEventListener("click", switch_camera);
17
+ document.getElementById("webcamButton").addEventListener("click", enable_camera);
18
  document.getElementById("take-pic").addEventListener("click", take_pic);
19
  clear_pic_btn.addEventListener("click", clear_pic);
20
  }
21
  else {
22
  console.warn("getUserMedia() is not supported by your browser");
23
  }
24
+ function enable_camera(){
25
+ video_facing_mode = 'environment'
26
+ load_camera()
27
+ webcamRunning = true
28
+ document.getElementById("webcamButton").style.display="none";
29
+ document.getElementById("switch-camera").style.display="block";
30
+ }
31
  async function switch_camera() {
32
  if (video_facing_mode == 'user') {
33
  webcamRunning = false
 
65
 
66
  canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
67
  canvasCtx.drawImage(video, 0, 0, canvasElement.width, (video.videoHeight / video.videoWidth) * canvasElement.width)
 
 
68
  if(pic_taken != true){
69
  setTimeout(function (){img_load()}, 10);
70
  }
 
74
  canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
75
  canvasCtx.drawImage(video, 0, 0, canvasElement.width, (video.videoHeight / video.videoWidth) * canvasElement.width)
76
  var image = canvasElement.toDataURL()
 
 
77
  console.log(image)
78
  send_frame(image);
79
  clear_pic_btn.style.display="inline"
 
127
  }
128
 
129
  // Update the displayed resolution
130
+ document.getElementById('currentResolution').innerText = `${resolutionK}K`;
131
  res_w=width
132
  res_h=height
133
  }
static/style.css CHANGED
@@ -1,10 +1,77 @@
1
- *{
 
 
2
  box-sizing: border-box;
3
  }
4
- img{
5
- text-align: center;
6
- width:100%;
7
- margin:2px;
8
- height:auto;
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
 
1
+
2
+
3
+ * {
4
  box-sizing: border-box;
5
  }
 
 
 
 
 
6
 
7
+ body {
8
+ font-family: roboto;
9
+ color: #3d3d3d;
10
+ --mdc-theme-primary: #007f8b;
11
+ --mdc-theme-on-primary: #f1f3f4;
12
+ margin-left: 8px;
13
+ }
14
+
15
+ .container {
16
+ position: relative;
17
+ }
18
+
19
+ .canvas_wrapper{
20
+ position: relative;
21
+ text-align: left;
22
+ height:290px;
23
+ background-color: #F3F3F3;
24
+ box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38);
25
+ margin:10px;
26
+ margin-bottom: 20px;
27
+
28
+ border-radius: 15px;
29
+ overflow: hidden;
30
+ }
31
+ #output_canvas{
32
+ display:block; position:absolute;
33
+ left:50%;
34
+ transform: translateX(-50%);
35
+ width:auto;
36
+ height:100%
37
+ }
38
+ #webcamButton{
39
+ margin: 0;
40
+ position: absolute;
41
+ top: 50%;
42
+ left: 50%;
43
+ -ms-transform: translate(-50%, -50%);
44
+ transform: translate(-50%, -50%);
45
+ padding:10px;
46
+ border:none;
47
+ border-radius: 12.25px;
48
+ background-color: #f2f2f2;
49
+ box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38);
50
+ }
51
+
52
+ .btn{
53
+ margin: 0;
54
+ position: relative;
55
+ padding:10px;
56
+ border:none;
57
+ border-radius: 12.25px;
58
+ background-color: #f2f2f2;
59
+ box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38);
60
+ font-weight: 600;
61
+ color:black;
62
+
63
+ }
64
+
65
+ .sld{
66
+ margin: 0;
67
+ position: relative;
68
+ display:block;
69
+ margin-top: 20px;
70
+ padding:10px;
71
+ border:none;
72
+ border-radius: 12.25px;
73
+ background-color: #f2f2f2;
74
+ box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38);
75
+ font-weight: 600;
76
+ color:black;
77
  }
templates/index.html CHANGED
@@ -8,14 +8,34 @@
8
  <script type="module" src="static/index.js"></script>
9
  </head>
10
  <body>
11
- <video id="webcam" style="display:none" autoplay="" playsinline=""></video>
12
- <canvas id="middleware_canvas" style="display:none"></canvas>
13
- <img id="output_image"></img>
14
- <button id="switch-camera">switch_cam</button>
15
- <button id="take-pic">take_pic</button>
16
- <button id="clear-pic" style="display:none">clear_pic</button>
17
- <input type="range" id="resolution" min="0" max="4000" step="100" value="0">
18
- <p>Current Resolution: <span id="currentResolution">0 x 0 (0K)</span></p>
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  </body>
21
  </html>
 
8
  <script type="module" src="static/index.js"></script>
9
  </head>
10
  <body>
 
 
 
 
 
 
 
 
11
 
12
+
13
+ <div class="container">
14
+
15
+ <video id="webcam" style="display:none" autoplay="" playsinline=""></video>
16
+ <div class="canvas_wrapper" id="canvas_wrapper">
17
+ <button id="switch-camera" style="display:none; position: absolute; top:10px; left:10px; padding:5px; height:40px; width:40px; text-align: center; border-radius: 12.25px; font-size: 20px; font-weight: 900; border:none; background-color: #f2f2f2; color:black;
18
+ box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38); z-index:100">
19
+ <span>⟳</span>
20
+ </button>
21
+ <center>
22
+ <canvas class="output_canvas" id="output_canvas"></canvas>
23
+ </center>
24
+ <center>
25
+ <button id="webcamButton" style="font-weight: 600; color:black;">
26
+ <span>Enable Webcam</span>
27
+ </button>
28
+ </center>
29
+ </div>
30
+ </div>
31
+ <center>
32
+ <button class="btn" id="take-pic">Take Picture</button>
33
+ <button class="btn" id="clear-pic" style="display:none">Clear Picture</button>
34
+ <span class="sld">
35
+ <input type="range" id="resolution" min="0" max="4000" step="100" value="0">
36
+ <span style="display:block"id="currentResolution"></span>
37
+ </span>
38
+
39
+ </center>
40
  </body>
41
  </html>