Spaces:
Running
Running
Update index.html
Browse files- index.html +184 -253
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/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
|
@@ -15,174 +15,95 @@
|
|
| 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, #
|
| 26 |
-
color: white; border: none; padding: 15px
|
| 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
|
| 30 |
}
|
| 31 |
#startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
}
|
| 38 |
-
|
| 39 |
-
.dashboard-container {
|
| 40 |
-
display: flex; flex-direction: row; gap: 25px;
|
| 41 |
-
align-items: flex-start; justify-content: center;
|
| 42 |
-
width: 100%; max-width: 1300px;
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
/* PANEL KIRI & KANAN */
|
| 46 |
-
.side-panel {
|
| 47 |
-
background: rgba(15, 23, 42, 0.7);
|
| 48 |
-
border: 2px solid #3b82f6; border-radius: 12px;
|
| 49 |
-
padding: 20px; width: 260px;
|
| 50 |
-
box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
|
| 51 |
-
backdrop-filter: blur(10px);
|
| 52 |
-
display: flex; flex-direction: column; gap: 15px;
|
| 53 |
-
}
|
| 54 |
-
.side-panel.pink-border { border-color: #ec4899; box-shadow: 0 0 20px rgba(236, 72, 153, 0.3); }
|
| 55 |
-
|
| 56 |
-
.panel-title { font-size: 12px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #334155; padding-bottom: 8px; margin-bottom: 5px; }
|
| 57 |
-
.data-item { display: flex; flex-direction: column; gap: 4px; }
|
| 58 |
-
.data-label { font-size: 14px; font-weight: bold; color: #f8fafc; }
|
| 59 |
-
.data-value { font-size: 13px; color: #10b981; }
|
| 60 |
-
|
| 61 |
-
/* --- PERBAIKAN MONITOR TENGAH (OVERLAY KACA TRANSPARAN) --- */
|
| 62 |
-
.center-stage { display: flex; flex-direction: column; align-items: center; gap: 20px; }
|
| 63 |
|
| 64 |
-
.
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
border: 3px solid #
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
overflow: hidden; /* Cegah video meluber */
|
| 71 |
-
background-color: #000;
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
/* Video aslinya sekarang DIMUNCULKAN di layar */
|
| 75 |
-
#videoElement {
|
| 76 |
-
position: absolute; top: 0; left: 0;
|
| 77 |
-
width: 100%; height: 100%; object-fit: cover;
|
| 78 |
-
transform: scaleX(-1); z-index: 1;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/* Kanvasnya dibuat TRANSPARAN di atas video */
|
| 82 |
-
#outputCanvas {
|
| 83 |
-
position: absolute; top: 0; left: 0;
|
| 84 |
-
width: 100%; height: 100%; object-fit: cover;
|
| 85 |
-
transform: scaleX(-1); z-index: 2;
|
| 86 |
-
background-color: transparent; /* PENTING! */
|
| 87 |
}
|
| 88 |
-
|
| 89 |
.pose1-anim {
|
| 90 |
position: absolute; opacity: 0; border-radius: 8px; z-index: 10;
|
| 91 |
border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 92 |
-
pointer-events: none; transition: opacity 0.2s, left 0.1s, top 0.1s;
|
| 93 |
transform: scaleX(-1);
|
| 94 |
}
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
width: 85px; display: flex; flex-direction: column; align-items: center; justify-content: center;
|
| 102 |
-
transition: all 0.2s ease; opacity: 0.6;
|
| 103 |
-
}
|
| 104 |
-
.pose-emoji { font-size: 26px; margin-bottom: 8px; }
|
| 105 |
-
.pose-name { font-size: 12px; font-weight: bold; color: #64748b; transition: color 0.2s; }
|
| 106 |
-
.pose-box.active {
|
| 107 |
-
border: 2px solid #eab308; background: rgba(234, 179, 8, 0.1);
|
| 108 |
-
box-shadow: 0 0 15px rgba(234, 179, 8, 0.5); opacity: 1; transform: scale(1.05);
|
| 109 |
}
|
| 110 |
-
.
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
</style>
|
| 113 |
</head>
|
| 114 |
-
<body>
|
| 115 |
|
| 116 |
-
<h2>🤖 AI Vision:
|
| 117 |
-
<p>
|
| 118 |
|
| 119 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
<div class="
|
| 128 |
-
<div
|
| 129 |
-
<div class="
|
| 130 |
-
<div class="
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
</
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
<img id="pose1Anim1" class="pose1-anim" src="animasi1.gif">
|
| 142 |
-
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif">
|
| 143 |
-
</div>
|
| 144 |
-
|
| 145 |
-
<div class="pose-indicators">
|
| 146 |
-
<div id="boxPose1" class="pose-box"><div class="pose-emoji">👍</div><div class="pose-name">Thumbs Up</div></div>
|
| 147 |
-
<div id="boxPose2" class="pose-box"><div class="pose-emoji">✌️</div><div class="pose-name">Peace</div></div>
|
| 148 |
-
<div id="boxPose3" class="pose-box"><div class="pose-emoji">👌</div><div class="pose-name">Okay</div></div>
|
| 149 |
-
<div id="boxPose4" class="pose-box"><div class="pose-emoji">🖐️</div><div class="pose-name">Open Palm</div></div>
|
| 150 |
-
<div id="boxPose5" class="pose-box"><div class="pose-emoji">✊</div><div class="pose-name">Fist</div></div>
|
| 151 |
-
</div>
|
| 152 |
-
</div>
|
| 153 |
-
|
| 154 |
-
<div style="display: flex; flex-direction: column; gap: 20px;">
|
| 155 |
-
<div class="side-panel">
|
| 156 |
-
<div class="panel-title">Kondisi Biometrik (Wajah)</div>
|
| 157 |
-
<div class="data-item"><div class="data-label">Bentuk Wajah</div><div id="valWajah" class="data-value" style="color: #cbd5e1;">Memindai...</div></div>
|
| 158 |
-
<div class="data-item"><div class="data-label">Bentuk Rahang</div><div id="valRahang" class="data-value" style="color: #cbd5e1;">Memindai...</div></div>
|
| 159 |
-
<div class="data-item"><div class="data-label">Karakter Alis</div><div id="valAlis" class="data-value" style="color: #cbd5e1;">Memindai...</div></div>
|
| 160 |
-
</div>
|
| 161 |
-
|
| 162 |
-
<div class="side-panel pink-border">
|
| 163 |
-
<div class="data-item"><div class="panel-title">Kondisi Mood</div><div id="moodValue" class="data-label" style="font-size: 18px;">Menganalisis...</div></div>
|
| 164 |
-
<div class="data-item" style="margin-top: 10px;"><div class="panel-title">Estimasi Gender / Hijab</div><div id="genderValue" class="data-label" style="font-size: 18px;">Memindai...</div></div>
|
| 165 |
-
</div>
|
| 166 |
-
</div>
|
| 167 |
-
</div>
|
| 168 |
-
|
| 169 |
<audio id="audio1" src="suara1.mp3"></audio>
|
| 170 |
<audio id="audio2" src="suara2.mp3"></audio>
|
| 171 |
<audio id="audio3" src="suara3.mp3"></audio>
|
| 172 |
<audio id="audio4" src="suara4.mp3"></audio>
|
| 173 |
<audio id="audio5" src="suara5.mp3"></audio>
|
| 174 |
-
|
| 175 |
<script>
|
| 176 |
const videoElement = document.getElementById('videoElement');
|
| 177 |
const canvasElement = document.getElementById('outputCanvas');
|
| 178 |
const canvasCtx = canvasElement.getContext('2d');
|
| 179 |
const startBtn = document.getElementById('startBtn');
|
| 180 |
-
const
|
| 181 |
-
const
|
| 182 |
-
|
| 183 |
-
const valWajah = document.getElementById('valWajah');
|
| 184 |
-
const valRahang = document.getElementById('valRahang');
|
| 185 |
-
const valAlis = document.getElementById('valAlis');
|
| 186 |
const moodValue = document.getElementById('moodValue');
|
| 187 |
const genderValue = document.getElementById('genderValue');
|
| 188 |
|
|
@@ -192,56 +113,46 @@
|
|
| 192 |
document.getElementById('audio3'), document.getElementById('audio4'),
|
| 193 |
document.getElementById('audio5')
|
| 194 |
];
|
| 195 |
-
const poseBoxes = [
|
| 196 |
-
document.getElementById('boxPose1'), document.getElementById('boxPose2'),
|
| 197 |
-
document.getElementById('boxPose3'), document.getElementById('boxPose4'),
|
| 198 |
-
document.getElementById('boxPose5')
|
| 199 |
-
];
|
| 200 |
|
| 201 |
let memoryActivePoses = [];
|
| 202 |
let memoryTimer = 0;
|
| 203 |
let currentFaceLandmarks = null;
|
| 204 |
|
| 205 |
-
function getDistance(p1, p2) {
|
|
|
|
|
|
|
| 206 |
|
| 207 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 208 |
-
const
|
| 209 |
-
const
|
| 210 |
-
const
|
| 211 |
-
const alisKiri = faceLandmarks[159]; const alisKiriTengah = faceLandmarks[52];
|
| 212 |
|
| 213 |
-
const
|
| 214 |
-
const
|
| 215 |
-
const
|
|
|
|
|
|
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
if (
|
| 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
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
|
|
|
| 231 |
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
let moodText = "Netral 😐"; let moodColor = "#3b82f6";
|
| 235 |
-
if (mouthHeight / faceWidth > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
|
| 236 |
-
else if (mouthWidth / faceWidth > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
genderText =
|
| 242 |
}
|
| 243 |
|
| 244 |
-
return {
|
| 245 |
}
|
| 246 |
|
| 247 |
function classifyPose(landmarks) {
|
|
@@ -251,136 +162,156 @@
|
|
| 251 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 252 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 253 |
|
| 254 |
-
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "
|
| 255 |
-
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "
|
| 256 |
-
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "
|
| 257 |
-
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "
|
| 258 |
-
if (getDistance(landmarks[4], landmarks[8]) < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "Okay" };
|
| 259 |
|
|
|
|
| 260 |
return null;
|
| 261 |
}
|
| 262 |
|
| 263 |
-
// AI
|
| 264 |
-
const faceMesh = new FaceMesh({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`});
|
| 265 |
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 266 |
-
faceMesh.onResults((
|
| 267 |
-
currentFaceLandmarks = (
|
| 268 |
});
|
| 269 |
|
| 270 |
-
|
|
|
|
| 271 |
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 272 |
-
|
| 273 |
hands.onResults((results) => {
|
| 274 |
-
|
| 275 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
|
|
|
| 276 |
|
| 277 |
-
// Render Wajah & Update Teks
|
| 278 |
if (currentFaceLandmarks) {
|
| 279 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 280 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
| 281 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
|
|
|
| 282 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 283 |
-
|
| 284 |
-
const bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
| 285 |
-
valWajah.textContent = bio.faceText; valWajah.style.color = "#10b981";
|
| 286 |
-
valRahang.textContent = bio.jawText; valRahang.style.color = "#10b981";
|
| 287 |
-
valAlis.textContent = bio.browText; valAlis.style.color = "#10b981";
|
| 288 |
-
moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
|
| 289 |
-
genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
|
| 290 |
-
} else {
|
| 291 |
-
valWajah.textContent = "Wajah Hilang"; valWajah.style.color = "#cbd5e1";
|
| 292 |
-
valRahang.textContent = "Wajah Hilang"; valRahang.style.color = "#cbd5e1";
|
| 293 |
-
valAlis.textContent = "Wajah Hilang"; valAlis.style.color = "#cbd5e1";
|
| 294 |
-
moodValue.textContent = "Menganalisis..."; moodValue.style.color = "#f8fafc";
|
| 295 |
-
genderValue.textContent = "Memindai..."; genderValue.style.color = "#f8fafc";
|
| 296 |
}
|
| 297 |
|
| 298 |
-
let
|
| 299 |
anims.forEach(a => a.style.opacity = '0');
|
| 300 |
-
poseBoxes.forEach(b => b.classList.remove('active'));
|
| 301 |
|
| 302 |
-
// Render Tangan & Lampu Pose
|
| 303 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 304 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 305 |
-
|
|
|
|
| 306 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 307 |
|
| 308 |
let pose = classifyPose(landmarks);
|
| 309 |
-
if (pose) {
|
| 310 |
-
currentIds.push(pose.id);
|
| 311 |
-
poseBoxes[pose.id - 1].classList.add('active');
|
| 312 |
-
|
| 313 |
-
if (pose.id === 1 && anims[index]) {
|
| 314 |
-
const wrist = landmarks[0];
|
| 315 |
-
anims[index].style.opacity = '1';
|
| 316 |
-
anims[index].style.left = `${((1 - wrist.x) * canvasElement.width) - 75}px`;
|
| 317 |
-
anims[index].style.top = `${(wrist.y * canvasElement.height) + 30}px`;
|
| 318 |
-
anims[index].style.width = `150px`;
|
| 319 |
-
}
|
| 320 |
-
}
|
| 321 |
});
|
| 322 |
}
|
|
|
|
| 323 |
|
| 324 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
if (currentIds.length > 0) {
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
|
| 328 |
if (newPoses.length > 0) {
|
|
|
|
| 329 |
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 330 |
-
const soundToPlay = sounds[
|
| 331 |
if (soundToPlay) soundToPlay.play();
|
| 332 |
}
|
| 333 |
memoryActivePoses = currentIds;
|
| 334 |
memoryTimer = Date.now();
|
| 335 |
-
} else
|
| 336 |
-
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
| 338 |
}
|
| 339 |
});
|
| 340 |
|
| 341 |
-
// CAMERA ENGINE
|
| 342 |
startBtn.addEventListener('click', async () => {
|
| 343 |
startBtn.style.display = 'none';
|
| 344 |
-
|
| 345 |
-
mainStatus.style.color = "#eab308";
|
| 346 |
|
|
|
|
| 347 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 348 |
|
| 349 |
-
try {
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
| 352 |
|
| 353 |
-
videoElement.
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
-
//
|
| 357 |
-
|
| 358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
-
//
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
}
|
| 373 |
-
}
|
| 374 |
-
requestAnimationFrame(processFrame);
|
| 375 |
-
}
|
| 376 |
-
processFrame();
|
| 377 |
-
};
|
| 378 |
-
} catch (error) {
|
| 379 |
-
alert("GAGAL AKSES KAMERA!\nBrowser memblokir kamera. Tolong klik icon gembok di sebelah URL / berikan izin 'Allow Camera'.\n\nDetail: " + error.message);
|
| 380 |
-
mainStatus.textContent = "Kamera Terblokir 🔴";
|
| 381 |
-
mainStatus.style.color = "#ef4444";
|
| 382 |
-
startBtn.style.display = 'block';
|
| 383 |
-
}
|
| 384 |
});
|
| 385 |
</script>
|
| 386 |
</body>
|
|
|
|
| 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>
|
|
|
|
| 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 |
|
|
|
|
| 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) {
|
|
|
|
| 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>
|