Spaces:
Running
Running
Update index.html
Browse files- index.html +69 -1
index.html
CHANGED
|
@@ -166,4 +166,72 @@
|
|
| 166 |
faceMesh.onResults((res) => { currentFaceLandmarks = res.multiFaceLandmarks?.[0]; });
|
| 167 |
|
| 168 |
const hands = new Hands({locateFile: (f) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${f}`});
|
| 169 |
-
hands.setOptions({ maxNumHands: 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
faceMesh.onResults((res) => { currentFaceLandmarks = res.multiFaceLandmarks?.[0]; });
|
| 167 |
|
| 168 |
const hands = new Hands({locateFile: (f) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${f}`});
|
| 169 |
+
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.7 });
|
| 170 |
+
hands.onResults((res) => {
|
| 171 |
+
canvasCtx.save();
|
| 172 |
+
canvasCtx.clearRect(0, 0, 640, 480);
|
| 173 |
+
canvasCtx.drawImage(res.image, 0, 0, 640, 480);
|
| 174 |
+
|
| 175 |
+
if (currentFaceLandmarks) {
|
| 176 |
+
const bio = analyzeFace(currentFaceLandmarks);
|
| 177 |
+
moodValue.textContent = bio.mood.text; moodValue.style.color = bio.mood.color;
|
| 178 |
+
genderValue.textContent = bio.gender.text; genderValue.style.color = bio.gender.color;
|
| 179 |
+
// Draw Face Mesh
|
| 180 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 181 |
+
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
let poses = [];
|
| 185 |
+
anims.forEach(a => a.style.opacity = '0');
|
| 186 |
+
|
| 187 |
+
if (res.multiHandLandmarks) {
|
| 188 |
+
res.multiHandLandmarks.forEach((lm, i) => {
|
| 189 |
+
drawConnectors(canvasCtx, lm, HAND_CONNECTIONS, {color: i===0?'#ec4899':'#06b6d4', lineWidth: 4});
|
| 190 |
+
let p = classifyPose(lm);
|
| 191 |
+
if (p) poses.push({...p, wrist: lm[0]});
|
| 192 |
+
});
|
| 193 |
+
}
|
| 194 |
+
canvasCtx.restore();
|
| 195 |
+
|
| 196 |
+
if (poses.length > 0) {
|
| 197 |
+
statusPose.textContent = [...new Set(poses.map(p => p.name))].join(" & ");
|
| 198 |
+
statusPose.style.color = poses[0].color;
|
| 199 |
+
|
| 200 |
+
poses.forEach((p, i) => {
|
| 201 |
+
if (p.id === 1 && anims[i]) {
|
| 202 |
+
anims[i].style.opacity = '1';
|
| 203 |
+
anims[i].style.left = `${((1-p.wrist.x)*640)-75}px`;
|
| 204 |
+
anims[i].style.top = `${(p.wrist.y*480)+30}px`;
|
| 205 |
+
anims[i].style.width = "150px";
|
| 206 |
+
}
|
| 207 |
+
});
|
| 208 |
+
|
| 209 |
+
let newIds = poses.map(p => p.id).filter(id => !memoryActivePoses.includes(id));
|
| 210 |
+
if (newIds.length > 0) {
|
| 211 |
+
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 212 |
+
sounds[newIds[0]-1]?.play();
|
| 213 |
+
}
|
| 214 |
+
memoryActivePoses = poses.map(p => p.id);
|
| 215 |
+
memoryTimer = Date.now();
|
| 216 |
+
} else if (Date.now() - memoryTimer > 500) {
|
| 217 |
+
statusPose.textContent = "Menunggu formasi jari...";
|
| 218 |
+
statusPose.style.color = "#94a3b8";
|
| 219 |
+
memoryActivePoses = [];
|
| 220 |
+
}
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
startBtn.addEventListener('click', () => {
|
| 224 |
+
startBtn.style.display = 'none';
|
| 225 |
+
sounds.forEach(s => { s.play().then(()=>s.pause()); });
|
| 226 |
+
const cam = new Camera(videoElement, {
|
| 227 |
+
onFrame: async () => {
|
| 228 |
+
await faceMesh.send({image: videoElement});
|
| 229 |
+
await hands.send({image: videoElement});
|
| 230 |
+
},
|
| 231 |
+
width: 640, height: 480
|
| 232 |
+
});
|
| 233 |
+
cam.start();
|
| 234 |
+
});
|
| 235 |
+
</script>
|
| 236 |
+
</body>
|
| 237 |
+
</html>
|