Spaces:
Sleeping
Sleeping
HuggingFace-SK
commited on
Commit
·
924f8d8
1
Parent(s):
11a985c
add update res slider
Browse files- static/index.js +24 -2
- templates/index.html +3 -0
static/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
var video_facing_mode = "user"
|
|
|
|
|
|
|
| 2 |
var video = document.getElementById("webcam")
|
| 3 |
var outputImage=document.getElementById("output_image")
|
| 4 |
const canvasElement = document.getElementById("middleware_canvas");
|
|
@@ -38,8 +40,8 @@ function load_camera() {
|
|
| 38 |
const constraints = {
|
| 39 |
video: {
|
| 40 |
facingMode: video_facing_mode,
|
| 41 |
-
width: { ideal:
|
| 42 |
-
height: { ideal:
|
| 43 |
}
|
| 44 |
};
|
| 45 |
// Activate the webcam stream.
|
|
@@ -107,5 +109,25 @@ document.body.appendChild(span);
|
|
| 107 |
console.error('Error:', error);
|
| 108 |
});
|
| 109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
|
|
|
| 1 |
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");
|
|
|
|
| 40 |
const constraints = {
|
| 41 |
video: {
|
| 42 |
facingMode: video_facing_mode,
|
| 43 |
+
width: { ideal: res_w },
|
| 44 |
+
height: { ideal: res_h }
|
| 45 |
}
|
| 46 |
};
|
| 47 |
// Activate the webcam stream.
|
|
|
|
| 109 |
console.error('Error:', error);
|
| 110 |
});
|
| 111 |
}
|
| 112 |
+
function updateResolution() {
|
| 113 |
+
const value = this.value;
|
| 114 |
+
const resolutionK = value / 1000;
|
| 115 |
+
const aspectRatio = 16 / 9;
|
| 116 |
+
let width, height;
|
| 117 |
|
| 118 |
+
if (resolutionK > 0) {
|
| 119 |
+
width = resolutionK * 1000;
|
| 120 |
+
height = Math.round(width / aspectRatio);
|
| 121 |
+
} else {
|
| 122 |
+
width = 0;
|
| 123 |
+
height = 0;
|
| 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 |
+
}
|
| 131 |
+
|
| 132 |
+
document.getElementById('resolution').addEventListener('input', updateResolution);
|
| 133 |
|
templates/index.html
CHANGED
|
@@ -14,5 +14,8 @@
|
|
| 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 |
</body>
|
| 18 |
</html>
|
|
|
|
| 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>
|