Spaces:
Running
Running
Update index.html
Browse files- index.html +225 -255
index.html
CHANGED
|
@@ -3,9 +3,8 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
|
| 8 |
-
<!-- Library AI MediaPipe -->
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 11 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
|
@@ -16,153 +15,122 @@
|
|
| 16 |
background: radial-gradient(circle at top, #1e293b, #0f172a);
|
| 17 |
color: #f8fafc;
|
| 18 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 19 |
-
display: flex;
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
color: white; border: none; padding: 15px 40px;
|
| 26 |
-
font-size: 18px; border-radius: 50px; cursor: pointer;
|
| 27 |
-
font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 28 |
-
transition: all 0.3s ease; margin-bottom: 20px;
|
| 29 |
-
text-transform: uppercase; letter-spacing: 1px;
|
| 30 |
-
}
|
| 31 |
-
#startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
border
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
align-items: flex-start; justify-content: center;
|
| 44 |
-
width: 100%; max-width: 1300px;
|
| 45 |
}
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
}
|
| 56 |
-
|
| 57 |
|
| 58 |
-
.
|
| 59 |
-
|
| 60 |
-
.data-label { font-size: 14px; font-weight: bold; color: #f8fafc; }
|
| 61 |
-
.data-value { font-size: 13px; color: #10b981; }
|
| 62 |
-
|
| 63 |
-
/* MONITOR TENGAH */
|
| 64 |
-
.center-stage { display: flex; flex-direction: column; align-items: center; gap: 20px; }
|
| 65 |
-
.canvas-container { position: relative; }
|
| 66 |
canvas {
|
| 67 |
-
border: 3px solid #
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
transform: scaleX(-1);
|
| 71 |
}
|
| 72 |
|
|
|
|
| 73 |
.pose1-anim {
|
| 74 |
-
position: absolute;
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
transform: scaleX(-1);
|
| 78 |
}
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
}
|
| 88 |
-
.
|
| 89 |
-
.
|
| 90 |
-
.
|
| 91 |
-
|
| 92 |
-
box-shadow: 0 0 15px rgba(234, 179, 8, 0.5); opacity: 1; transform: scale(1.05);
|
| 93 |
-
}
|
| 94 |
-
.pose-box.active .pose-name { color: #f8fafc; }
|
| 95 |
-
|
| 96 |
</style>
|
| 97 |
</head>
|
| 98 |
<body>
|
| 99 |
|
|
|
|
|
|
|
|
|
|
| 100 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
<div class="side-panel">
|
| 106 |
-
<div class="data-item" style="margin-bottom: 10px;">
|
| 107 |
-
<div class="data-label" style="font-size: 18px; color: #38bdf8;">⚙️ Zero-Team AI</div>
|
| 108 |
-
</div>
|
| 109 |
-
<div class="data-item"><div class="data-label">👁️ Computer Vision Engine</div></div>
|
| 110 |
-
<div class="data-item"><div class="data-label">🖐️ Mediapipe Hands: v0.10.x</div></div>
|
| 111 |
-
<div class="data-item"><div class="data-label">🎭 Mediapipe FaceMesh: v0.10.x</div></div>
|
| 112 |
-
<div class="data-item" style="margin-top: 20px;">
|
| 113 |
-
<div class="data-label">🛡️ Status Deteksi:</div>
|
| 114 |
-
<div id="statusKiri" class="data-value" style="color: #94a3b8; font-size: 14px;">Standby</div>
|
| 115 |
-
</div>
|
| 116 |
-
</div>
|
| 117 |
|
| 118 |
-
|
| 119 |
-
<div
|
| 120 |
-
<div class="
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 126 |
-
</div>
|
| 127 |
-
|
| 128 |
-
<div class="pose-indicators">
|
| 129 |
-
<div id="boxPose1" class="pose-box"><div class="pose-emoji">👍</div><div class="pose-name">Thumbs Up</div></div>
|
| 130 |
-
<div id="boxPose2" class="pose-box"><div class="pose-emoji">✌️</div><div class="pose-name">Peace</div></div>
|
| 131 |
-
<div id="boxPose3" class="pose-box"><div class="pose-emoji">👌</div><div class="pose-name">Okay</div></div>
|
| 132 |
-
<div id="boxPose4" class="pose-box"><div class="pose-emoji">🖐️</div><div class="pose-name">Open Palm</div></div>
|
| 133 |
-
<div id="boxPose5" class="pose-box"><div class="pose-emoji">✊</div><div class="pose-name">Fist</div></div>
|
| 134 |
-
</div>
|
| 135 |
</div>
|
| 136 |
|
| 137 |
-
<
|
| 138 |
-
<
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
<div class="data-label">Bentuk Wajah</div>
|
| 143 |
-
<div id="valWajah" class="data-value" style="color: #cbd5e1;">Memindai...</div>
|
| 144 |
-
</div>
|
| 145 |
-
<div class="data-item">
|
| 146 |
-
<div class="data-label">Bentuk Rahang</div>
|
| 147 |
-
<div id="valRahang" class="data-value" style="color: #cbd5e1;">Memindai...</div>
|
| 148 |
-
</div>
|
| 149 |
-
<div class="data-item">
|
| 150 |
-
<div class="data-label">Karakter Alis</div>
|
| 151 |
-
<div id="valAlis" class="data-value" style="color: #cbd5e1;">Memindai...</div>
|
| 152 |
-
</div>
|
| 153 |
-
</div>
|
| 154 |
-
|
| 155 |
-
<div class="side-panel pink-border">
|
| 156 |
-
<div class="data-item">
|
| 157 |
-
<div class="panel-title">Kondisi Mood</div>
|
| 158 |
-
<div id="moodValue" class="data-label" style="font-size: 18px;">Menganalisis...</div>
|
| 159 |
-
</div>
|
| 160 |
-
<div class="data-item" style="margin-top: 10px;">
|
| 161 |
-
<div class="panel-title">Estimasi Gender / Hijab</div>
|
| 162 |
-
<div id="genderValue" class="data-label" style="font-size: 18px;">Memindai...</div>
|
| 163 |
-
</div>
|
| 164 |
-
</div>
|
| 165 |
-
</div>
|
| 166 |
</div>
|
| 167 |
|
| 168 |
<audio id="audio1" src="suara1.mp3"></audio>
|
|
@@ -176,12 +144,9 @@
|
|
| 176 |
const canvasElement = document.getElementById('outputCanvas');
|
| 177 |
const canvasCtx = canvasElement.getContext('2d');
|
| 178 |
const startBtn = document.getElementById('startBtn');
|
| 179 |
-
const
|
| 180 |
-
const statusKiri = document.getElementById('statusKiri');
|
| 181 |
|
| 182 |
-
const
|
| 183 |
-
const valRahang = document.getElementById('valRahang');
|
| 184 |
-
const valAlis = document.getElementById('valAlis');
|
| 185 |
const moodValue = document.getElementById('moodValue');
|
| 186 |
const genderValue = document.getElementById('genderValue');
|
| 187 |
|
|
@@ -191,60 +156,55 @@
|
|
| 191 |
document.getElementById('audio3'), document.getElementById('audio4'),
|
| 192 |
document.getElementById('audio5')
|
| 193 |
];
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
document.getElementById('boxPose3'), document.getElementById('boxPose4'),
|
| 197 |
-
document.getElementById('boxPose5')
|
| 198 |
-
];
|
| 199 |
-
|
| 200 |
let memoryActivePoses = [];
|
| 201 |
let memoryTimer = 0;
|
| 202 |
let currentFaceLandmarks = null;
|
| 203 |
|
| 204 |
function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
|
| 205 |
|
| 206 |
-
// --- ALGORITMA BIOMETRIK & HIJAB ---
|
| 207 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 208 |
-
|
| 209 |
-
const
|
| 210 |
-
const
|
| 211 |
-
const
|
| 212 |
-
|
| 213 |
-
const
|
| 214 |
-
const
|
| 215 |
-
const
|
| 216 |
-
|
| 217 |
-
const
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
else if (ratioFace > 1.20) faceText = "Kotak / Simetris";
|
| 221 |
-
|
| 222 |
-
const ratioJaw = jawWidth / faceWidth;
|
| 223 |
-
let jawText = "Tirus / V-Shape";
|
| 224 |
-
if (ratioJaw > 0.85) jawText = "Square-Strong";
|
| 225 |
-
else if (ratioJaw > 0.75) jawText = "Tapered / Normal";
|
| 226 |
-
|
| 227 |
-
const ratioEyebrow = getDistance(alisKiri, alisKiriTengah) / faceHeight;
|
| 228 |
-
let browText = "Datar / Straight";
|
| 229 |
-
if (ratioEyebrow > 0.055) browText = "Arched-High";
|
| 230 |
-
else if (ratioEyebrow > 0.040) browText = "Melengkung Alami";
|
| 231 |
-
|
| 232 |
-
const mouthWidth = getDistance(faceLandmarks[61], faceLandmarks[291]);
|
| 233 |
-
const mouthHeight = getDistance(faceLandmarks[13], faceLandmarks[14]);
|
| 234 |
let moodText = "Netral 😐"; let moodColor = "#3b82f6";
|
| 235 |
-
if (
|
| 236 |
-
else if (
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
}
|
| 243 |
|
| 244 |
-
return {
|
| 245 |
}
|
| 246 |
|
| 247 |
-
// --- ALGORITMA POSE ---
|
| 248 |
function classifyPose(landmarks) {
|
| 249 |
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 250 |
const middleOpen = landmarks[12].y < landmarks[10].y;
|
|
@@ -252,23 +212,31 @@
|
|
| 252 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 253 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 254 |
|
| 255 |
-
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "
|
| 256 |
-
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "
|
| 257 |
-
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "
|
| 258 |
-
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "
|
| 259 |
-
|
|
|
|
|
|
|
| 260 |
|
| 261 |
return null;
|
| 262 |
}
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
|
|
|
| 266 |
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 267 |
-
faceMesh.onResults((results) => { currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null; });
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
|
|
|
|
|
|
|
|
|
| 271 |
|
|
|
|
|
|
|
|
|
|
| 272 |
hands.onResults((results) => {
|
| 273 |
canvasCtx.save();
|
| 274 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
|
@@ -277,107 +245,109 @@
|
|
| 277 |
if (currentFaceLandmarks) {
|
| 278 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 279 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
| 280 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
|
|
|
| 281 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 282 |
-
|
| 283 |
-
const bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
| 284 |
-
valWajah.textContent = bio.faceText; valWajah.style.color = "#10b981";
|
| 285 |
-
valRahang.textContent = bio.jawText; valRahang.style.color = "#10b981";
|
| 286 |
-
valAlis.textContent = bio.browText; valAlis.style.color = "#10b981";
|
| 287 |
-
moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
|
| 288 |
-
genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
|
| 289 |
-
} else {
|
| 290 |
-
valWajah.textContent = "Wajah Hilang"; valRahang.textContent = "Wajah Hilang"; valAlis.textContent = "Wajah Hilang";
|
| 291 |
-
valWajah.style.color = "#cbd5e1"; valRahang.style.color = "#cbd5e1"; valAlis.style.color = "#cbd5e1";
|
| 292 |
-
moodValue.textContent = "Menganalisis..."; moodValue.style.color = "#f8fafc";
|
| 293 |
-
genderValue.textContent = "Memindai..."; genderValue.style.color = "#f8fafc";
|
| 294 |
}
|
| 295 |
|
| 296 |
-
let
|
| 297 |
-
|
| 298 |
-
|
| 299 |
|
| 300 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 301 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 302 |
-
|
|
|
|
| 303 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 304 |
|
| 305 |
let pose = classifyPose(landmarks);
|
| 306 |
-
if (pose) {
|
| 307 |
-
currentIds.push(pose.id);
|
| 308 |
-
poseBoxes[pose.id - 1].classList.add('active');
|
| 309 |
-
|
| 310 |
-
if (pose.id === 1 && anims[index]) {
|
| 311 |
-
const wrist = landmarks[0];
|
| 312 |
-
anims[index].style.opacity = '1';
|
| 313 |
-
anims[index].style.left = `${((1 - wrist.x) * canvasElement.width) - 75}px`;
|
| 314 |
-
anims[index].style.top = `${(wrist.y * canvasElement.height) + 30}px`;
|
| 315 |
-
anims[index].style.width = `150px`;
|
| 316 |
-
}
|
| 317 |
-
}
|
| 318 |
});
|
| 319 |
}
|
| 320 |
canvasCtx.restore();
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
if (currentIds.length > 0) {
|
| 323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
|
|
|
|
| 325 |
if (newPoses.length > 0) {
|
|
|
|
| 326 |
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 327 |
-
const soundToPlay = sounds[
|
| 328 |
if (soundToPlay) soundToPlay.play();
|
| 329 |
}
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
}
|
| 336 |
});
|
| 337 |
|
| 338 |
-
|
| 339 |
-
startBtn.addEventListener('click', async () => {
|
| 340 |
startBtn.style.display = 'none';
|
| 341 |
-
|
| 342 |
-
mainStatus.style.color = "#eab308"; // Kuning warning
|
| 343 |
-
|
| 344 |
-
// Unblock Audio
|
| 345 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 346 |
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
faceMesh.send({image: videoElement}),
|
| 360 |
-
hands.send({image: videoElement})
|
| 361 |
-
]);
|
| 362 |
-
|
| 363 |
-
// Ubah teks saat frame pertama berhasil masuk
|
| 364 |
-
if (mainStatus.textContent.includes("Mendownload")) {
|
| 365 |
-
mainStatus.textContent = "Sistem Aktif & Terkoneksi 🚀";
|
| 366 |
-
mainStatus.style.color = "#10b981"; // Hijau sukses
|
| 367 |
-
}
|
| 368 |
-
},
|
| 369 |
-
width: 640,
|
| 370 |
-
height: 480
|
| 371 |
-
});
|
| 372 |
-
camera.start();
|
| 373 |
-
|
| 374 |
-
} catch (error) {
|
| 375 |
-
// MUNCULKAN ERROR JIKA KAMERA DIBLOKIR / RUSAK
|
| 376 |
-
alert("GAGAL MENGAKSES KAMERA! \nPastikan kamu sudah menekan 'Allow/Izinkan' pada *pop-up* browser. \n\nDetail Error: " + error.message);
|
| 377 |
-
mainStatus.textContent = "Akses Kamera Ditolak / Error 🔴";
|
| 378 |
-
mainStatus.style.color = "#ef4444";
|
| 379 |
-
startBtn.style.display = 'block'; // Munculkan tombol lagi untuk coba ulang
|
| 380 |
-
}
|
| 381 |
});
|
| 382 |
</script>
|
| 383 |
</body>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>AI Vision - v19 Smooth Performance</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>
|
|
|
|
| 15 |
background: radial-gradient(circle at top, #1e293b, #0f172a);
|
| 16 |
color: #f8fafc;
|
| 17 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, 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;
|
| 32 |
+
border: none;
|
| 33 |
+
padding: 15px 35px;
|
| 34 |
+
font-size: 18px;
|
| 35 |
+
border-radius: 50px;
|
| 36 |
+
cursor: pointer;
|
| 37 |
+
font-weight: bold;
|
| 38 |
+
box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 39 |
+
transition: all 0.3s ease;
|
| 40 |
+
margin: 20px 0;
|
| 41 |
+
text-transform: uppercase;
|
| 42 |
}
|
| 43 |
+
#startBtn:hover {
|
| 44 |
+
transform: translateY(-3px);
|
| 45 |
+
box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6);
|
| 46 |
+
background: linear-gradient(135deg, #f472b6, #a78bfa);
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
+
#statusContainer {
|
| 50 |
+
background: rgba(15, 23, 42, 0.8);
|
| 51 |
+
border: 1px solid #334155;
|
| 52 |
+
padding: 15px 30px;
|
| 53 |
+
border-radius: 12px;
|
| 54 |
+
margin-bottom: 20px;
|
| 55 |
+
min-width: 300px;
|
| 56 |
+
text-align: center;
|
| 57 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
| 58 |
}
|
| 59 |
+
#statusPose { font-size: 24px; font-weight: bold; color: #94a3b8; transition: color 0.3s; }
|
| 60 |
|
| 61 |
+
.monitor-container { position: relative; }
|
| 62 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
canvas {
|
| 64 |
+
border: 3px solid #3b82f6;
|
| 65 |
+
box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
|
| 66 |
+
border-radius: 16px;
|
| 67 |
+
background-color: #000;
|
| 68 |
+
width: 640px;
|
| 69 |
+
height: 480px;
|
| 70 |
+
max-width: 90vw;
|
| 71 |
+
object-fit: cover;
|
| 72 |
transform: scaleX(-1);
|
| 73 |
}
|
| 74 |
|
| 75 |
+
/* PERBAIKAN CSS: Animasi GIF Transisi Halus (Anti-Blink) */
|
| 76 |
.pose1-anim {
|
| 77 |
+
position: absolute;
|
| 78 |
+
opacity: 0; /* Default tidak terlihat */
|
| 79 |
+
border-radius: 8px;
|
| 80 |
+
z-index: 10;
|
| 81 |
+
border: 2px solid #eab308;
|
| 82 |
+
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 83 |
+
pointer-events: none;
|
| 84 |
+
/* Transisi opacity ditambahkan agar memudar perlahan saat AI berkedip */
|
| 85 |
+
transition: opacity 0.2s ease-in-out, left 0.1s linear, top 0.1s linear;
|
| 86 |
transform: scaleX(-1);
|
| 87 |
}
|
| 88 |
|
| 89 |
+
#biometricContainer {
|
| 90 |
+
position: absolute;
|
| 91 |
+
top: 15px;
|
| 92 |
+
right: 15px;
|
| 93 |
+
background: rgba(15, 23, 42, 0.85);
|
| 94 |
+
border: 2px solid #3b82f6;
|
| 95 |
+
padding: 15px;
|
| 96 |
+
border-radius: 12px;
|
| 97 |
+
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
|
| 98 |
+
z-index: 20;
|
| 99 |
+
backdrop-filter: blur(5px);
|
| 100 |
+
transition: border-color 0.3s, box-shadow 0.3s;
|
| 101 |
+
min-width: 150px;
|
| 102 |
}
|
| 103 |
+
.bio-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; margin-bottom: 2px;}
|
| 104 |
+
.bio-label:first-child { margin-top: 0; }
|
| 105 |
+
.bio-value { font-size: 18px; font-weight: bold; color: #f8fafc; }
|
| 106 |
+
.divider { height: 1px; background-color: #334155; margin: 8px 0; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
</style>
|
| 108 |
</head>
|
| 109 |
<body>
|
| 110 |
|
| 111 |
+
<h2>🤖 AI Vision: Smooth Tracking</h2>
|
| 112 |
+
<p>By Rizki Ardiansyah (Optimized)</p>
|
| 113 |
+
|
| 114 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 115 |
+
|
| 116 |
+
<div id="statusContainer">
|
| 117 |
+
<div id="statusPose">Menunggu Kamera...</div>
|
| 118 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
<div class="monitor-container">
|
| 121 |
+
<div id="biometricContainer">
|
| 122 |
+
<div class="bio-label">Kondisi Mood</div>
|
| 123 |
+
<div id="moodValue" class="bio-value">Menganalisis...</div>
|
| 124 |
+
<div class="divider"></div>
|
| 125 |
+
<div class="bio-label">Estimasi Anatomi</div>
|
| 126 |
+
<div id="genderValue" class="bio-value" style="color: #cbd5e1;">Memindai...</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
</div>
|
| 128 |
|
| 129 |
+
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
| 130 |
+
<canvas id="outputCanvas" width="640" height="480"></canvas>
|
| 131 |
+
|
| 132 |
+
<img id="pose1Anim1" class="pose1-anim" src="animasi1.gif" alt="Pose 1">
|
| 133 |
+
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
</div>
|
| 135 |
|
| 136 |
<audio id="audio1" src="suara1.mp3"></audio>
|
|
|
|
| 144 |
const canvasElement = document.getElementById('outputCanvas');
|
| 145 |
const canvasCtx = canvasElement.getContext('2d');
|
| 146 |
const startBtn = document.getElementById('startBtn');
|
| 147 |
+
const statusPose = document.getElementById('statusPose');
|
|
|
|
| 148 |
|
| 149 |
+
const biometricContainer = document.getElementById('biometricContainer');
|
|
|
|
|
|
|
| 150 |
const moodValue = document.getElementById('moodValue');
|
| 151 |
const genderValue = document.getElementById('genderValue');
|
| 152 |
|
|
|
|
| 156 |
document.getElementById('audio3'), document.getElementById('audio4'),
|
| 157 |
document.getElementById('audio5')
|
| 158 |
];
|
| 159 |
+
|
| 160 |
+
// VARIABEL MEMORI (ANTI-LAG & ANTI-STUTTER)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
let memoryActivePoses = [];
|
| 162 |
let memoryTimer = 0;
|
| 163 |
let currentFaceLandmarks = null;
|
| 164 |
|
| 165 |
function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
|
| 166 |
|
|
|
|
| 167 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 168 |
+
// 1. Analisis Mood
|
| 169 |
+
const leftMouth = faceLandmarks[61]; const rightMouth = faceLandmarks[291];
|
| 170 |
+
const topLip = faceLandmarks[13]; const bottomLip = faceLandmarks[14];
|
| 171 |
+
const leftEye = faceLandmarks[33]; const rightEye = faceLandmarks[263];
|
| 172 |
+
|
| 173 |
+
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 174 |
+
const mouthHeight = getDistance(topLip, bottomLip);
|
| 175 |
+
const faceScale = getDistance(leftEye, rightEye);
|
| 176 |
+
|
| 177 |
+
const smileRatio = mouthWidth / faceScale;
|
| 178 |
+
const openRatio = mouthHeight / faceScale;
|
| 179 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
let moodText = "Netral 😐"; let moodColor = "#3b82f6";
|
| 181 |
+
if (openRatio > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 182 |
+
else if (smileRatio > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 183 |
|
| 184 |
+
// 2. Analisis Estimasi Gender
|
| 185 |
+
const leftCheek = faceLandmarks[234]; const rightCheek = faceLandmarks[454];
|
| 186 |
+
const leftJaw = faceLandmarks[132]; const rightJaw = faceLandmarks[361];
|
| 187 |
+
|
| 188 |
+
const cheekWidth = getDistance(leftCheek, rightCheek);
|
| 189 |
+
const jawWidth = getDistance(leftJaw, rightJaw);
|
| 190 |
+
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 191 |
+
|
| 192 |
+
// FITUR DEBUGGING
|
| 193 |
+
let angkaRasio = jawToCheekRatio.toFixed(3);
|
| 194 |
+
|
| 195 |
+
let genderText = ""; let genderColor = "";
|
| 196 |
+
|
| 197 |
+
if (jawToCheekRatio > 0.820) {
|
| 198 |
+
genderText = `Pria 👨 (${angkaRasio})`;
|
| 199 |
+
genderColor = "#60a5fa";
|
| 200 |
+
} else {
|
| 201 |
+
genderText = `Wanita 👩 (${angkaRasio})`;
|
| 202 |
+
genderColor = "#f472b6";
|
| 203 |
}
|
| 204 |
|
| 205 |
+
return { moodText, moodColor, genderText, genderColor };
|
| 206 |
}
|
| 207 |
|
|
|
|
| 208 |
function classifyPose(landmarks) {
|
| 209 |
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 210 |
const middleOpen = landmarks[12].y < landmarks[10].y;
|
|
|
|
| 212 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 213 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 214 |
|
| 215 |
+
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
|
| 216 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak", color: "#3b82f6" };
|
| 217 |
+
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 218 |
+
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
| 219 |
+
|
| 220 |
+
const thumbIndexTipDist = getDistance(landmarks[4], landmarks[8]);
|
| 221 |
+
if (thumbIndexTipDist < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "👌 Okay", color: "#10b981" };
|
| 222 |
|
| 223 |
return null;
|
| 224 |
}
|
| 225 |
|
| 226 |
+
const faceMesh = new FaceMesh({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`; }});
|
| 227 |
+
|
| 228 |
+
// SOLUSI LAG 1: refineLandmarks diubah ke false, confidence diturunkan ke 0.5
|
| 229 |
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
|
|
|
| 230 |
|
| 231 |
+
faceMesh.onResults((results) => {
|
| 232 |
+
currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null;
|
| 233 |
+
});
|
| 234 |
+
|
| 235 |
+
const hands = new Hands({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; }});
|
| 236 |
|
| 237 |
+
// SOLUSI LAG 2: modelComplexity 0, confidence diturunkan ke 0.5
|
| 238 |
+
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 239 |
+
|
| 240 |
hands.onResults((results) => {
|
| 241 |
canvasCtx.save();
|
| 242 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
|
|
|
| 245 |
if (currentFaceLandmarks) {
|
| 246 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 247 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
| 248 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYEBROW, {color: '#ec4899', lineWidth: 2});
|
| 249 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
|
| 250 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYEBROW, {color: '#ec4899', lineWidth: 2});
|
| 251 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_FACE_OVAL, {color: '#ec4899', lineWidth: 2});
|
| 252 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
}
|
| 254 |
|
| 255 |
+
let detectedPosesThisFrame = [];
|
| 256 |
+
// Reset opacity GIF (bukan display none, agar tidak kaku)
|
| 257 |
+
anims.forEach(a => a.style.opacity = '0');
|
| 258 |
|
| 259 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 260 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 261 |
+
let boneColor = index === 0 ? '#ec4899' : '#06b6d4';
|
| 262 |
+
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: boneColor, lineWidth: 4});
|
| 263 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 264 |
|
| 265 |
let pose = classifyPose(landmarks);
|
| 266 |
+
if (pose) detectedPosesThisFrame.push({ ...pose, handIndex: index, wrist: landmarks[0] });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
});
|
| 268 |
}
|
| 269 |
canvasCtx.restore();
|
| 270 |
|
| 271 |
+
// RENDER UI & LOGIKA
|
| 272 |
+
if (currentFaceLandmarks) {
|
| 273 |
+
let bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
| 274 |
+
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 275 |
+
if (bio.moodText === "Senang 😊" && isPositivePose) {
|
| 276 |
+
bio.moodText = "Sangat Senang! ✨"; bio.moodColor = "#eab308";
|
| 277 |
+
}
|
| 278 |
+
moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
|
| 279 |
+
genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
|
| 280 |
+
biometricContainer.style.borderColor = bio.moodColor; biometricContainer.style.boxShadow = `0 0 15px ${bio.moodColor}80`;
|
| 281 |
+
} else {
|
| 282 |
+
moodValue.textContent = "Wajah Hilang"; moodValue.style.color = "#94a3b8";
|
| 283 |
+
genderValue.textContent = "Wajah Hilang"; genderValue.style.color = "#94a3b8";
|
| 284 |
+
biometricContainer.style.borderColor = "#334155";
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// --- LOGIKA AUDIO DENGAN MEMORI DEBOUNCE ---
|
| 288 |
+
let currentIds = detectedPosesThisFrame.map(p => p.id);
|
| 289 |
+
|
| 290 |
if (currentIds.length > 0) {
|
| 291 |
+
let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
|
| 292 |
+
statusPose.textContent = uniquePoseNames.join(" & ");
|
| 293 |
+
statusPose.style.color = detectedPosesThisFrame[0].color;
|
| 294 |
+
|
| 295 |
+
// Perbarui posisi GIF dengan halus
|
| 296 |
+
detectedPosesThisFrame.forEach((pose, i) => {
|
| 297 |
+
if (pose.id === 1 && anims[i]) {
|
| 298 |
+
const wrist = pose.wrist;
|
| 299 |
+
const leftPos = ((1 - wrist.x) * canvasElement.width) - 75;
|
| 300 |
+
const topPos = (wrist.y * canvasElement.height) + 30;
|
| 301 |
+
|
| 302 |
+
anims[i].style.opacity = '1'; // Munculkan dengan efek fade
|
| 303 |
+
anims[i].style.left = `${leftPos}px`;
|
| 304 |
+
anims[i].style.top = `${topPos}px`;
|
| 305 |
+
anims[i].style.width = `150px`;
|
| 306 |
+
}
|
| 307 |
+
});
|
| 308 |
+
|
| 309 |
+
// Cek pose baru yang belum ada di memori stabil
|
| 310 |
let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
|
| 311 |
+
|
| 312 |
if (newPoses.length > 0) {
|
| 313 |
+
let primaryNewPoseId = newPoses[0];
|
| 314 |
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 315 |
+
const soundToPlay = sounds[primaryNewPoseId - 1];
|
| 316 |
if (soundToPlay) soundToPlay.play();
|
| 317 |
}
|
| 318 |
+
|
| 319 |
+
memoryActivePoses = currentIds; // Simpan memori terbaru
|
| 320 |
+
memoryTimer = Date.now(); // Reset stopwatch memori
|
| 321 |
+
|
| 322 |
+
} else {
|
| 323 |
+
// Tangan tidak terdeteksi. Jangan langsung bersihkan memori! Tunggu 0.5 detik (500ms)
|
| 324 |
+
if (Date.now() - memoryTimer > 500) {
|
| 325 |
+
if (memoryActivePoses.length > 0) {
|
| 326 |
+
statusPose.textContent = "Menunggu formasi jari...";
|
| 327 |
+
statusPose.style.color = "#94a3b8";
|
| 328 |
+
memoryActivePoses = [];
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
}
|
| 332 |
});
|
| 333 |
|
| 334 |
+
startBtn.addEventListener('click', () => {
|
|
|
|
| 335 |
startBtn.style.display = 'none';
|
| 336 |
+
statusPose.textContent = "Menyiapkan Kamera...";
|
|
|
|
|
|
|
|
|
|
| 337 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 338 |
|
| 339 |
+
const camera = new Camera(videoElement, {
|
| 340 |
+
onFrame: async () => {
|
| 341 |
+
// SOLUSI LAG 3: Gunakan Promise.all agar AI Wajah dan Tangan memproses secara paralel, BUKAN antri
|
| 342 |
+
await Promise.all([
|
| 343 |
+
faceMesh.send({image: videoElement}),
|
| 344 |
+
hands.send({image: videoElement})
|
| 345 |
+
]);
|
| 346 |
+
},
|
| 347 |
+
width: 640,
|
| 348 |
+
height: 480
|
| 349 |
+
});
|
| 350 |
+
camera.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
});
|
| 352 |
</script>
|
| 353 |
</body>
|