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