Emeritus-21 commited on
Commit
f0e23b6
·
verified ·
1 Parent(s): 4b603ae

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +20 -43
static/script.js CHANGED
@@ -1,50 +1,27 @@
1
- const itsekiri_labels = [
2
- 'Méene', 'Méji', 'Métà', 'Mérin', 'Márùn',
3
- 'Méfa', 'Méje', 'Méjọ', 'Méṣan', 'Méwà'
4
- ];
5
-
6
  const video = document.getElementById('video');
7
  const canvas = document.getElementById('canvas');
8
  const ctx = canvas.getContext('2d');
9
  const predictionText = document.getElementById('prediction');
10
- const fingersDisplay = document.getElementById('fingers');
11
- const enableWebcamBtn = document.getElementById('enable-webcam');
12
- let stream;
13
-
14
- enableWebcamBtn.addEventListener('click', () => {
15
- if (!stream) {
16
- navigator.mediaDevices.getUserMedia({ video: true })
17
- .then(s => {
18
- stream = s;
19
- video.srcObject = stream;
20
- enableWebcamBtn.style.display = 'none';
21
- startPrediction();
22
- })
23
- .catch(console.error);
24
- }
25
- });
26
-
27
- function startPrediction() {
28
- setInterval(() => {
29
- // Draw video frame to canvas
30
- ctx.drawImage(video, 0, 0, 640, 480);
31
 
32
- // Simulate finger detection (random for demo)
33
- const fingerCount = Math.floor(Math.random() * 5) + 1; // Random 1-5 fingers
34
- fingersDisplay.textContent = `Fingers Detected: ${fingerCount}`;
 
 
35
 
36
- // Mock prediction based on finger count
37
- predictionText.textContent = `Prediction: Sign ${fingerCount}`;
 
 
38
 
39
- // Optional: Draw circles for fingers (visualization)
40
- ctx.strokeStyle = '#ff4444';
41
- ctx.lineWidth = 2;
42
- for (let i = 0; i < fingerCount; i++) {
43
- const x = 100 + (i * 100);
44
- const y = 100 + Math.random() * 200;
45
- ctx.beginPath();
46
- ctx.arc(x, y, 20, 0, Math.PI * 2);
47
- ctx.stroke();
48
- }
49
- }, 500);
50
- }
 
 
 
 
 
 
1
  const video = document.getElementById('video');
2
  const canvas = document.getElementById('canvas');
3
  const ctx = canvas.getContext('2d');
4
  const predictionText = document.getElementById('prediction');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ navigator.mediaDevices.getUserMedia({ video: true })
7
+ .then(stream => {
8
+ video.srcObject = stream;
9
+ })
10
+ .catch(console.error);
11
 
12
+ setInterval(() => {
13
+ // Crop and resize the area with digit from webcam video (adjust coords if needed)
14
+ ctx.drawImage(video, 100, 100, 200, 200, 0, 0, 64, 64);
15
+ const dataUrl = canvas.toDataURL('image/jpeg');
16
 
17
+ fetch('/predict', {
18
+ method: 'POST',
19
+ headers: { 'Content-Type': 'application/json' },
20
+ body: JSON.stringify({ image: dataUrl })
21
+ })
22
+ .then(res => res.json())
23
+ .then(data => {
24
+ predictionText.textContent = data.prediction;
25
+ })
26
+ .catch(console.error);
27
+ }, 500);