Spaces:
Running
Running
Update index.html
Browse files- index.html +253 -184
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>AI
|
| 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,95 +15,174 @@
|
|
| 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: 20px
|
| 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 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 52 |
transform: scaleX(-1);
|
| 53 |
}
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
-
.
|
| 62 |
-
|
| 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:
|
| 70 |
-
<p>
|
| 71 |
|
| 72 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
<div class="
|
| 81 |
-
<div
|
| 82 |
-
<div class="
|
| 83 |
-
<div class="
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
<
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 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
|
| 106 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
const moodValue = document.getElementById('moodValue');
|
| 108 |
const genderValue = document.getElementById('genderValue');
|
| 109 |
|
|
@@ -113,46 +192,56 @@
|
|
| 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
|
| 127 |
-
const
|
| 128 |
-
const
|
|
|
|
| 129 |
|
| 130 |
-
const
|
| 131 |
-
const
|
| 132 |
-
const
|
| 133 |
-
const smileRatio = mouthWidth / faceScale;
|
| 134 |
-
const openRatio = mouthHeight / faceScale;
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
| 139 |
|
| 140 |
-
const
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 145 |
|
| 146 |
-
|
| 147 |
-
let
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
-
return { moodText, moodColor, genderText, genderColor };
|
| 156 |
}
|
| 157 |
|
| 158 |
function classifyPose(landmarks) {
|
|
@@ -162,156 +251,136 @@
|
|
| 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: "
|
| 166 |
-
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "
|
| 167 |
-
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "
|
| 168 |
-
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "
|
|
|
|
| 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 |
-
//
|
| 175 |
-
const faceMesh = new FaceMesh({locateFile: (file) =>
|
| 176 |
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 177 |
-
faceMesh.onResults((
|
| 178 |
-
currentFaceLandmarks = (
|
| 179 |
});
|
| 180 |
|
| 181 |
-
|
| 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 |
-
|
| 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
|
| 200 |
anims.forEach(a => a.style.opacity = '0');
|
|
|
|
| 201 |
|
|
|
|
| 202 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 203 |
results.multiHandLandmarks.forEach((landmarks, index) => {
|
| 204 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
});
|
| 211 |
}
|
| 212 |
-
canvasCtx.restore();
|
| 213 |
|
| 214 |
-
//
|
| 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 |
-
|
| 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[
|
| 255 |
if (soundToPlay) soundToPlay.play();
|
| 256 |
}
|
| 257 |
memoryActivePoses = currentIds;
|
| 258 |
memoryTimer = Date.now();
|
| 259 |
-
} else {
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
statusPose.style.color = "#94a3b8";
|
| 263 |
-
memoryActivePoses = [];
|
| 264 |
-
}
|
| 265 |
}
|
| 266 |
});
|
| 267 |
|
| 268 |
-
//
|
| 269 |
startBtn.addEventListener('click', async () => {
|
| 270 |
startBtn.style.display = 'none';
|
| 271 |
-
|
|
|
|
| 272 |
|
| 273 |
-
// Unblock audio
|
| 274 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 275 |
|
| 276 |
-
try {
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
video: { width: 640, height: 480 }
|
| 280 |
-
});
|
| 281 |
|
| 282 |
-
videoElement.
|
| 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 |
-
//
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
// Kirim gambar ke otak AI
|
| 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 |
-
//
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
});
|
| 316 |
</script>
|
| 317 |
</body>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Zero-Team AI - Camera Fix v24</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; overflow-x: hidden;
|
| 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, #a855f7, #ec4899);
|
| 26 |
+
color: white; border: none; padding: 15px 40px;
|
| 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-bottom: 20px; text-transform: uppercase;
|
| 30 |
}
|
| 31 |
#startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }
|
| 32 |
|
| 33 |
+
#mainStatus {
|
| 34 |
+
font-size: 20px; font-weight: bold; color: #94a3b8;
|
| 35 |
+
background: rgba(15, 23, 42, 0.6); padding: 10px 30px;
|
| 36 |
+
border-radius: 12px; border: 1px solid #334155; margin-bottom: 25px;
|
| 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 |
+
.canvas-container {
|
| 65 |
+
position: relative;
|
| 66 |
+
width: 640px; height: 480px;
|
| 67 |
+
border: 3px solid #06b6d4;
|
| 68 |
+
box-shadow: 0 0 25px rgba(6, 182, 212, 0.4);
|
| 69 |
+
border-radius: 16px;
|
| 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 |
+
/* INDIKATOR POSE Bawah */
|
| 97 |
+
.pose-indicators { display: flex; gap: 15px; justify-content: center; width: 100%; }
|
| 98 |
+
.pose-box {
|
| 99 |
+
background: rgba(15, 23, 42, 0.5); border: 1px solid #334155;
|
| 100 |
+
border-radius: 12px; padding: 15px 10px; text-align: center;
|
| 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 |
+
.pose-box.active .pose-name { color: #f8fafc; }
|
| 111 |
+
|
|
|
|
|
|
|
| 112 |
</style>
|
| 113 |
</head>
|
| 114 |
+
<body>
|
| 115 |
|
| 116 |
+
<h2>🤖 AI Vision: Ultimate Overlay Engine</h2>
|
| 117 |
+
<p>By Rizki Ardiansyah (v24 Camera Fix)</p>
|
| 118 |
|
| 119 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 120 |
+
<div id="mainStatus">Sistem Menunggu Kamera...</div>
|
| 121 |
+
|
| 122 |
+
<div class="dashboard-container">
|
| 123 |
+
<div class="side-panel">
|
| 124 |
+
<div class="data-item" style="margin-bottom: 10px;">
|
| 125 |
+
<div class="data-label" style="font-size: 18px; color: #38bdf8;">⚙️ Zero-Team AI</div>
|
| 126 |
+
</div>
|
| 127 |
+
<div class="data-item"><div class="data-label">👁️ Computer Vision Engine</div></div>
|
| 128 |
+
<div class="data-item"><div class="data-label">🖐️ Mediapipe Hands: v0.10.x</div></div>
|
| 129 |
+
<div class="data-item"><div class="data-label">🎭 Mediapipe FaceMesh: v0.10.x</div></div>
|
| 130 |
+
<div class="data-item" style="margin-top: 20px;">
|
| 131 |
+
<div class="data-label">🛡️ Status Deteksi:</div>
|
| 132 |
+
<div id="statusKiri" class="data-value" style="color: #94a3b8; font-size: 14px;">Standby</div>
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
|
| 136 |
+
<div class="center-stage">
|
| 137 |
+
<div class="canvas-container">
|
| 138 |
+
<video id="videoElement" autoplay playsinline webkit-playsinline muted></video>
|
| 139 |
+
<canvas id="outputCanvas" width="640" height="480"></canvas>
|
| 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 mainStatus = document.getElementById('mainStatus');
|
| 181 |
+
const statusKiri = document.getElementById('statusKiri');
|
| 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 |
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) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }
|
|
|
|
|
|
|
| 206 |
|
| 207 |
function analyzeFaceBiometrics(faceLandmarks) {
|
| 208 |
+
const dahi = faceLandmarks[10]; const dagu = faceLandmarks[152];
|
| 209 |
+
const pipiKiri = faceLandmarks[234]; const pipiKanan = faceLandmarks[454];
|
| 210 |
+
const rahangKiri = faceLandmarks[132]; const rahangKanan = faceLandmarks[361];
|
| 211 |
+
const alisKiri = faceLandmarks[159]; const alisKiriTengah = faceLandmarks[52];
|
| 212 |
|
| 213 |
+
const faceHeight = getDistance(dahi, dagu);
|
| 214 |
+
const faceWidth = getDistance(pipiKiri, pipiKanan);
|
| 215 |
+
const jawWidth = getDistance(rahangKiri, rahangKanan);
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
const ratioFace = faceHeight / faceWidth;
|
| 218 |
+
let faceText = "Bulat / Pendek";
|
| 219 |
+
if (ratioFace > 1.35) faceText = "Oval / Heart";
|
| 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 ratioEyebrow = getDistance(alisKiri, alisKiriTengah) / faceHeight;
|
| 228 |
+
let browText = "Datar / Straight";
|
| 229 |
+
if (ratioEyebrow > 0.055) browText = "Arched-High";
|
| 230 |
+
else if (ratioEyebrow > 0.040) browText = "Melengkung Alami";
|
| 231 |
|
| 232 |
+
const mouthWidth = getDistance(faceLandmarks[61], faceLandmarks[291]);
|
| 233 |
+
const mouthHeight = getDistance(faceLandmarks[13], faceLandmarks[14]);
|
| 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 |
+
const headRatio = getDistance(dahi, faceLandmarks[168]) / jawWidth;
|
| 239 |
+
let genderText = "Pria 👨"; let genderColor = "#60a5fa";
|
| 240 |
+
if (headRatio < 0.22 || ratioJaw < 0.75) {
|
| 241 |
+
genderText = "Wanita 👩 (Hijab/Tirus)"; genderColor = "#f472b6";
|
| 242 |
}
|
| 243 |
|
| 244 |
+
return { faceText, jawText, browText, moodText, moodColor, genderText, genderColor };
|
| 245 |
}
|
| 246 |
|
| 247 |
function classifyPose(landmarks) {
|
|
|
|
| 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: "Fist" };
|
| 255 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "Open Palm" };
|
| 256 |
+
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "Peace" };
|
| 257 |
+
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "Thumbs Up" };
|
| 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 INITIALIZATION (Ringan)
|
| 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((res) => {
|
| 267 |
+
currentFaceLandmarks = (res.multiFaceLandmarks && res.multiFaceLandmarks.length > 0) ? res.multiFaceLandmarks[0] : null;
|
| 268 |
});
|
| 269 |
|
| 270 |
+
const hands = new Hands({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`});
|
|
|
|
| 271 |
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 272 |
+
|
| 273 |
hands.onResults((results) => {
|
| 274 |
+
// PERBAIKAN: Hapus Tinta Transparan saja (TIDAK MENGHAPUS VIDEO ASLI)
|
| 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 currentIds = [];
|
| 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 |
+
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: index === 0 ? '#ec4899' : '#06b6d4', lineWidth: 4});
|
|
|
|
| 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 |
+
// Audio System
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
if (currentIds.length > 0) {
|
| 326 |
+
statusKiri.textContent = "AI Aktif & Merespon 🟢"; statusKiri.style.color = "#10b981";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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[newPoses[0] - 1];
|
| 331 |
if (soundToPlay) soundToPlay.play();
|
| 332 |
}
|
| 333 |
memoryActivePoses = currentIds;
|
| 334 |
memoryTimer = Date.now();
|
| 335 |
+
} else if (Date.now() - memoryTimer > 500) {
|
| 336 |
+
statusKiri.textContent = "Menunggu Tangan... 🟡"; statusKiri.style.color = "#eab308";
|
| 337 |
+
memoryActivePoses = [];
|
|
|
|
|
|
|
|
|
|
| 338 |
}
|
| 339 |
});
|
| 340 |
|
| 341 |
+
// CAMERA ENGINE KUSTOM
|
| 342 |
startBtn.addEventListener('click', async () => {
|
| 343 |
startBtn.style.display = 'none';
|
| 344 |
+
mainStatus.textContent = "Mohon Izinkan Kamera di Pop-up Browser...";
|
| 345 |
+
mainStatus.style.color = "#eab308";
|
| 346 |
|
|
|
|
| 347 |
sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });
|
| 348 |
|
| 349 |
+
try {
|
| 350 |
+
const stream = await navigator.mediaDevices.getUserMedia({ video: { width: 640, height: 480 } });
|
| 351 |
+
videoElement.srcObject = stream;
|
|
|
|
|
|
|
| 352 |
|
| 353 |
+
videoElement.onloadedmetadata = () => {
|
| 354 |
+
videoElement.play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
+
// KAMERA SUDAH MUNCUL DISINI!
|
| 357 |
+
mainStatus.textContent = "Kamera Terhubung! Sedang Memuat Otak AI (3-5 Detik)...";
|
| 358 |
+
mainStatus.style.color = "#38bdf8";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
+
// Loop AI
|
| 361 |
+
async function processFrame() {
|
| 362 |
+
if (!videoElement.paused) {
|
| 363 |
+
try {
|
| 364 |
+
await faceMesh.send({image: videoElement});
|
| 365 |
+
await hands.send({image: videoElement});
|
| 366 |
+
if (mainStatus.textContent.includes("Memuat")) {
|
| 367 |
+
mainStatus.textContent = "Sistem Biometrik & Pose Aktif 🚀";
|
| 368 |
+
mainStatus.style.color = "#10b981";
|
| 369 |
+
}
|
| 370 |
+
} catch(e) {
|
| 371 |
+
console.warn("AI Loading...");
|
| 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>
|