Spaces:
Running
Running
Update index.html
Browse files- index.html +80 -65
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Zero-Team AI - Biometric Dashboard
|
| 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>
|
|
@@ -30,33 +30,32 @@
|
|
| 30 |
font-size: 18px; border-radius: 50px; cursor: pointer;
|
| 31 |
font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 32 |
transition: all 0.3s ease; margin-bottom: 20px;
|
| 33 |
-
text-transform: uppercase;
|
| 34 |
}
|
| 35 |
#startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }
|
| 36 |
|
| 37 |
#mainStatus {
|
| 38 |
font-size: 20px; font-weight: bold; color: #94a3b8;
|
| 39 |
background: rgba(15, 23, 42, 0.6); padding: 10px 30px;
|
| 40 |
-
border-radius:
|
| 41 |
}
|
| 42 |
|
| 43 |
-
/* --- LAYOUT UTAMA
|
| 44 |
.dashboard-container {
|
| 45 |
display: flex; flex-direction: row; gap: 25px;
|
| 46 |
-
align-items:
|
| 47 |
-
width: 100%; max-width:
|
| 48 |
}
|
| 49 |
|
| 50 |
-
/*
|
| 51 |
.side-panel {
|
| 52 |
background: rgba(15, 23, 42, 0.7);
|
| 53 |
border: 2px solid #3b82f6; border-radius: 12px;
|
| 54 |
-
padding: 20px; width:
|
| 55 |
box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
|
| 56 |
backdrop-filter: blur(10px);
|
| 57 |
display: flex; flex-direction: column; gap: 15px;
|
| 58 |
}
|
| 59 |
-
|
| 60 |
.side-panel.pink-border { border-color: #ec4899; box-shadow: 0 0 20px rgba(236, 72, 153, 0.3); }
|
| 61 |
|
| 62 |
.panel-title { font-size: 12px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #334155; padding-bottom: 8px; margin-bottom: 5px; }
|
|
@@ -64,10 +63,9 @@
|
|
| 64 |
.data-label { font-size: 14px; font-weight: bold; color: #f8fafc; }
|
| 65 |
.data-value { font-size: 13px; color: #10b981; }
|
| 66 |
|
| 67 |
-
/*
|
| 68 |
.center-stage {
|
| 69 |
display: flex; flex-direction: column; align-items: center; gap: 20px;
|
| 70 |
-
position: relative;
|
| 71 |
}
|
| 72 |
|
| 73 |
.canvas-container { position: relative; }
|
|
@@ -78,7 +76,6 @@
|
|
| 78 |
transform: scaleX(-1);
|
| 79 |
}
|
| 80 |
|
| 81 |
-
/* GIF Transisi Halus */
|
| 82 |
.pose1-anim {
|
| 83 |
position: absolute; opacity: 0; border-radius: 8px; z-index: 10;
|
| 84 |
border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
|
@@ -86,34 +83,47 @@
|
|
| 86 |
transform: scaleX(-1);
|
| 87 |
}
|
| 88 |
|
| 89 |
-
/*
|
| 90 |
.pose-indicators {
|
| 91 |
-
display: flex; gap: 15px; justify-content: center;
|
| 92 |
}
|
| 93 |
.pose-box {
|
| 94 |
-
background: rgba(15, 23, 42, 0.
|
| 95 |
-
border
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
.pose-box.active {
|
| 99 |
-
border
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
-
.pose-
|
| 103 |
-
.pose-name { font-size: 11px; font-weight: bold; color: #f8fafc; }
|
| 104 |
|
| 105 |
</style>
|
| 106 |
</head>
|
| 107 |
<body>
|
| 108 |
|
| 109 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 110 |
-
<div id="mainStatus">Sistem Menunggu...</div>
|
| 111 |
|
| 112 |
<div class="dashboard-container">
|
| 113 |
-
<!-- PANEL KIRI -->
|
| 114 |
<div class="side-panel">
|
| 115 |
<div class="data-item" style="margin-bottom: 10px;">
|
| 116 |
-
<div class="data-label" style="font-size: 18px; color: #38bdf8;">⚙️ Zero-Team AI
|
| 117 |
</div>
|
| 118 |
<div class="data-item">
|
| 119 |
<div class="data-label">👁️ Computer Vision Engine</div>
|
|
@@ -130,7 +140,7 @@
|
|
| 130 |
</div>
|
| 131 |
</div>
|
| 132 |
|
| 133 |
-
<!-- TENGAH
|
| 134 |
<div class="center-stage">
|
| 135 |
<div class="canvas-container">
|
| 136 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
|
@@ -139,7 +149,7 @@
|
|
| 139 |
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 140 |
</div>
|
| 141 |
|
| 142 |
-
<!--
|
| 143 |
<div class="pose-indicators">
|
| 144 |
<div id="boxPose1" class="pose-box"><div class="pose-emoji">👍</div><div class="pose-name">Thumbs Up</div></div>
|
| 145 |
<div id="boxPose2" class="pose-box"><div class="pose-emoji">✌️</div><div class="pose-name">Peace</div></div>
|
|
@@ -149,21 +159,21 @@
|
|
| 149 |
</div>
|
| 150 |
</div>
|
| 151 |
|
| 152 |
-
<!-- PANEL KANAN -->
|
| 153 |
<div style="display: flex; flex-direction: column; gap: 20px;">
|
| 154 |
<div class="side-panel">
|
| 155 |
-
<div class="panel-title">Kondisi Biometrik (
|
| 156 |
<div class="data-item">
|
| 157 |
<div class="data-label">Bentuk Wajah</div>
|
| 158 |
-
<div id="valWajah" class="data-value" style="color: #cbd5e1;">
|
| 159 |
</div>
|
| 160 |
<div class="data-item">
|
| 161 |
<div class="data-label">Bentuk Rahang</div>
|
| 162 |
-
<div id="valRahang" class="data-value" style="color: #cbd5e1;">
|
| 163 |
</div>
|
| 164 |
<div class="data-item">
|
| 165 |
-
<div class="data-label">Karakter Alis
|
| 166 |
-
<div id="valAlis" class="data-value" style="color: #cbd5e1;">
|
| 167 |
</div>
|
| 168 |
</div>
|
| 169 |
|
|
@@ -173,7 +183,7 @@
|
|
| 173 |
<div id="moodValue" class="data-label" style="font-size: 18px;">Menganalisis...</div>
|
| 174 |
</div>
|
| 175 |
<div class="data-item" style="margin-top: 10px;">
|
| 176 |
-
<div class="panel-title">Estimasi
|
| 177 |
<div id="genderValue" class="data-label" style="font-size: 18px;">Memindai...</div>
|
| 178 |
</div>
|
| 179 |
</div>
|
|
@@ -209,7 +219,7 @@
|
|
| 209 |
document.getElementById('audio5')
|
| 210 |
];
|
| 211 |
|
| 212 |
-
//
|
| 213 |
const poseBoxes = [
|
| 214 |
document.getElementById('boxPose1'), document.getElementById('boxPose2'),
|
| 215 |
document.getElementById('boxPose3'), document.getElementById('boxPose4'),
|
|
@@ -222,8 +232,8 @@
|
|
| 222 |
|
| 223 |
function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
|
| 224 |
|
|
|
|
| 225 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 226 |
-
// Titik Referensi Anatomi
|
| 227 |
const dahi = faceLandmarks[10]; const dagu = faceLandmarks[152];
|
| 228 |
const pipiKiri = faceLandmarks[234]; const pipiKanan = faceLandmarks[454];
|
| 229 |
const rahangKiri = faceLandmarks[132]; const rahangKanan = faceLandmarks[361];
|
|
@@ -233,23 +243,23 @@
|
|
| 233 |
const faceWidth = getDistance(pipiKiri, pipiKanan);
|
| 234 |
const jawWidth = getDistance(rahangKiri, rahangKanan);
|
| 235 |
|
| 236 |
-
// 1.
|
| 237 |
const ratioFace = faceHeight / faceWidth;
|
| 238 |
-
let faceText = "
|
| 239 |
-
if (ratioFace > 1.35) faceText = "
|
| 240 |
-
else if (ratioFace > 1.20) faceText = "
|
| 241 |
|
| 242 |
-
// 2.
|
| 243 |
const ratioJaw = jawWidth / faceWidth;
|
| 244 |
-
let jawText = "
|
| 245 |
-
if (ratioJaw > 0.85) jawText = "
|
| 246 |
-
else if (ratioJaw > 0.75) jawText = "
|
| 247 |
|
| 248 |
-
// 3.
|
| 249 |
const ratioEyebrow = getDistance(alisKiri, alisKiriTengah) / faceHeight;
|
| 250 |
-
let browText = "
|
| 251 |
-
if (ratioEyebrow > 0.055) browText = "
|
| 252 |
-
else if (ratioEyebrow > 0.040) browText = "
|
| 253 |
|
| 254 |
// 4. Mood
|
| 255 |
const mouthWidth = getDistance(faceLandmarks[61], faceLandmarks[291]);
|
|
@@ -258,16 +268,17 @@
|
|
| 258 |
if (mouthHeight / faceWidth > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 259 |
else if (mouthWidth / faceWidth > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 260 |
|
| 261 |
-
// 5. Gender
|
| 262 |
const headRatio = getDistance(dahi, faceLandmarks[168]) / jawWidth;
|
| 263 |
let genderText = "Pria 👨"; let genderColor = "#60a5fa";
|
| 264 |
if (headRatio < 0.22 || ratioJaw < 0.75) {
|
| 265 |
-
genderText = "Wanita 👩"; genderColor = "#f472b6";
|
| 266 |
}
|
| 267 |
|
| 268 |
return { faceText, jawText, browText, moodText, moodColor, genderText, genderColor };
|
| 269 |
}
|
| 270 |
|
|
|
|
| 271 |
function classifyPose(landmarks) {
|
| 272 |
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 273 |
const middleOpen = landmarks[12].y < landmarks[10].y;
|
|
@@ -275,11 +286,12 @@
|
|
| 275 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 276 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 277 |
|
| 278 |
-
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return 5
|
| 279 |
-
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return 4
|
| 280 |
-
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return 2
|
| 281 |
-
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return 1
|
| 282 |
-
if (getDistance(landmarks[4], landmarks[8]) < 0.05 && middleOpen && ringOpen && pinkyOpen) return 3
|
|
|
|
| 283 |
return null;
|
| 284 |
}
|
| 285 |
|
|
@@ -298,7 +310,7 @@
|
|
| 298 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 299 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 300 |
|
| 301 |
-
//
|
| 302 |
if (currentFaceLandmarks) {
|
| 303 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 304 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
@@ -320,21 +332,24 @@
|
|
| 320 |
}
|
| 321 |
|
| 322 |
let currentIds = [];
|
| 323 |
-
anims.forEach(a => a.style.opacity = '0'); //
|
| 324 |
-
poseBoxes.forEach(b => b.classList.remove('active')); //
|
| 325 |
|
|
|
|
| 326 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 327 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 328 |
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: index === 0 ? '#ec4899' : '#06b6d4', lineWidth: 4});
|
| 329 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 330 |
|
| 331 |
-
let
|
| 332 |
-
if (
|
| 333 |
-
currentIds.push(
|
| 334 |
-
|
|
|
|
|
|
|
| 335 |
|
| 336 |
-
// GIF
|
| 337 |
-
if (
|
| 338 |
const wrist = landmarks[0];
|
| 339 |
anims[index].style.opacity = '1';
|
| 340 |
anims[index].style.left = `${((1 - wrist.x) * canvasElement.width) - 75}px`;
|
|
@@ -346,7 +361,7 @@
|
|
| 346 |
}
|
| 347 |
canvasCtx.restore();
|
| 348 |
|
| 349 |
-
// LOGIKA AUDIO & STATUS
|
| 350 |
if (currentIds.length > 0) {
|
| 351 |
statusKiri.textContent = "Aktif & Responsif 🟢"; statusKiri.style.color = "#10b981";
|
| 352 |
|
|
@@ -361,7 +376,7 @@
|
|
| 361 |
memoryTimer = Date.now();
|
| 362 |
} else {
|
| 363 |
if (Date.now() - memoryTimer > 500) {
|
| 364 |
-
statusKiri.textContent = "Menunggu
|
| 365 |
memoryActivePoses = [];
|
| 366 |
}
|
| 367 |
}
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Zero-Team AI - Biometric Dashboard</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>
|
|
|
|
| 30 |
font-size: 18px; border-radius: 50px; cursor: pointer;
|
| 31 |
font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 32 |
transition: all 0.3s ease; margin-bottom: 20px;
|
| 33 |
+
text-transform: uppercase; letter-spacing: 1px;
|
| 34 |
}
|
| 35 |
#startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }
|
| 36 |
|
| 37 |
#mainStatus {
|
| 38 |
font-size: 20px; font-weight: bold; color: #94a3b8;
|
| 39 |
background: rgba(15, 23, 42, 0.6); padding: 10px 30px;
|
| 40 |
+
border-radius: 12px; border: 1px solid #334155; margin-bottom: 25px;
|
| 41 |
}
|
| 42 |
|
| 43 |
+
/* --- LAYOUT UTAMA --- */
|
| 44 |
.dashboard-container {
|
| 45 |
display: flex; flex-direction: row; gap: 25px;
|
| 46 |
+
align-items: flex-start; justify-content: center;
|
| 47 |
+
width: 100%; max-width: 1300px;
|
| 48 |
}
|
| 49 |
|
| 50 |
+
/* PANEL KIRI & KANAN */
|
| 51 |
.side-panel {
|
| 52 |
background: rgba(15, 23, 42, 0.7);
|
| 53 |
border: 2px solid #3b82f6; border-radius: 12px;
|
| 54 |
+
padding: 20px; width: 260px;
|
| 55 |
box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
|
| 56 |
backdrop-filter: blur(10px);
|
| 57 |
display: flex; flex-direction: column; gap: 15px;
|
| 58 |
}
|
|
|
|
| 59 |
.side-panel.pink-border { border-color: #ec4899; box-shadow: 0 0 20px rgba(236, 72, 153, 0.3); }
|
| 60 |
|
| 61 |
.panel-title { font-size: 12px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #334155; padding-bottom: 8px; margin-bottom: 5px; }
|
|
|
|
| 63 |
.data-label { font-size: 14px; font-weight: bold; color: #f8fafc; }
|
| 64 |
.data-value { font-size: 13px; color: #10b981; }
|
| 65 |
|
| 66 |
+
/* MONITOR TENGAH */
|
| 67 |
.center-stage {
|
| 68 |
display: flex; flex-direction: column; align-items: center; gap: 20px;
|
|
|
|
| 69 |
}
|
| 70 |
|
| 71 |
.canvas-container { position: relative; }
|
|
|
|
| 76 |
transform: scaleX(-1);
|
| 77 |
}
|
| 78 |
|
|
|
|
| 79 |
.pose1-anim {
|
| 80 |
position: absolute; opacity: 0; border-radius: 8px; z-index: 10;
|
| 81 |
border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
|
|
|
| 83 |
transform: scaleX(-1);
|
| 84 |
}
|
| 85 |
|
| 86 |
+
/* --- DESAIN INDIKATOR POSE SESUAI GAMBAR --- */
|
| 87 |
.pose-indicators {
|
| 88 |
+
display: flex; gap: 15px; justify-content: center; width: 100%;
|
| 89 |
}
|
| 90 |
.pose-box {
|
| 91 |
+
background: rgba(15, 23, 42, 0.5); /* Gelap saat tidak aktif */
|
| 92 |
+
border: 1px solid #334155; /* Border abu-abu tipis */
|
| 93 |
+
border-radius: 12px;
|
| 94 |
+
padding: 15px 10px;
|
| 95 |
+
text-align: center;
|
| 96 |
+
width: 85px;
|
| 97 |
+
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
| 98 |
+
transition: all 0.2s ease;
|
| 99 |
+
opacity: 0.6; /* Redup */
|
| 100 |
}
|
| 101 |
+
|
| 102 |
+
.pose-emoji { font-size: 26px; margin-bottom: 8px; }
|
| 103 |
+
.pose-name { font-size: 12px; font-weight: bold; color: #64748b; transition: color 0.2s; }
|
| 104 |
+
|
| 105 |
+
/* Gaya saat Pose Terdeteksi (Menyala Kuning) */
|
| 106 |
.pose-box.active {
|
| 107 |
+
border: 2px solid #eab308;
|
| 108 |
+
background: rgba(234, 179, 8, 0.1);
|
| 109 |
+
box-shadow: 0 0 15px rgba(234, 179, 8, 0.5);
|
| 110 |
+
opacity: 1;
|
| 111 |
+
transform: scale(1.05);
|
| 112 |
}
|
| 113 |
+
.pose-box.active .pose-name { color: #f8fafc; /* Teks jadi putih terang */ }
|
|
|
|
| 114 |
|
| 115 |
</style>
|
| 116 |
</head>
|
| 117 |
<body>
|
| 118 |
|
| 119 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 120 |
+
<div id="mainStatus">Sistem Menunggu Kamera...</div>
|
| 121 |
|
| 122 |
<div class="dashboard-container">
|
| 123 |
+
<!-- PANEL KIRI (Sistem) -->
|
| 124 |
<div class="side-panel">
|
| 125 |
<div class="data-item" style="margin-bottom: 10px;">
|
| 126 |
+
<div class="data-label" style="font-size: 18px; color: #38bdf8;">⚙️ Zero-Team AI</div>
|
| 127 |
</div>
|
| 128 |
<div class="data-item">
|
| 129 |
<div class="data-label">👁️ Computer Vision Engine</div>
|
|
|
|
| 140 |
</div>
|
| 141 |
</div>
|
| 142 |
|
| 143 |
+
<!-- TENGAH (Kamera & Indikator Pose) -->
|
| 144 |
<div class="center-stage">
|
| 145 |
<div class="canvas-container">
|
| 146 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
|
|
|
| 149 |
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 150 |
</div>
|
| 151 |
|
| 152 |
+
<!-- 5 KOTAK INDIKATOR POSE -->
|
| 153 |
<div class="pose-indicators">
|
| 154 |
<div id="boxPose1" class="pose-box"><div class="pose-emoji">👍</div><div class="pose-name">Thumbs Up</div></div>
|
| 155 |
<div id="boxPose2" class="pose-box"><div class="pose-emoji">✌️</div><div class="pose-name">Peace</div></div>
|
|
|
|
| 159 |
</div>
|
| 160 |
</div>
|
| 161 |
|
| 162 |
+
<!-- PANEL KANAN (Biometrik Wajah) -->
|
| 163 |
<div style="display: flex; flex-direction: column; gap: 20px;">
|
| 164 |
<div class="side-panel">
|
| 165 |
+
<div class="panel-title">Kondisi Biometrik (Wajah)</div>
|
| 166 |
<div class="data-item">
|
| 167 |
<div class="data-label">Bentuk Wajah</div>
|
| 168 |
+
<div id="valWajah" class="data-value" style="color: #cbd5e1;">Memindai...</div>
|
| 169 |
</div>
|
| 170 |
<div class="data-item">
|
| 171 |
<div class="data-label">Bentuk Rahang</div>
|
| 172 |
+
<div id="valRahang" class="data-value" style="color: #cbd5e1;">Memindai...</div>
|
| 173 |
</div>
|
| 174 |
<div class="data-item">
|
| 175 |
+
<div class="data-label">Karakter Alis</div>
|
| 176 |
+
<div id="valAlis" class="data-value" style="color: #cbd5e1;">Memindai...</div>
|
| 177 |
</div>
|
| 178 |
</div>
|
| 179 |
|
|
|
|
| 183 |
<div id="moodValue" class="data-label" style="font-size: 18px;">Menganalisis...</div>
|
| 184 |
</div>
|
| 185 |
<div class="data-item" style="margin-top: 10px;">
|
| 186 |
+
<div class="panel-title">Estimasi Gender / Hijab</div>
|
| 187 |
<div id="genderValue" class="data-label" style="font-size: 18px;">Memindai...</div>
|
| 188 |
</div>
|
| 189 |
</div>
|
|
|
|
| 219 |
document.getElementById('audio5')
|
| 220 |
];
|
| 221 |
|
| 222 |
+
// Element Kotak Pose Bawah
|
| 223 |
const poseBoxes = [
|
| 224 |
document.getElementById('boxPose1'), document.getElementById('boxPose2'),
|
| 225 |
document.getElementById('boxPose3'), document.getElementById('boxPose4'),
|
|
|
|
| 232 |
|
| 233 |
function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
|
| 234 |
|
| 235 |
+
// --- ALGORITMA BIOMETRIK & HIJAB ---
|
| 236 |
function analyzeFaceBiometrics(faceLandmarks) {
|
|
|
|
| 237 |
const dahi = faceLandmarks[10]; const dagu = faceLandmarks[152];
|
| 238 |
const pipiKiri = faceLandmarks[234]; const pipiKanan = faceLandmarks[454];
|
| 239 |
const rahangKiri = faceLandmarks[132]; const rahangKanan = faceLandmarks[361];
|
|
|
|
| 243 |
const faceWidth = getDistance(pipiKiri, pipiKanan);
|
| 244 |
const jawWidth = getDistance(rahangKiri, rahangKanan);
|
| 245 |
|
| 246 |
+
// 1. Bentuk Wajah
|
| 247 |
const ratioFace = faceHeight / faceWidth;
|
| 248 |
+
let faceText = "Bulat / Pendek";
|
| 249 |
+
if (ratioFace > 1.35) faceText = "Oval / Heart";
|
| 250 |
+
else if (ratioFace > 1.20) faceText = "Kotak / Simetris";
|
| 251 |
|
| 252 |
+
// 2. Bentuk Rahang
|
| 253 |
const ratioJaw = jawWidth / faceWidth;
|
| 254 |
+
let jawText = "Tirus / V-Shape";
|
| 255 |
+
if (ratioJaw > 0.85) jawText = "Square-Strong";
|
| 256 |
+
else if (ratioJaw > 0.75) jawText = "Tapered / Normal";
|
| 257 |
|
| 258 |
+
// 3. Karakter Alis
|
| 259 |
const ratioEyebrow = getDistance(alisKiri, alisKiriTengah) / faceHeight;
|
| 260 |
+
let browText = "Datar / Straight";
|
| 261 |
+
if (ratioEyebrow > 0.055) browText = "Arched-High";
|
| 262 |
+
else if (ratioEyebrow > 0.040) browText = "Melengkung Alami";
|
| 263 |
|
| 264 |
// 4. Mood
|
| 265 |
const mouthWidth = getDistance(faceLandmarks[61], faceLandmarks[291]);
|
|
|
|
| 268 |
if (mouthHeight / faceWidth > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 269 |
else if (mouthWidth / faceWidth > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 270 |
|
| 271 |
+
// 5. Gender & Logika Hijab
|
| 272 |
const headRatio = getDistance(dahi, faceLandmarks[168]) / jawWidth;
|
| 273 |
let genderText = "Pria 👨"; let genderColor = "#60a5fa";
|
| 274 |
if (headRatio < 0.22 || ratioJaw < 0.75) {
|
| 275 |
+
genderText = "Wanita 👩 (Hijab/Tirus)"; genderColor = "#f472b6";
|
| 276 |
}
|
| 277 |
|
| 278 |
return { faceText, jawText, browText, moodText, moodColor, genderText, genderColor };
|
| 279 |
}
|
| 280 |
|
| 281 |
+
// --- ALGORITMA POSE JARI ---
|
| 282 |
function classifyPose(landmarks) {
|
| 283 |
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 284 |
const middleOpen = landmarks[12].y < landmarks[10].y;
|
|
|
|
| 286 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 287 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 288 |
|
| 289 |
+
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "Fist" };
|
| 290 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "Open Palm" };
|
| 291 |
+
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "Peace" };
|
| 292 |
+
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "Thumbs Up" };
|
| 293 |
+
if (getDistance(landmarks[4], landmarks[8]) < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "Okay" };
|
| 294 |
+
|
| 295 |
return null;
|
| 296 |
}
|
| 297 |
|
|
|
|
| 310 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 311 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 312 |
|
| 313 |
+
// --- RENDER WAJAH ---
|
| 314 |
if (currentFaceLandmarks) {
|
| 315 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 316 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
| 332 |
}
|
| 333 |
|
| 334 |
let currentIds = [];
|
| 335 |
+
anims.forEach(a => a.style.opacity = '0'); // Reset GIF
|
| 336 |
+
poseBoxes.forEach(b => b.classList.remove('active')); // Reset Lampu Indikator
|
| 337 |
|
| 338 |
+
// --- RENDER TANGAN & AKTIFKAN INDIKATOR POSE ---
|
| 339 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 340 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 341 |
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: index === 0 ? '#ec4899' : '#06b6d4', lineWidth: 4});
|
| 342 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 343 |
|
| 344 |
+
let pose = classifyPose(landmarks);
|
| 345 |
+
if (pose) {
|
| 346 |
+
currentIds.push(pose.id);
|
| 347 |
+
|
| 348 |
+
// Menyalakan kotak di bawah layar
|
| 349 |
+
poseBoxes[pose.id - 1].classList.add('active');
|
| 350 |
|
| 351 |
+
// Menampilkan GIF di atas tangan (Khusus Thumbs Up/L-Shape)
|
| 352 |
+
if (pose.id === 1 && anims[index]) {
|
| 353 |
const wrist = landmarks[0];
|
| 354 |
anims[index].style.opacity = '1';
|
| 355 |
anims[index].style.left = `${((1 - wrist.x) * canvasElement.width) - 75}px`;
|
|
|
|
| 361 |
}
|
| 362 |
canvasCtx.restore();
|
| 363 |
|
| 364 |
+
// --- LOGIKA AUDIO & STATUS SISTEM ---
|
| 365 |
if (currentIds.length > 0) {
|
| 366 |
statusKiri.textContent = "Aktif & Responsif 🟢"; statusKiri.style.color = "#10b981";
|
| 367 |
|
|
|
|
| 376 |
memoryTimer = Date.now();
|
| 377 |
} else {
|
| 378 |
if (Date.now() - memoryTimer > 500) {
|
| 379 |
+
statusKiri.textContent = "Menunggu Gerakan Jari 🟡"; statusKiri.style.color = "#eab308";
|
| 380 |
memoryActivePoses = [];
|
| 381 |
}
|
| 382 |
}
|