Spaces:
Running
Running
Update index.html
Browse files- index.html +81 -43
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>
|
| 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>
|
|
@@ -81,31 +81,36 @@
|
|
| 81 |
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 82 |
pointer-events: none;
|
| 83 |
transition: transform 0.1s linear;
|
| 84 |
-
transform: scaleX(-1);
|
| 85 |
}
|
| 86 |
|
| 87 |
-
/* --- STYLING PANEL
|
| 88 |
-
#
|
| 89 |
position: absolute;
|
| 90 |
-
top:
|
| 91 |
-
right:
|
| 92 |
background: rgba(15, 23, 42, 0.85);
|
| 93 |
border: 2px solid #3b82f6;
|
| 94 |
-
padding:
|
| 95 |
border-radius: 12px;
|
| 96 |
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
|
| 97 |
z-index: 20;
|
| 98 |
backdrop-filter: blur(5px);
|
| 99 |
transition: border-color 0.3s, box-shadow 0.3s;
|
|
|
|
| 100 |
}
|
| 101 |
-
.
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
</style>
|
| 104 |
</head>
|
| 105 |
<body>
|
| 106 |
|
| 107 |
-
<h2>🤖 AI Vision:
|
| 108 |
-
<p>
|
| 109 |
|
| 110 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 111 |
|
|
@@ -114,10 +119,15 @@
|
|
| 114 |
</div>
|
| 115 |
|
| 116 |
<div class="monitor-container">
|
| 117 |
-
<!-- Floating Panel
|
| 118 |
-
<div id="
|
| 119 |
-
<div class="
|
| 120 |
-
<div id="moodValue">Menganalisis...</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
</div>
|
| 122 |
|
| 123 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
|
@@ -127,7 +137,6 @@
|
|
| 127 |
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 128 |
</div>
|
| 129 |
|
| 130 |
-
<!-- Audio -->
|
| 131 |
<audio id="audio1" src="suara1.mp3"></audio>
|
| 132 |
<audio id="audio2" src="suara2.mp3"></audio>
|
| 133 |
<audio id="audio3" src="suara3.mp3"></audio>
|
|
@@ -141,8 +150,9 @@
|
|
| 141 |
const startBtn = document.getElementById('startBtn');
|
| 142 |
const statusPose = document.getElementById('statusPose');
|
| 143 |
|
| 144 |
-
const
|
| 145 |
const moodValue = document.getElementById('moodValue');
|
|
|
|
| 146 |
|
| 147 |
const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
|
| 148 |
const sounds = [
|
|
@@ -158,9 +168,9 @@
|
|
| 158 |
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 159 |
}
|
| 160 |
|
| 161 |
-
// --- FUNGSI ANALISIS MOOD
|
| 162 |
-
function
|
| 163 |
-
//
|
| 164 |
const leftMouth = faceLandmarks[61];
|
| 165 |
const rightMouth = faceLandmarks[291];
|
| 166 |
const topLip = faceLandmarks[13];
|
|
@@ -168,22 +178,43 @@
|
|
| 168 |
const leftEye = faceLandmarks[33];
|
| 169 |
const rightEye = faceLandmarks[263];
|
| 170 |
|
| 171 |
-
// Hitung lebar, tinggi mulut, dan skala wajah (lebar mata)
|
| 172 |
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 173 |
const mouthHeight = getDistance(topLip, bottomLip);
|
| 174 |
const faceScale = getDistance(leftEye, rightEye);
|
| 175 |
|
| 176 |
-
// Cari rasio agar akurat tidak peduli jarak wajah ke kamera
|
| 177 |
const smileRatio = mouthWidth / faceScale;
|
| 178 |
const openRatio = mouthHeight / faceScale;
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
} else {
|
| 185 |
-
|
|
|
|
| 186 |
}
|
|
|
|
|
|
|
| 187 |
}
|
| 188 |
|
| 189 |
function classifyPose(landmarks) {
|
|
@@ -194,12 +225,12 @@
|
|
| 194 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 195 |
|
| 196 |
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
|
| 197 |
-
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak
|
| 198 |
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 199 |
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
| 200 |
|
| 201 |
const thumbIndexTipDist = getDistance(landmarks[4], landmarks[8]);
|
| 202 |
-
if (thumbIndexTipDist < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "👌
|
| 203 |
|
| 204 |
return null;
|
| 205 |
}
|
|
@@ -256,27 +287,34 @@
|
|
| 256 |
}
|
| 257 |
canvasCtx.restore();
|
| 258 |
|
| 259 |
-
// --- LOGIKA UPDATE
|
| 260 |
|
| 261 |
-
// 1. Update Panel Mood
|
| 262 |
if (currentFaceLandmarks) {
|
| 263 |
-
let
|
| 264 |
|
| 265 |
-
// GABUNGAN WAJAH & TANGAN: Jika senyum + pose positif
|
| 266 |
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 267 |
-
if (
|
| 268 |
-
|
| 269 |
-
|
| 270 |
}
|
| 271 |
|
| 272 |
-
|
| 273 |
-
moodValue.
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
} else {
|
| 277 |
-
moodValue.textContent = "Wajah
|
| 278 |
-
|
| 279 |
-
|
| 280 |
}
|
| 281 |
|
| 282 |
// 2. Update Teks Tangan & Animasi GIF
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>AI Vision - v18 Biometric Scanner</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>
|
|
|
|
| 81 |
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 82 |
pointer-events: none;
|
| 83 |
transition: transform 0.1s linear;
|
| 84 |
+
transform: scaleX(-1);
|
| 85 |
}
|
| 86 |
|
| 87 |
+
/* --- STYLING PANEL BIOMETRIC SCANNER --- */
|
| 88 |
+
#biometricContainer {
|
| 89 |
position: absolute;
|
| 90 |
+
top: 15px;
|
| 91 |
+
right: 15px;
|
| 92 |
background: rgba(15, 23, 42, 0.85);
|
| 93 |
border: 2px solid #3b82f6;
|
| 94 |
+
padding: 15px;
|
| 95 |
border-radius: 12px;
|
| 96 |
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
|
| 97 |
z-index: 20;
|
| 98 |
backdrop-filter: blur(5px);
|
| 99 |
transition: border-color 0.3s, box-shadow 0.3s;
|
| 100 |
+
min-width: 150px;
|
| 101 |
}
|
| 102 |
+
.bio-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; margin-bottom: 2px;}
|
| 103 |
+
.bio-label:first-child { margin-top: 0; }
|
| 104 |
+
.bio-value { font-size: 18px; font-weight: bold; color: #f8fafc; }
|
| 105 |
+
|
| 106 |
+
/* Garis pemisah kecil di panel */
|
| 107 |
+
.divider { height: 1px; background-color: #334155; margin: 8px 0; }
|
| 108 |
</style>
|
| 109 |
</head>
|
| 110 |
<body>
|
| 111 |
|
| 112 |
+
<h2>🤖 AI Vision: Biometric Analytics</h2>
|
| 113 |
+
<p>Deteksi Pose, Mood, dan Proporsi Gender Real-Time v18</p>
|
| 114 |
|
| 115 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 116 |
|
|
|
|
| 119 |
</div>
|
| 120 |
|
| 121 |
<div class="monitor-container">
|
| 122 |
+
<!-- Floating Panel Biometric Baru -->
|
| 123 |
+
<div id="biometricContainer">
|
| 124 |
+
<div class="bio-label">Kondisi Mood</div>
|
| 125 |
+
<div id="moodValue" class="bio-value">Menganalisis...</div>
|
| 126 |
+
|
| 127 |
+
<div class="divider"></div>
|
| 128 |
+
|
| 129 |
+
<div class="bio-label">Estimasi Anatomi</div>
|
| 130 |
+
<div id="genderValue" class="bio-value" style="color: #cbd5e1;">Memindai...</div>
|
| 131 |
</div>
|
| 132 |
|
| 133 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
|
|
|
| 137 |
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 138 |
</div>
|
| 139 |
|
|
|
|
| 140 |
<audio id="audio1" src="suara1.mp3"></audio>
|
| 141 |
<audio id="audio2" src="suara2.mp3"></audio>
|
| 142 |
<audio id="audio3" src="suara3.mp3"></audio>
|
|
|
|
| 150 |
const startBtn = document.getElementById('startBtn');
|
| 151 |
const statusPose = document.getElementById('statusPose');
|
| 152 |
|
| 153 |
+
const biometricContainer = document.getElementById('biometricContainer');
|
| 154 |
const moodValue = document.getElementById('moodValue');
|
| 155 |
+
const genderValue = document.getElementById('genderValue');
|
| 156 |
|
| 157 |
const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
|
| 158 |
const sounds = [
|
|
|
|
| 168 |
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 169 |
}
|
| 170 |
|
| 171 |
+
// --- FUNGSI ANALISIS WAJAH (MOOD & GENDER) ---
|
| 172 |
+
function analyzeFaceBiometrics(faceLandmarks) {
|
| 173 |
+
// 1. Analisis Mood (Senyum & Mulut Terbuka)
|
| 174 |
const leftMouth = faceLandmarks[61];
|
| 175 |
const rightMouth = faceLandmarks[291];
|
| 176 |
const topLip = faceLandmarks[13];
|
|
|
|
| 178 |
const leftEye = faceLandmarks[33];
|
| 179 |
const rightEye = faceLandmarks[263];
|
| 180 |
|
|
|
|
| 181 |
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 182 |
const mouthHeight = getDistance(topLip, bottomLip);
|
| 183 |
const faceScale = getDistance(leftEye, rightEye);
|
| 184 |
|
|
|
|
| 185 |
const smileRatio = mouthWidth / faceScale;
|
| 186 |
const openRatio = mouthHeight / faceScale;
|
| 187 |
|
| 188 |
+
let moodText = "Netral 😐"; let moodColor = "#3b82f6";
|
| 189 |
+
if (openRatio > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 190 |
+
else if (smileRatio > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 191 |
+
|
| 192 |
+
// 2. Analisis Estimasi Gender (Rasio Tulang Pipi vs Rahang)
|
| 193 |
+
const leftCheek = faceLandmarks[234];
|
| 194 |
+
const rightCheek = faceLandmarks[454];
|
| 195 |
+
const leftJaw = faceLandmarks[132];
|
| 196 |
+
const rightJaw = faceLandmarks[361];
|
| 197 |
+
|
| 198 |
+
const cheekWidth = getDistance(leftCheek, rightCheek);
|
| 199 |
+
const jawWidth = getDistance(leftJaw, rightJaw);
|
| 200 |
+
|
| 201 |
+
// Rumus Logika: Pria cenderung memiliki rahang yang lebih seimbang dengan pipi (lebar)
|
| 202 |
+
// Wanita cenderung memiliki rahang lebih tirus (rasio lebih kecil)
|
| 203 |
+
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 204 |
+
|
| 205 |
+
let genderText = "Memindai..."; let genderColor = "#cbd5e1";
|
| 206 |
+
|
| 207 |
+
// Nilai treshold 0.76 ini adalah estimasi matematis.
|
| 208 |
+
// Wajah yang rahangnya lebar (>0.76 dari pipi) diasumsikan maskulin.
|
| 209 |
+
if (jawToCheekRatio > 0.755) {
|
| 210 |
+
genderText = "Pria 👨";
|
| 211 |
+
genderColor = "#60a5fa"; // Biru Pria
|
| 212 |
} else {
|
| 213 |
+
genderText = "Wanita 👩";
|
| 214 |
+
genderColor = "#f472b6"; // Pink Wanita
|
| 215 |
}
|
| 216 |
+
|
| 217 |
+
return { moodText, moodColor, genderText, genderColor };
|
| 218 |
}
|
| 219 |
|
| 220 |
function classifyPose(landmarks) {
|
|
|
|
| 225 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 226 |
|
| 227 |
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
|
| 228 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak", color: "#3b82f6" };
|
| 229 |
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 230 |
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
| 231 |
|
| 232 |
const thumbIndexTipDist = getDistance(landmarks[4], landmarks[8]);
|
| 233 |
+
if (thumbIndexTipDist < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "👌 Okay", color: "#10b981" };
|
| 234 |
|
| 235 |
return null;
|
| 236 |
}
|
|
|
|
| 287 |
}
|
| 288 |
canvasCtx.restore();
|
| 289 |
|
| 290 |
+
// --- LOGIKA UPDATE BIOMETRIC & POSE ---
|
| 291 |
|
| 292 |
+
// 1. Update Panel Biometric (Mood & Gender)
|
| 293 |
if (currentFaceLandmarks) {
|
| 294 |
+
let bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
| 295 |
|
| 296 |
+
// GABUNGAN WAJAH & TANGAN: Jika senyum + pose positif
|
| 297 |
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 298 |
+
if (bio.moodText === "Senang 😊" && isPositivePose) {
|
| 299 |
+
bio.moodText = "Sangat Senang! ✨";
|
| 300 |
+
bio.moodColor = "#eab308";
|
| 301 |
}
|
| 302 |
|
| 303 |
+
// Update UI Mood
|
| 304 |
+
moodValue.textContent = bio.moodText;
|
| 305 |
+
moodValue.style.color = bio.moodColor;
|
| 306 |
+
|
| 307 |
+
// Update UI Gender
|
| 308 |
+
genderValue.textContent = bio.genderText;
|
| 309 |
+
genderValue.style.color = bio.genderColor;
|
| 310 |
+
|
| 311 |
+
// Animasi Box Panel
|
| 312 |
+
biometricContainer.style.borderColor = bio.moodColor;
|
| 313 |
+
biometricContainer.style.boxShadow = `0 0 15px ${bio.moodColor}80`;
|
| 314 |
} else {
|
| 315 |
+
moodValue.textContent = "Wajah Hilang"; moodValue.style.color = "#94a3b8";
|
| 316 |
+
genderValue.textContent = "Wajah Hilang"; genderValue.style.color = "#94a3b8";
|
| 317 |
+
biometricContainer.style.borderColor = "#334155";
|
| 318 |
}
|
| 319 |
|
| 320 |
// 2. Update Teks Tangan & Animasi GIF
|