Paradise151 commited on
Commit
a449ecd
·
verified ·
1 Parent(s): 717ce86

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +64 -0
index.html ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>GrechnikNet — Test</title>
6
+ <style>
7
+ body { background:#111; color:#eee; font-family:sans-serif; text-align:center; }
8
+ video, img { width: 480px; border:1px solid #333; border-radius:8px; margin:10px; }
9
+ button { padding:10px 16px; border:none; border-radius:6px; background:#3a6df0; color:#fff; cursor:pointer; }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <h2>GrechnikNet — Test API</h2>
14
+ <p>Нажми кнопку, чтобы сделать кадр и отправить на сервер</p>
15
+
16
+ <video id="video" autoplay playsinline></video><br>
17
+ <button id="snapBtn">Сделать кадр</button><br>
18
+ <img id="resultImg" alt="Результат появится здесь">
19
+
20
+ <script>
21
+ const video = document.getElementById('video');
22
+ const snapBtn = document.getElementById('snapBtn');
23
+ const resultImg = document.getElementById('resultImg');
24
+
25
+ // Запрашиваем доступ к камере
26
+ navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment', width: 480 }, audio: false })
27
+ .then(stream => { video.srcObject = stream; })
28
+ .catch(err => { alert("Ошибка доступа к камере: " + err); });
29
+
30
+ snapBtn.onclick = async () => {
31
+ // Снимаем кадр в canvas
32
+ const canvas = document.createElement('canvas');
33
+ canvas.width = video.videoWidth;
34
+ canvas.height = video.videoHeight;
35
+ const ctx = canvas.getContext('2d');
36
+ ctx.drawImage(video, 0, 0);
37
+
38
+ // Конвертим в Blob
39
+ const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.85));
40
+
41
+ // Отправляем на сервер
42
+ const formData = new FormData();
43
+ formData.append('file', blob, 'frame.jpg');
44
+ formData.append('conf', '0.25');
45
+ formData.append('iou', '0.45');
46
+ formData.append('return_image', '1');
47
+
48
+ try {
49
+ const resp = await fetch('/predict', { method: 'POST', body: formData });
50
+ if (!resp.ok) {
51
+ const text = await resp.text();
52
+ alert("Ошибка сервера: " + text);
53
+ return;
54
+ }
55
+ const arrBuf = await resp.arrayBuffer();
56
+ const blobRes = new Blob([arrBuf], { type: 'image/jpeg' });
57
+ resultImg.src = URL.createObjectURL(blobRes);
58
+ } catch (e) {
59
+ alert("Ошибка запроса: " + e);
60
+ }
61
+ };
62
+ </script>
63
+ </body>
64
+ </html>