Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +1 -136
index.html
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
<html>
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
|
@@ -180,141 +180,6 @@
|
|
| 180 |
</script>
|
| 181 |
</body>
|
| 182 |
</html>
|
| 183 |
-
-->
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
<!DOCTYPE html>
|
| 189 |
-
<html>
|
| 190 |
-
<head>
|
| 191 |
-
<meta charset="utf-8">
|
| 192 |
-
<title>GrechnikNet — YOLOv8n Detection</title>
|
| 193 |
-
<style>
|
| 194 |
-
body { background:#111; color:#eee; font-family:sans-serif; text-align:center; }
|
| 195 |
-
.controls { margin:16px; display:flex; flex-wrap:wrap; gap:16px; justify-content:center; }
|
| 196 |
-
.control { background:#1b1b1b; padding:10px; border-radius:8px; }
|
| 197 |
-
label { display:block; margin-bottom:6px; }
|
| 198 |
-
input[type="range"] { width:200px; }
|
| 199 |
-
button { padding:8px 14px; border:none; border-radius:6px; background:#3a6df0; color:#fff; cursor:pointer; }
|
| 200 |
-
button:disabled { background:#555; cursor:not-allowed; }
|
| 201 |
-
canvas { border:1px solid #333; border-radius:8px; margin-top:12px; }
|
| 202 |
-
pre { text-align:left; background:#0e0e0e; padding:12px; border-radius:8px; }
|
| 203 |
-
</style>
|
| 204 |
-
</head>
|
| 205 |
-
<body>
|
| 206 |
-
<h2>GrechnikNet — Impurity Detection</h2>
|
| 207 |
-
<p>Наведи камеру телефона на гречку и получи боксы</p>
|
| 208 |
-
|
| 209 |
-
<div class="controls">
|
| 210 |
-
<div class="control">
|
| 211 |
-
<label>Камера:</label>
|
| 212 |
-
<select id="cameraSelect"></select>
|
| 213 |
-
</div>
|
| 214 |
-
<div class="control">
|
| 215 |
-
<label>Confidence: <span id="confVal">0.25</span></label>
|
| 216 |
-
<input type="range" id="confSlider" min="0" max="1" step="0.05" value="0.25">
|
| 217 |
-
</div>
|
| 218 |
-
<div class="control">
|
| 219 |
-
<label>IoU: <span id="iouVal">0.45</span></label>
|
| 220 |
-
<input type="range" id="iouSlider" min="0" max="1" step="0.05" value="0.45">
|
| 221 |
-
</div>
|
| 222 |
-
<div class="control">
|
| 223 |
-
<label>Режим:</label>
|
| 224 |
-
<select id="modeSelect">
|
| 225 |
-
<option value="image">Аннотированное изображение</option>
|
| 226 |
-
<option value="json">JSON боксы</option>
|
| 227 |
-
</select>
|
| 228 |
-
</div>
|
| 229 |
-
<div class="control">
|
| 230 |
-
<button id="startBtn">Старт</button>
|
| 231 |
-
<button id="stopBtn" disabled>Стоп</button>
|
| 232 |
-
</div>
|
| 233 |
-
</div>
|
| 234 |
|
| 235 |
-
<video id="video" playsinline autoplay muted style="display:none;"></video>
|
| 236 |
-
<canvas id="resultCanvas" width="480" height="480"></canvas>
|
| 237 |
-
<pre id="jsonOut" style="display:none;"></pre>
|
| 238 |
|
| 239 |
-
<script>
|
| 240 |
-
const video = document.getElementById('video');
|
| 241 |
-
const resultCanvas = document.getElementById('resultCanvas');
|
| 242 |
-
const ctxResult = resultCanvas.getContext('2d');
|
| 243 |
-
const jsonOut = document.getElementById('jsonOut');
|
| 244 |
-
const startBtn = document.getElementById('startBtn');
|
| 245 |
-
const stopBtn = document.getElementById('stopBtn');
|
| 246 |
-
const cameraSelect = document.getElementById('cameraSelect');
|
| 247 |
-
const confSlider = document.getElementById('confSlider');
|
| 248 |
-
const iouSlider = document.getElementById('iouSlider');
|
| 249 |
-
const confVal = document.getElementById('confVal');
|
| 250 |
-
const iouVal = document.getElementById('iouVal');
|
| 251 |
-
const modeSelect = document.getElementById('modeSelect');
|
| 252 |
-
|
| 253 |
-
let stream = null;
|
| 254 |
-
let active = false;
|
| 255 |
-
let running = false;
|
| 256 |
-
let currentDeviceId = null;
|
| 257 |
-
let frameCounter = 0;
|
| 258 |
-
|
| 259 |
-
confSlider.oninput = () => confVal.textContent = confSlider.value;
|
| 260 |
-
iouSlider.oninput = () => iouVal.textContent = iouSlider.value;
|
| 261 |
-
|
| 262 |
-
async function enumerateCameras() {
|
| 263 |
-
const devices = await navigator.mediaDevices.enumerateDevices();
|
| 264 |
-
cameraSelect.innerHTML = '';
|
| 265 |
-
const cams = devices.filter(d => d.kind === 'videoinput');
|
| 266 |
-
cams.forEach((cam, i) => {
|
| 267 |
-
const opt = document.createElement('option');
|
| 268 |
-
opt.value = cam.deviceId || i;
|
| 269 |
-
opt.textContent = cam.label || `Камера ${i+1}`;
|
| 270 |
-
cameraSelect.appendChild(opt);
|
| 271 |
-
});
|
| 272 |
-
if (cams.length > 0) currentDeviceId = cams[0].deviceId;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
async function startCamera(deviceId) {
|
| 276 |
-
if (stream) stopCamera();
|
| 277 |
-
const constraints = {
|
| 278 |
-
video: {
|
| 279 |
-
deviceId: deviceId ? { exact: deviceId } : undefined,
|
| 280 |
-
facingMode: 'environment',
|
| 281 |
-
width: { ideal: 480 },
|
| 282 |
-
height: { ideal: 480 }
|
| 283 |
-
},
|
| 284 |
-
audio: false
|
| 285 |
-
};
|
| 286 |
-
stream = await navigator.mediaDevices.getUserMedia(constraints);
|
| 287 |
-
video.srcObject = stream;
|
| 288 |
-
await video.play();
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
function stopCamera() {
|
| 292 |
-
if (stream) {
|
| 293 |
-
stream.getTracks().forEach(t => t.stop());
|
| 294 |
-
stream = null;
|
| 295 |
-
}
|
| 296 |
-
}
|
| 297 |
-
|
| 298 |
-
cameraSelect.onchange = async () => {
|
| 299 |
-
currentDeviceId = cameraSelect.value;
|
| 300 |
-
await startCamera(currentDeviceId);
|
| 301 |
-
};
|
| 302 |
-
|
| 303 |
-
async function captureAndSendFrame() {
|
| 304 |
-
if (!stream || running || !active) return;
|
| 305 |
-
frameCounter++;
|
| 306 |
-
if (frameCounter % 2 !== 0) { // обрабатываем только каждый 2-й кадр
|
| 307 |
-
requestAnimationFrame(captureAndSendFrame);
|
| 308 |
-
return;
|
| 309 |
-
}
|
| 310 |
-
running = true;
|
| 311 |
-
|
| 312 |
-
const canvas = document.createElement('canvas');
|
| 313 |
-
const w = 480;
|
| 314 |
-
const h = Math.floor(w * (video.videoHeight / video.videoWidth));
|
| 315 |
-
canvas.width = w;
|
| 316 |
-
canvas.height = h;
|
| 317 |
-
const ctx = canvas.getContext('2d');
|
| 318 |
-
ctx.drawImage(video, 0, 0, w, h);
|
| 319 |
|
| 320 |
-
const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
|
|
|
| 180 |
</script>
|
| 181 |
</body>
|
| 182 |
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
|
|
|
|
|
|
|
|
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
|
|