codrizsain commited on
Commit
4648aa4
·
verified ·
1 Parent(s): f2cc729

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +190 -271
index.html CHANGED
@@ -3,316 +3,235 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>AI Vision - Custom WebRTC Camera</title>
7
 
 
8
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
9
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
10
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js" crossorigin="anonymous"></script>
11
 
12
  <style>
13
- body {
14
- background: radial-gradient(circle at top, #1e293b, #0f172a);
15
- color: #f8fafc;
16
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
17
- display: flex; flex-direction: column; align-items: center;
18
- margin: 0; padding: 20px; min-height: 100vh;
 
 
 
 
19
  }
20
-
21
  h2 { margin-bottom: 5px; color: #38bdf8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.5); }
22
  p { color: #94a3b8; margin-top: 0; text-align: center; }
23
-
24
- #startBtn {
25
- background: linear-gradient(135deg, #ec4899, #8b5cf6);
26
- color: white; border: none; padding: 15px 35px;
27
- font-size: 18px; border-radius: 50px; cursor: pointer;
28
- font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
29
- transition: all 0.3s ease; margin: 20px 0; text-transform: uppercase;
30
  }
31
- #startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }
32
-
33
- #statusContainer {
34
- background: rgba(15, 23, 42, 0.8); border: 1px solid #334155;
35
- padding: 15px 30px; border-radius: 12px; margin-bottom: 20px;
36
- min-width: 300px; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.3);
37
  }
38
- #statusPose { font-size: 24px; font-weight: bold; color: #94a3b8; transition: color 0.3s; }
39
-
40
  .monitor-container { position: relative; }
41
 
42
- canvas {
43
- border: 3px solid #3b82f6; box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
44
- border-radius: 16px; background-color: #000; width: 640px; height: 480px;
45
- max-width: 90vw; object-fit: cover; transform: scaleX(-1);
 
 
46
  }
47
-
48
- .pose1-anim {
49
  position: absolute; opacity: 0; border-radius: 8px; z-index: 10;
50
  border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
51
- pointer-events: none; transition: opacity 0.2s ease-in-out, left 0.1s linear, top 0.1s linear;
52
- transform: scaleX(-1);
53
  }
54
-
55
- #biometricContainer {
56
- position: absolute; top: 15px; right: 15px;
57
- background: rgba(15, 23, 42, 0.85); border: 2px solid #3b82f6;
58
- padding: 15px; border-radius: 12px; box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
59
- z-index: 20; backdrop-filter: blur(5px); transition: border-color 0.3s, box-shadow 0.3s; min-width: 150px;
60
  }
61
- .bio-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; margin-bottom: 2px;}
62
- .bio-label:first-child { margin-top: 0; }
63
- .bio-value { font-size: 18px; font-weight: bold; color: #f8fafc; }
64
- .divider { height: 1px; background-color: #334155; margin: 8px 0; }
65
  </style>
66
  </head>
67
- <body>
68
 
69
- <h2>🤖 AI Vision: Stable Camera Engine</h2>
70
- <p>Sistem WebRTC Manual By Rizki Ardiansyah</p>
71
-
72
- <button id="startBtn">▶ Mulai Sistem Deteksi</button>
73
-
74
- <div id="statusContainer">
75
- <div id="statusPose">Menunggu Kamera...</div>
76
- </div>
77
 
78
- <div class="monitor-container">
79
- <div id="biometricContainer">
80
- <div class="bio-label">Kondisi Mood</div>
81
- <div id="moodValue" class="bio-value">Menganalisis...</div>
82
- <div class="divider"></div>
83
- <div class="bio-label">Estimasi Anatomi</div>
84
- <div id="genderValue" class="bio-value" style="color: #cbd5e1;">Memindai...</div>
85
- </div>
86
-
87
- <video id="videoElement" style="display: none;" autoplay playsinline webkit-playsinline muted></video>
88
- <canvas id="outputCanvas" width="640" height="480"></canvas>
 
 
 
 
89
 
90
- <img id="pose1Anim1" class="pose1-anim" src="animasi1.gif" alt="Pose 1">
91
- <img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
92
- </div>
93
-
94
  <audio id="audio1" src="suara1.mp3"></audio>
95
  <audio id="audio2" src="suara2.mp3"></audio>
96
  <audio id="audio3" src="suara3.mp3"></audio>
97
  <audio id="audio4" src="suara4.mp3"></audio>
98
  <audio id="audio5" src="suara5.mp3"></audio>
99
-
100
- <script>
101
- const videoElement = document.getElementById('videoElement');
102
- const canvasElement = document.getElementById('outputCanvas');
103
- const canvasCtx = canvasElement.getContext('2d');
104
- const startBtn = document.getElementById('startBtn');
105
- const statusPose = document.getElementById('statusPose');
106
- const biometricContainer = document.getElementById('biometricContainer');
107
- const moodValue = document.getElementById('moodValue');
108
- const genderValue = document.getElementById('genderValue');
109
-
110
- const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
111
- const sounds = [
112
- document.getElementById('audio1'), document.getElementById('audio2'),
113
- document.getElementById('audio3'), document.getElementById('audio4'),
114
- document.getElementById('audio5')
115
- ];
116
-
117
  let memoryActivePoses = [];
118
  let memoryTimer = 0;
119
- let currentFaceLandmarks = null;
120
-
121
- function getDistance(p1, p2) {
122
- return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
123
- }
124
-
125
- function analyzeFaceBiometrics(faceLandmarks) {
126
- const leftMouth = faceLandmarks[61]; const rightMouth = faceLandmarks[291];
127
- const topLip = faceLandmarks[13]; const bottomLip = faceLandmarks[14];
128
- const leftEye = faceLandmarks[33]; const rightEye = faceLandmarks[263];
129
-
130
- const mouthWidth = getDistance(leftMouth, rightMouth);
131
- const mouthHeight = getDistance(topLip, bottomLip);
132
- const faceScale = getDistance(leftEye, rightEye);
133
- const smileRatio = mouthWidth / faceScale;
134
- const openRatio = mouthHeight / faceScale;
135
-
136
- let moodText = "Netral 😐"; let moodColor = "#3b82f6";
137
- if (openRatio > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
138
- else if (smileRatio > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
139
-
140
- const leftCheek = faceLandmarks[234]; const rightCheek = faceLandmarks[454];
141
- const leftJaw = faceLandmarks[132]; const rightJaw = faceLandmarks[361];
142
- const cheekWidth = getDistance(leftCheek, rightCheek);
143
- const jawWidth = getDistance(leftJaw, rightJaw);
144
- const jawToCheekRatio = jawWidth / cheekWidth;
145
-
146
- let angkaRasio = jawToCheekRatio.toFixed(3);
147
- let genderText = ""; let genderColor = "";
148
 
149
- if (jawToCheekRatio > 0.820) {
150
- genderText = `Pria 👨 (${angkaRasio})`; genderColor = "#60a5fa";
151
- } else {
152
- genderText = `Wanita 👩 (${angkaRasio})`; genderColor = "#f472b6";
153
- }
 
 
 
 
154
 
155
- return { moodText, moodColor, genderText, genderColor };
156
- }
157
-
158
- function classifyPose(landmarks) {
159
- const indexOpen = landmarks[8].y < landmarks[6].y;
160
- const middleOpen = landmarks[12].y < landmarks[10].y;
161
- const ringOpen = landmarks[16].y < landmarks[14].y;
162
- const pinkyOpen = landmarks[20].y < landmarks[18].y;
 
 
 
 
 
 
163
  const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
164
-
165
- if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
166
- if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak", color: "#3b82f6" };
167
- if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
168
- if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
169
-
170
- if (getDistance(landmarks[4], landmarks[8]) < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "👌 Okay", color: "#10b981" };
171
- return null;
172
- }
173
-
174
- // SETUP AI WAJAH
175
- const faceMesh = new FaceMesh({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`; }});
176
- faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
177
- faceMesh.onResults((results) => {
178
- currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null;
179
- });
180
-
181
- // SETUP AI TANGAN
182
- const hands = new Hands({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; }});
183
- hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
184
- hands.onResults((results) => {
185
- canvasCtx.save();
186
- canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
187
- canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
188
-
189
- if (currentFaceLandmarks) {
190
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
191
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
192
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYEBROW, {color: '#ec4899', lineWidth: 2});
193
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
194
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYEBROW, {color: '#ec4899', lineWidth: 2});
195
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_FACE_OVAL, {color: '#ec4899', lineWidth: 2});
196
- drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
197
- }
198
-
199
- let detectedPosesThisFrame = [];
200
- anims.forEach(a => a.style.opacity = '0');
201
-
202
- if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
203
- results.multiHandLandmarks.forEach((landmarks, index) => {
204
- let boneColor = index === 0 ? '#ec4899' : '#06b6d4';
205
- drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: boneColor, lineWidth: 4});
206
- drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
207
-
208
- let pose = classifyPose(landmarks);
209
- if (pose) detectedPosesThisFrame.push({ ...pose, handIndex: index, wrist: landmarks[0] });
210
- });
211
- }
212
- canvasCtx.restore();
213
-
214
- // UPDATE UI & LOGIKA
215
- if (currentFaceLandmarks) {
216
- let bio = analyzeFaceBiometrics(currentFaceLandmarks);
217
- let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
218
-
219
- if (bio.moodText === "Senang 😊" && isPositivePose) {
220
- bio.moodText = "Sangat Senang! ✨"; bio.moodColor = "#eab308";
221
- }
222
- moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
223
- genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
224
- biometricContainer.style.borderColor = bio.moodColor;
225
- biometricContainer.style.boxShadow = `0 0 15px ${bio.moodColor}80`;
226
- } else {
227
- moodValue.textContent = "Wajah Hilang"; moodValue.style.color = "#94a3b8";
228
- genderValue.textContent = "Wajah Hilang"; genderValue.style.color = "#94a3b8";
229
- biometricContainer.style.borderColor = "#334155";
230
- }
231
-
232
- // AUDIO & GIF
233
- let currentIds = detectedPosesThisFrame.map(p => p.id);
234
- if (currentIds.length > 0) {
235
- let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
236
- statusPose.textContent = uniquePoseNames.join(" & ");
237
- statusPose.style.color = detectedPosesThisFrame[0].color;
238
-
239
- detectedPosesThisFrame.forEach((pose, i) => {
240
- if (pose.id === 1 && anims[i]) {
241
- const leftPos = ((1 - pose.wrist.x) * canvasElement.width) - 75;
242
- const topPos = (pose.wrist.y * canvasElement.height) + 30;
243
- anims[i].style.opacity = '1';
244
- anims[i].style.left = `${leftPos}px`;
245
- anims[i].style.top = `${topPos}px`;
246
- anims[i].style.width = `150px`;
247
- }
248
- });
249
-
250
- let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
251
- if (newPoses.length > 0) {
252
- let primaryNewPoseId = newPoses[0];
253
- sounds.forEach(s => { s.pause(); s.currentTime = 0; });
254
- const soundToPlay = sounds[primaryNewPoseId - 1];
255
- if (soundToPlay) soundToPlay.play();
256
- }
257
- memoryActivePoses = currentIds;
258
- memoryTimer = Date.now();
259
- } else {
260
- if (Date.now() - memoryTimer > 500) {
261
- statusPose.textContent = "Menunggu formasi jari...";
262
- statusPose.style.color = "#94a3b8";
263
- memoryActivePoses = [];
264
- }
265
- }
266
- });
267
 
268
- // --- CUSTOM CAMERA ENGINE (PENGGANTI camera_utils.js) ---
269
- startBtn.addEventListener('click', async () => {
270
- startBtn.style.display = 'none';
271
- statusPose.textContent = "Minta Izin Kamera...";
272
-
273
- // Unblock audio
274
- sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
275
-
276
- try {
277
- // Memanggil Kamera Manual (WebRTC)
278
- const stream = await navigator.mediaDevices.getUserMedia({
279
- video: { width: 640, height: 480 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  });
 
 
 
 
 
 
281
 
282
- videoElement.srcObject = stream;
283
-
284
- // Menunggu video siap dimainkan
285
- videoElement.onloadedmetadata = () => {
286
- videoElement.play();
287
- statusPose.textContent = "Sistem AI Berjalan 🚀";
288
- statusPose.style.color = "#10b981"; // Hijau
289
-
290
- // Fungsi Loop Frame Dinamis
291
- async function renderFrame() {
292
- if (!videoElement.paused && !videoElement.ended) {
293
- // Kirim gambar ke otak AI secara paralel
294
- await Promise.all([
295
- faceMesh.send({image: videoElement}),
296
- hands.send({image: videoElement})
297
- ]);
298
- }
299
- // Ulangi terus menerus seperti animasi
300
- requestAnimationFrame(renderFrame);
301
  }
302
-
303
- // Jalankan loop
304
- renderFrame();
305
- };
306
 
307
- } catch (error) {
308
- // Pesan peringatan jika kamera ditolak / error
309
- alert("KAMERA GAGAL DIAKSES!\n\n1. Pastikan Anda klik 'Allow/Izinkan'.\n2. Jika Anda membuka file ini dengan klik 2x (file://), kamera akan diblokir. Harap buka lewat Hugging Face / localhost.\n\nDetail: " + error.message);
310
-
311
- statusPose.textContent = "Kamera Terblokir 🔴";
312
- statusPose.style.color = "#ef4444";
313
- startBtn.style.display = 'block';
 
 
 
 
314
  }
315
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  </script>
317
  </body>
318
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AI Vision v20 - Rizki Ardiansyah</title>
7
 
8
+ <script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
9
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
10
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
11
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js" crossorigin="anonymous"></script>
12
 
13
  <style>
14
+ body {
15
+ background: radial-gradient(circle at top, #1e293b, #0f172a);
16
+ color: #f8fafc;
17
+ font-family: 'Segoe UI', sans-serif;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ margin: 0;
22
+ padding: 20px;
23
+ min-height: 100vh;
24
  }
25
+
26
  h2 { margin-bottom: 5px; color: #38bdf8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.5); }
27
  p { color: #94a3b8; margin-top: 0; text-align: center; }
28
+
29
+ #startBtn {
30
+ background: linear-gradient(135deg, #ec4899, #8b5cf6);
31
+ color: white; border: none; padding: 15px 35px;
32
+ font-size: 18px; border-radius: 50px; cursor: pointer;
33
+ font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
34
+ transition: all 0.3s ease; margin: 20px 0;
35
  }
36
+
37
+ #statusContainer {
38
+ background: rgba(15, 23, 42, 0.8); border: 1px solid #334155;
39
+ padding: 15px 30px; border-radius: 12px; margin-bottom: 20px;
40
+ min-width: 300px; text-align: center;
 
41
  }
42
+
 
43
  .monitor-container { position: relative; }
44
 
45
+ canvas {
46
+ border: 3px solid #3b82f6;
47
+ box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
48
+ border-radius: 16px; background-color: #000;
49
+ width: 640px; height: 480px; max-width: 90vw;
50
+ object-fit: cover; transform: scaleX(-1);
51
  }
52
+
53
+ .pose1-anim {
54
  position: absolute; opacity: 0; border-radius: 8px; z-index: 10;
55
  border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
56
+ pointer-events: none; transition: opacity 0.2s, left 0.1s, top 0.1s;
57
+ transform: scaleX(-1);
58
  }
59
+
60
+ #biometricContainer {
61
+ position: absolute; top: 15px; right: 15px;
62
+ background: rgba(15, 23, 42, 0.85); border: 2px solid #3b82f6;
63
+ padding: 15px; border-radius: 12px; z-index: 20;
64
+ backdrop-filter: blur(5px); min-width: 160px;
65
  }
66
+ .bio-label { font-size: 10px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; }
67
+ .bio-value { font-size: 17px; font-weight: bold; color: #f8fafc; margin-bottom: 5px; }
68
+ .divider { height: 1px; background-color: #334155; margin: 8px 0; }
 
69
  </style>
70
  </head>
71
+ <body>
72
 
73
+ <h2>🤖 AI Vision: Ultimate Tracking By Rizki</h2>
74
+ <p>Smart Biometrics & Debounce System v20</p>
75
+
76
+ <button id="startBtn">▶ Jalankan Sistem AI</button>
 
 
 
 
77
 
78
+ <div id="statusContainer">
79
+ <div id="statusPose" style="font-size: 24px; font-weight: bold; color: #94a3b8;">Menunggu Kamera...</div>
80
+ </div>
81
+
82
+ <div class="monitor-container">
83
+ <div id="biometricContainer">
84
+ <div class="bio-label">Kondisi Mood</div>
85
+ <div id="moodValue" class="bio-value">...</div>
86
+ <div class="divider"></div>
87
+ <div class="bio-label">Estimasi Gender</div>
88
+ <div id="genderValue" class="bio-value">...</div>
89
+ </div>
90
+
91
+ <video id="videoElement" style="display: none;" autoplay playsinline></video>
92
+ <canvas id="outputCanvas" width="640" height="480"></canvas>
93
 
94
+ <img id="pose1Anim1" class="pose1-anim" src="animasi1.gif">
95
+ <img id="pose1Anim2" class="pose1-anim" src="animasi1.gif">
96
+ </div>
97
+
98
  <audio id="audio1" src="suara1.mp3"></audio>
99
  <audio id="audio2" src="suara2.mp3"></audio>
100
  <audio id="audio3" src="suara3.mp3"></audio>
101
  <audio id="audio4" src="suara4.mp3"></audio>
102
  <audio id="audio5" src="suara5.mp3"></audio>
103
+
104
+ <script>
105
+ const videoElement = document.getElementById('videoElement');
106
+ const canvasElement = document.getElementById('outputCanvas');
107
+ const canvasCtx = canvasElement.getContext('2d');
108
+ const startBtn = document.getElementById('startBtn');
109
+ const statusPose = document.getElementById('statusPose');
110
+ const moodValue = document.getElementById('moodValue');
111
+ const genderValue = document.getElementById('genderValue');
112
+ const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
113
+ const sounds = [
114
+ document.getElementById('audio1'), document.getElementById('audio2'),
115
+ document.getElementById('audio3'), document.getElementById('audio4'),
116
+ document.getElementById('audio5')
117
+ ];
118
+
 
 
119
  let memoryActivePoses = [];
120
  let memoryTimer = 0;
121
+ let currentFaceLandmarks = null;
122
+
123
+ function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
124
+
125
+ function analyzeFace(face) {
126
+ // Mood Logic
127
+ const smileRatio = getDistance(face[61], face[291]) / getDistance(face[33], face[263]);
128
+ const openRatio = getDistance(face[13], face[14]) / getDistance(face[33], face[263]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
+ let mood = { text: "Netral 😐", color: "#3b82f6" };
131
+ if (openRatio > 0.15) mood = { text: "Terkejut 😲", color: "#a855f7" };
132
+ else if (smileRatio > 0.52) mood = { text: "Senang 😊", color: "#10b981" };
133
+
134
+ // SMART GENDER LOGIC (Hijab Friendly)
135
+ // Cek Alis (Biasanya wanita lebih melengkung tinggi)
136
+ const eyebrowRatio = getDistance(face[159], face[52]) / getDistance(face[10], face[152]);
137
+ // Cek Rahang
138
+ const jawRatio = getDistance(face[132], face[361]) / getDistance(face[234], face[454]);
139
 
140
+ let gender = { text: "Pria 👨", color: "#60a5fa" };
141
+ // Jika Alis Tinggi (>0.050) OTOMATIS Wanita (Mengabaikan kain hijab di rahang)
142
+ if (eyebrowRatio > 0.050 || jawRatio < 0.755) {
143
+ gender = { text: "Wanita 👩", color: "#f472b6" };
144
+ }
145
+
146
+ return { mood, gender };
147
+ }
148
+
149
+ function classifyPose(landmarks) {
150
+ const indexOpen = landmarks[8].y < landmarks[6].y;
151
+ const middleOpen = landmarks[12].y < landmarks[10].y;
152
+ const ringOpen = landmarks[16].y < landmarks[14].y;
153
+ const pinkyOpen = landmarks[20].y < landmarks[18].y;
154
  const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
+ if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
157
+ if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak", color: "#3b82f6" };
158
+ if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
159
+ if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
160
+ if (getDistance(landmarks[4], landmarks[8]) < 0.05 && middleOpen) return { id: 3, name: "👌 Okay", color: "#10b981" };
161
+ return null;
162
+ }
163
+
164
+ const faceMesh = new FaceMesh({locateFile: (f) => `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${f}`});
165
+ faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: true, minDetectionConfidence: 0.7 });
166
+ faceMesh.onResults((res) => { currentFaceLandmarks = res.multiFaceLandmarks?.[0]; });
167
+
168
+ const hands = new Hands({locateFile: (f) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${f}`});
169
+ hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.7 });
170
+ hands.onResults((res) => {
171
+ canvasCtx.save();
172
+ canvasCtx.clearRect(0, 0, 640, 480);
173
+ canvasCtx.drawImage(res.image, 0, 0, 640, 480);
174
+
175
+ if (currentFaceLandmarks) {
176
+ const bio = analyzeFace(currentFaceLandmarks);
177
+ moodValue.textContent = bio.mood.text; moodValue.style.color = bio.mood.color;
178
+ genderValue.textContent = bio.gender.text; genderValue.style.color = bio.gender.color;
179
+ // Draw Face Mesh
180
+ drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
181
+ drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
182
+ }
183
+
184
+ let poses = [];
185
+ anims.forEach(a => a.style.opacity = '0');
186
+
187
+ if (res.multiHandLandmarks) {
188
+ res.multiHandLandmarks.forEach((lm, i) => {
189
+ drawConnectors(canvasCtx, lm, HAND_CONNECTIONS, {color: i===0?'#ec4899':'#06b6d4', lineWidth: 4});
190
+ let p = classifyPose(lm);
191
+ if (p) poses.push({...p, wrist: lm[0]});
192
  });
193
+ }
194
+ canvasCtx.restore();
195
+
196
+ if (poses.length > 0) {
197
+ statusPose.textContent = [...new Set(poses.map(p => p.name))].join(" & ");
198
+ statusPose.style.color = poses[0].color;
199
 
200
+ poses.forEach((p, i) => {
201
+ if (p.id === 1 && anims[i]) {
202
+ anims[i].style.opacity = '1';
203
+ anims[i].style.left = `${((1-p.wrist.x)*640)-75}px`;
204
+ anims[i].style.top = `${(p.wrist.y*480)+30}px`;
205
+ anims[i].style.width = "150px";
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  }
207
+ });
 
 
 
208
 
209
+ let newIds = poses.map(p => p.id).filter(id => !memoryActivePoses.includes(id));
210
+ if (newIds.length > 0) {
211
+ sounds.forEach(s => { s.pause(); s.currentTime = 0; });
212
+ sounds[newIds[0]-1]?.play();
213
+ }
214
+ memoryActivePoses = poses.map(p => p.id);
215
+ memoryTimer = Date.now();
216
+ } else if (Date.now() - memoryTimer > 500) {
217
+ statusPose.textContent = "Menunggu formasi jari...";
218
+ statusPose.style.color = "#94a3b8";
219
+ memoryActivePoses = [];
220
  }
221
+ });
222
+
223
+ startBtn.addEventListener('click', () => {
224
+ startBtn.style.display = 'none';
225
+ sounds.forEach(s => { s.play().then(()=>s.pause()); });
226
+ const cam = new Camera(videoElement, {
227
+ onFrame: async () => {
228
+ await faceMesh.send({image: videoElement});
229
+ await hands.send({image: videoElement});
230
+ },
231
+ width: 640, height: 480
232
+ });
233
+ cam.start();
234
+ });
235
  </script>
236
  </body>
237
  </html>