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 |
+
<html lang="id">
|
| 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>
|
| 11 |
+
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js" crossorigin="anonymous"></script>
|
| 12 |
+
|
| 13 |
+
<style>
|
| 14 |
+
body {
|
| 15 |
+
background: radial-gradient(circle at top, #1e293b, #0f172a);
|
| 16 |
+
color: #f8fafc;
|
| 17 |
+
font-family: 'Segoe UI', 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; border: none; padding: 15px 35px;
|
| 32 |
+
font-size: 18px; border-radius: 50px; cursor: pointer;
|
| 33 |
+
font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 34 |
+
transition: all 0.3s ease; margin: 20px 0; text-transform: uppercase;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
#startBtn:hover {
|
| 38 |
+
transform: translateY(-3px);
|
| 39 |
+
box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6);
|
| 40 |
+
background: linear-gradient(135deg, #f472b6, #a78bfa);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
#statusContainer {
|
| 44 |
+
background: rgba(15, 23, 42, 0.8); border: 1px solid #334155;
|
| 45 |
+
padding: 15px 30px; border-radius: 12px; margin-bottom: 20px;
|
| 46 |
+
min-width: 300px; text-align: center; box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#statusPose { font-size: 24px; font-weight: bold; color: #94a3b8; transition: color 0.3s; }
|
| 50 |
+
|
| 51 |
+
.monitor-container { position: relative; }
|
| 52 |
+
|
| 53 |
+
canvas {
|
| 54 |
+
border: 3px solid #3b82f6; box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
|
| 55 |
+
border-radius: 16px; background-color: #000; width: 640px; height: 480px;
|
| 56 |
+
max-width: 90vw; object-fit: cover; transform: scaleX(-1);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* PERBAIKAN CSS: Animasi GIF Transisi Halus (Anti-Blink) */
|
| 60 |
+
.pose1-anim {
|
| 61 |
+
position: absolute; opacity: 0; border-radius: 8px; z-index: 10;
|
| 62 |
+
border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 63 |
+
pointer-events: none; transition: opacity 0.2s ease-in-out, left 0.1s linear, top 0.1s linear;
|
| 64 |
+
transform: scaleX(-1);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
#biometricContainer {
|
| 68 |
+
position: absolute; top: 15px; right: 15px;
|
| 69 |
+
background: rgba(15, 23, 42, 0.85); border: 2px solid #3b82f6;
|
| 70 |
+
padding: 15px; border-radius: 12px; box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
|
| 71 |
+
z-index: 20; backdrop-filter: blur(5px); transition: border-color 0.3s, box-shadow 0.3s; min-width: 150px;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.bio-label { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; margin-bottom: 2px;}
|
| 75 |
+
.bio-label:first-child { margin-top: 0; }
|
| 76 |
+
.bio-value { font-size: 18px; font-weight: bold; color: #f8fafc; }
|
| 77 |
+
.divider { height: 1px; background-color: #334155; margin: 8px 0; }
|
| 78 |
+
</style>
|
| 79 |
+
</head>
|
| 80 |
+
<body>
|
| 81 |
+
|
| 82 |
+
<h2>🤖 AI Vision: Smooth Tracking By Rizki Ardiansyah</h2>
|
| 83 |
+
<p>Algoritma Debounce untuk Audio & Visual v19</p>
|
| 84 |
+
|
| 85 |
+
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 86 |
+
|
| 87 |
+
<div id="statusContainer">
|
| 88 |
+
<div id="statusPose">Menunggu Kamera...</div>
|
| 89 |
+
</div>
|
| 90 |
+
|
| 91 |
+
<div class="monitor-container">
|
| 92 |
+
<div id="biometricContainer">
|
| 93 |
+
<div class="bio-label">Kondisi Mood</div>
|
| 94 |
+
<div id="moodValue" class="bio-value">Menganalisis...</div>
|
| 95 |
+
<div class="divider"></div>
|
| 96 |
+
<div class="bio-label">Estimasi Anatomi</div>
|
| 97 |
+
<div id="genderValue" class="bio-value" style="color: #cbd5e1;">Memindai...</div>
|
| 98 |
+
</div>
|
| 99 |
+
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
| 100 |
+
<canvas id="outputCanvas" width="640" height="480"></canvas>
|
| 101 |
+
<img id="pose1Anim1" class="pose1-anim" src="animasi1.gif" alt="Pose 1">
|
| 102 |
+
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<audio id="audio1" src="suara1.mp3"></audio>
|
| 106 |
+
<audio id="audio2" src="suara2.mp3"></audio>
|
| 107 |
+
<audio id="audio3" src="suara3.mp3"></audio>
|
| 108 |
+
<audio id="audio4" src="suara4.mp3"></audio>
|
| 109 |
+
<audio id="audio5" src="suara5.mp3"></audio>
|
| 110 |
+
|
| 111 |
+
<script>
|
| 112 |
+
const videoElement = document.getElementById('videoElement');
|
| 113 |
+
const canvasElement = document.getElementById('outputCanvas');
|
| 114 |
+
const canvasCtx = canvasElement.getContext('2d');
|
| 115 |
+
const startBtn = document.getElementById('startBtn');
|
| 116 |
+
const statusPose = document.getElementById('statusPose');
|
| 117 |
+
const biometricContainer = document.getElementById('biometricContainer');
|
| 118 |
+
const moodValue = document.getElementById('moodValue');
|
| 119 |
+
const genderValue = document.getElementById('genderValue');
|
| 120 |
+
|
| 121 |
+
const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
|
| 122 |
+
const sounds = [
|
| 123 |
+
document.getElementById('audio1'), document.getElementById('audio2'),
|
| 124 |
+
document.getElementById('audio3'), document.getElementById('audio4'),
|
| 125 |
+
document.getElementById('audio5')
|
| 126 |
+
];
|
| 127 |
+
|
| 128 |
+
// VARIABEL MEMORI (ANTI-LAG & ANTI-STUTTER)
|
| 129 |
+
let memoryActivePoses = [];
|
| 130 |
+
let memoryTimer = 0;
|
| 131 |
+
let currentFaceLandmarks = null;
|
| 132 |
+
|
| 133 |
+
function getDistance(p1, p2) {
|
| 134 |
+
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
function analyzeFaceBiometrics(faceLandmarks) {
|
| 138 |
+
// 1. Analisis Mood
|
| 139 |
+
const leftMouth = faceLandmarks[61]; const rightMouth = faceLandmarks[291];
|
| 140 |
+
const topLip = faceLandmarks[13]; const bottomLip = faceLandmarks[14];
|
| 141 |
+
const leftEye = faceLandmarks[33]; const rightEye = faceLandmarks[263];
|
| 142 |
+
|
| 143 |
+
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 144 |
+
const mouthHeight = getDistance(topLip, bottomLip);
|
| 145 |
+
const faceScale = getDistance(leftEye, rightEye);
|
| 146 |
+
const smileRatio = mouthWidth / faceScale;
|
| 147 |
+
const openRatio = mouthHeight / faceScale;
|
| 148 |
+
|
| 149 |
+
let moodText = "Netral 😐"; let moodColor = "#3b82f6";
|
| 150 |
+
if (openRatio > 0.15) {
|
| 151 |
+
moodText = "Terkejut 😲"; moodColor = "#a855f7";
|
| 152 |
+
} else if (smileRatio > 0.52) {
|
| 153 |
+
moodText = "Senang 😊"; moodColor = "#10b981";
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
// 2. Analisis Estimasi Gender
|
| 157 |
+
const leftCheek = faceLandmarks[234]; const rightCheek = faceLandmarks[454];
|
| 158 |
+
const leftJaw = faceLandmarks[132]; const rightJaw = faceLandmarks[361];
|
| 159 |
+
const cheekWidth = getDistance(leftCheek, rightCheek);
|
| 160 |
+
const jawWidth = getDistance(leftJaw, rightJaw);
|
| 161 |
+
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 162 |
+
|
| 163 |
+
let angkaRasio = jawToCheekRatio.toFixed(3);
|
| 164 |
+
let genderText = ""; let genderColor = "";
|
| 165 |
+
|
| 166 |
+
if (jawToCheekRatio > 0.820) {
|
| 167 |
+
genderText = `Pria 👨 (${angkaRasio})`;
|
| 168 |
+
genderColor = "#60a5fa";
|
| 169 |
+
} else {
|
| 170 |
+
genderText = `Wanita 👩 (${angkaRasio})`;
|
| 171 |
+
genderColor = "#f472b6";
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
return { moodText, moodColor, genderText, genderColor };
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
function classifyPose(landmarks) {
|
| 178 |
+
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 179 |
+
const middleOpen = landmarks[12].y < landmarks[10].y;
|
| 180 |
+
const ringOpen = landmarks[16].y < landmarks[14].y;
|
| 181 |
+
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 182 |
+
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 183 |
+
|
| 184 |
+
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
|
| 185 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak", color: "#3b82f6" };
|
| 186 |
+
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 187 |
+
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
| 188 |
+
|
| 189 |
+
const thumbIndexTipDist = getDistance(landmarks[4], landmarks[8]);
|
| 190 |
+
if (thumbIndexTipDist < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "👌 Okay", color: "#10b981" };
|
| 191 |
+
|
| 192 |
+
return null;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
const faceMesh = new FaceMesh({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`; }});
|
| 196 |
+
// ANTI-LAG: refineLandmarks false & confidence diturunkan
|
| 197 |
+
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 198 |
+
|
| 199 |
+
faceMesh.onResults((results) => {
|
| 200 |
+
currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null;
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
+
const hands = new Hands({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; }});
|
| 204 |
+
// ANTI-LAG: modelComplexity 0 & confidence diturunkan
|
| 205 |
+
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 206 |
+
|
| 207 |
+
hands.onResults((results) => {
|
| 208 |
+
canvasCtx.save();
|
| 209 |
+
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 210 |
+
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 211 |
+
|
| 212 |
+
if (currentFaceLandmarks) {
|
| 213 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 214 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
| 215 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYEBROW, {color: '#ec4899', lineWidth: 2});
|
| 216 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
|
| 217 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYEBROW, {color: '#ec4899', lineWidth: 2});
|
| 218 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_FACE_OVAL, {color: '#ec4899', lineWidth: 2});
|
| 219 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
let detectedPosesThisFrame = [];
|
| 223 |
+
anims.forEach(a => a.style.opacity = '0');
|
| 224 |
+
|
| 225 |
+
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 226 |
+
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 227 |
+
let boneColor = index === 0 ? '#ec4899' : '#06b6d4';
|
| 228 |
+
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: boneColor, lineWidth: 4});
|
| 229 |
+
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 230 |
+
|
| 231 |
+
let pose = classifyPose(landmarks);
|
| 232 |
+
if (pose) detectedPosesThisFrame.push({ ...pose, handIndex: index, wrist: landmarks[0] });
|
| 233 |
+
});
|
| 234 |
+
}
|
| 235 |
+
canvasCtx.restore();
|
| 236 |
+
|
| 237 |
+
// RENDER UI & LOGIKA
|
| 238 |
+
if (currentFaceLandmarks) {
|
| 239 |
+
let bio = analyzeFaceBiometrics(currentFaceLandmarks);
|
| 240 |
+
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 241 |
+
|
| 242 |
+
if (bio.moodText === "Senang 😊" && isPositivePose) {
|
| 243 |
+
bio.moodText = "Sangat Senang! ✨"; bio.moodColor = "#eab308";
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
|
| 247 |
+
genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
|
| 248 |
+
biometricContainer.style.borderColor = bio.moodColor;
|
| 249 |
+
biometricContainer.style.boxShadow = `0 0 15px ${bio.moodColor}80`;
|
| 250 |
+
} else {
|
| 251 |
+
moodValue.textContent = "Wajah Hilang"; moodValue.style.color = "#94a3b8";
|
| 252 |
+
genderValue.textContent = "Wajah Hilang"; genderValue.style.color = "#94a3b8";
|
| 253 |
+
biometricContainer.style.borderColor = "#334155";
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
// --- LOGIKA AUDIO DENGAN MEMORI DEBOUNCE ---
|
| 257 |
+
let currentIds = detectedPosesThisFrame.map(p => p.id);
|
| 258 |
+
if (currentIds.length > 0) {
|
| 259 |
+
let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
|
| 260 |
+
statusPose.textContent = uniquePoseNames.join(" & ");
|
| 261 |
+
statusPose.style.color = detectedPosesThisFrame[0].color;
|
| 262 |
+
|
| 263 |
+
detectedPosesThisFrame.forEach((pose, i) => {
|
| 264 |
+
if (pose.id === 1 && anims[i]) {
|
| 265 |
+
const wrist = pose.wrist;
|
| 266 |
+
const leftPos = ((1 - wrist.x) * canvasElement.width) - 75;
|
| 267 |
+
const topPos = (wrist.y * canvasElement.height) + 30;
|
| 268 |
+
anims[i].style.opacity = '1';
|
| 269 |
+
anims[i].style.left = `${leftPos}px`;
|
| 270 |
+
anims[i].style.top = `${topPos}px`;
|
| 271 |
+
anims[i].style.width = `150px`;
|
| 272 |
+
}
|
| 273 |
+
});
|
| 274 |
+
|
| 275 |
+
let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
|
| 276 |
+
if (newPoses.length > 0) {
|
| 277 |
+
let primaryNewPoseId = newPoses[0];
|
| 278 |
+
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 279 |
+
const soundToPlay = sounds[primaryNewPoseId - 1];
|
| 280 |
+
if (soundToPlay) soundToPlay.play();
|
| 281 |
+
}
|
| 282 |
+
memoryActivePoses = currentIds;
|
| 283 |
+
memoryTimer = Date.now();
|
| 284 |
+
} else {
|
| 285 |
+
if (Date.now() - memoryTimer > 500) {
|
| 286 |
+
if (memoryActivePoses.length > 0) {
|
| 287 |
+
statusPose.textContent = "Menunggu formasi jari...";
|
| 288 |
+
statusPose.style.color = "#94a3b8";
|
| 289 |
+
memoryActivePoses = [];
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
});
|
| 294 |
+
|
| 295 |
+
startBtn.addEventListener('click', async () => {
|
| 296 |
+
startBtn.style.display = 'none';
|
| 297 |
+
statusPose.textContent = "Meminta Izin Kamera...";
|
| 298 |
+
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 299 |
+
|
| 300 |
+
try {
|
| 301 |
+
// SOLUSI KAMERA BLANK: Paksa browser meminta izin kamera
|
| 302 |
+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 303 |
+
videoElement.srcObject = stream;
|
| 304 |
+
statusPose.textContent = "Mendownload AI...";
|
| 305 |
+
|
| 306 |
+
const camera = new Camera(videoElement, {
|
| 307 |
+
onFrame: async () => {
|
| 308 |
+
// SOLUSI LAG: Jalankan dua AI bersamaan (Paralel)
|
| 309 |
+
await Promise.all([
|
| 310 |
+
faceMesh.send({image: videoElement}),
|
| 311 |
+
hands.send({image: videoElement})
|
| 312 |
+
]);
|
| 313 |
+
},
|
| 314 |
+
width: 640,
|
| 315 |
+
height: 480
|
| 316 |
+
});
|
| 317 |
+
camera.start();
|
| 318 |
+
} catch (error) {
|
| 319 |
+
alert("GAGAL MENGAKSES KAMERA! \nPastikan kamu mengizinkan akses kamera di pop-up browser.");
|
| 320 |
+
statusPose.textContent = "Kamera Terblokir";
|
| 321 |
+
startBtn.style.display = 'block';
|
| 322 |
+
}
|
| 323 |
+
});
|
| 324 |
+
</script>
|
| 325 |
+
</body>
|
| 326 |
+
</html>
|