Spaces:
Running
Running
Update index.html
Browse files- index.html +100 -63
index.html
CHANGED
|
@@ -3,9 +3,8 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Hand & Face AI Vision -
|
| 7 |
|
| 8 |
-
<!-- Library MediaPipe Wajib (Tambah Face Mesh) -->
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 11 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
|
@@ -39,7 +38,6 @@
|
|
| 39 |
box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 40 |
transition: all 0.3s ease;
|
| 41 |
margin: 20px 0;
|
| 42 |
-
letter-spacing: 1px;
|
| 43 |
text-transform: uppercase;
|
| 44 |
}
|
| 45 |
#startBtn:hover {
|
|
@@ -58,16 +56,10 @@
|
|
| 58 |
text-align: center;
|
| 59 |
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
| 60 |
}
|
| 61 |
-
#statusPose {
|
| 62 |
-
font-size: 24px;
|
| 63 |
-
font-weight: bold;
|
| 64 |
-
color: #94a3b8;
|
| 65 |
-
transition: color 0.3s;
|
| 66 |
-
}
|
| 67 |
|
| 68 |
-
.monitor-container {
|
| 69 |
-
|
| 70 |
-
}
|
| 71 |
canvas {
|
| 72 |
border: 3px solid #3b82f6;
|
| 73 |
box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
|
|
@@ -77,11 +69,9 @@
|
|
| 77 |
height: 480px;
|
| 78 |
max-width: 90vw;
|
| 79 |
object-fit: cover;
|
| 80 |
-
/*
|
| 81 |
-
transform: scaleX(-1);
|
| 82 |
}
|
| 83 |
|
| 84 |
-
/* GIF Animasi - Juga dibalik agar posisinya cocok dengan cermin */
|
| 85 |
.pose1-anim {
|
| 86 |
position: absolute;
|
| 87 |
display: none;
|
|
@@ -91,14 +81,31 @@
|
|
| 91 |
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 92 |
pointer-events: none;
|
| 93 |
transition: transform 0.1s linear;
|
| 94 |
-
transform: scaleX(-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
|
|
|
|
|
|
| 96 |
</style>
|
| 97 |
</head>
|
| 98 |
<body>
|
| 99 |
|
| 100 |
-
<h2>🤖 AI Vision:
|
| 101 |
-
<p>
|
| 102 |
|
| 103 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 104 |
|
|
@@ -107,6 +114,12 @@
|
|
| 107 |
</div>
|
| 108 |
|
| 109 |
<div class="monitor-container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
| 111 |
<canvas id="outputCanvas" width="640" height="480"></canvas>
|
| 112 |
|
|
@@ -114,6 +127,7 @@
|
|
| 114 |
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 115 |
</div>
|
| 116 |
|
|
|
|
| 117 |
<audio id="audio1" src="suara1.mp3"></audio>
|
| 118 |
<audio id="audio2" src="suara2.mp3"></audio>
|
| 119 |
<audio id="audio3" src="suara3.mp3"></audio>
|
|
@@ -127,6 +141,9 @@
|
|
| 127 |
const startBtn = document.getElementById('startBtn');
|
| 128 |
const statusPose = document.getElementById('statusPose');
|
| 129 |
|
|
|
|
|
|
|
|
|
|
| 130 |
const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
|
| 131 |
const sounds = [
|
| 132 |
document.getElementById('audio1'), document.getElementById('audio2'),
|
|
@@ -135,12 +152,40 @@
|
|
| 135 |
];
|
| 136 |
|
| 137 |
let currentActivePoses = [];
|
| 138 |
-
let currentFaceLandmarks = null;
|
| 139 |
|
| 140 |
function getDistance(p1, p2) {
|
| 141 |
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 142 |
}
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
function classifyPose(landmarks) {
|
| 145 |
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 146 |
const middleOpen = landmarks[12].y < landmarks[10].y;
|
|
@@ -148,7 +193,7 @@
|
|
| 148 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 149 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 150 |
|
| 151 |
-
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan
|
| 152 |
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak Terbuka", color: "#3b82f6" };
|
| 153 |
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 154 |
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
|
@@ -159,20 +204,12 @@
|
|
| 159 |
return null;
|
| 160 |
}
|
| 161 |
|
| 162 |
-
//
|
| 163 |
-
// 1. INISIALISASI FACE MESH (AKURASI TINGGI)
|
| 164 |
-
// ==========================================
|
| 165 |
const faceMesh = new FaceMesh({locateFile: (file) => {
|
| 166 |
return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`;
|
| 167 |
}});
|
| 168 |
-
faceMesh.setOptions({
|
| 169 |
-
maxNumFaces: 1, // Fokus 1 wajah agar performa tetap cepat
|
| 170 |
-
refineLandmarks: true, // PENTING: Pelacakan ekstra akurat pada mata/bibir meski bergerak
|
| 171 |
-
minDetectionConfidence: 0.7,
|
| 172 |
-
minTrackingConfidence: 0.7
|
| 173 |
-
});
|
| 174 |
|
| 175 |
-
// Simpan titik wajah saat terdeteksi
|
| 176 |
faceMesh.onResults((results) => {
|
| 177 |
if (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) {
|
| 178 |
currentFaceLandmarks = results.multiFaceLandmarks[0];
|
|
@@ -181,30 +218,20 @@
|
|
| 181 |
}
|
| 182 |
});
|
| 183 |
|
| 184 |
-
//
|
| 185 |
-
// 2. INISIALISASI HANDS (SEKALIGUS RENDER)
|
| 186 |
-
// ==========================================
|
| 187 |
const hands = new Hands({locateFile: (file) => {
|
| 188 |
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`;
|
| 189 |
}});
|
| 190 |
-
hands.setOptions({
|
| 191 |
-
maxNumHands: 2,
|
| 192 |
-
modelComplexity: 1,
|
| 193 |
-
minDetectionConfidence: 0.7,
|
| 194 |
-
minTrackingConfidence: 0.7
|
| 195 |
-
});
|
| 196 |
|
| 197 |
hands.onResults((results) => {
|
| 198 |
canvasCtx.save();
|
| 199 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 200 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 201 |
|
| 202 |
-
// ---
|
| 203 |
if (currentFaceLandmarks) {
|
| 204 |
-
// Tesselation (Jaring-jaring wajah) - Biru Cyan
|
| 205 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
| 206 |
-
|
| 207 |
-
// Kontur Utama Wajah - Pink Neon tebal
|
| 208 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
| 209 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYEBROW, {color: '#ec4899', lineWidth: 2});
|
| 210 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
@@ -213,7 +240,7 @@
|
|
| 213 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 214 |
}
|
| 215 |
|
| 216 |
-
// ---
|
| 217 |
let detectedPosesThisFrame = [];
|
| 218 |
anims.forEach(a => a.style.display = 'none');
|
| 219 |
|
|
@@ -224,31 +251,45 @@
|
|
| 224 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 225 |
|
| 226 |
let pose = classifyPose(landmarks);
|
| 227 |
-
if (pose) {
|
| 228 |
-
detectedPosesThisFrame.push({
|
| 229 |
-
...pose, handIndex: index, wrist: landmarks[0]
|
| 230 |
-
});
|
| 231 |
-
}
|
| 232 |
});
|
| 233 |
}
|
| 234 |
canvasCtx.restore();
|
| 235 |
|
| 236 |
-
// ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
if (detectedPosesThisFrame.length > 0) {
|
| 238 |
let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
|
| 239 |
statusPose.textContent = uniquePoseNames.join(" & ");
|
| 240 |
statusPose.style.color = detectedPosesThisFrame[0].color;
|
| 241 |
|
| 242 |
-
// Penempatan Dinamis GIF
|
| 243 |
detectedPosesThisFrame.forEach((pose, i) => {
|
| 244 |
if (pose.id === 1 && anims[i]) {
|
| 245 |
const wrist = pose.wrist;
|
| 246 |
-
const
|
| 247 |
-
const
|
| 248 |
-
|
| 249 |
-
// Karena kanvas dibalik (Cermin), perhitungan X ikut dibalik
|
| 250 |
-
const leftPos = ((1 - wrist.x) * canvasWidth) - (150 / 2);
|
| 251 |
-
const topPos = (wrist.y * canvasHeight) + 30;
|
| 252 |
|
| 253 |
anims[i].style.display = 'block';
|
| 254 |
anims[i].style.left = `${leftPos}px`;
|
|
@@ -284,9 +325,6 @@
|
|
| 284 |
}
|
| 285 |
});
|
| 286 |
|
| 287 |
-
// ==========================================
|
| 288 |
-
// 3. EVENT MULAI KAMERA (SYNCHRONIZE DUAL AI)
|
| 289 |
-
// ==========================================
|
| 290 |
startBtn.addEventListener('click', () => {
|
| 291 |
startBtn.style.display = 'none';
|
| 292 |
statusPose.textContent = "Menyiapkan Kamera...";
|
|
@@ -295,9 +333,8 @@
|
|
| 295 |
|
| 296 |
const camera = new Camera(videoElement, {
|
| 297 |
onFrame: async () => {
|
| 298 |
-
|
| 299 |
-
await
|
| 300 |
-
await hands.send({image: videoElement}); // Render tangan dan wajah sekaligus ke layar
|
| 301 |
},
|
| 302 |
width: 640,
|
| 303 |
height: 480
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Hand & Face AI Vision - v17 Mood Tracker</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>
|
|
|
|
| 38 |
box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 39 |
transition: all 0.3s ease;
|
| 40 |
margin: 20px 0;
|
|
|
|
| 41 |
text-transform: uppercase;
|
| 42 |
}
|
| 43 |
#startBtn:hover {
|
|
|
|
| 56 |
text-align: center;
|
| 57 |
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
| 58 |
}
|
| 59 |
+
#statusPose { font-size: 24px; font-weight: bold; color: #94a3b8; transition: color 0.3s; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
.monitor-container { position: relative; }
|
| 62 |
+
|
|
|
|
| 63 |
canvas {
|
| 64 |
border: 3px solid #3b82f6;
|
| 65 |
box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
|
|
|
|
| 69 |
height: 480px;
|
| 70 |
max-width: 90vw;
|
| 71 |
object-fit: cover;
|
| 72 |
+
transform: scaleX(-1); /* Efek Cermin */
|
|
|
|
| 73 |
}
|
| 74 |
|
|
|
|
| 75 |
.pose1-anim {
|
| 76 |
position: absolute;
|
| 77 |
display: none;
|
|
|
|
| 81 |
box-shadow: 0 0 15px rgba(234, 179, 8, 0.8);
|
| 82 |
pointer-events: none;
|
| 83 |
transition: transform 0.1s linear;
|
| 84 |
+
transform: scaleX(-1); /* Samakan dengan efek cermin kamera */
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/* --- STYLING PANEL MOOD TRACKER --- */
|
| 88 |
+
#moodTrackerContainer {
|
| 89 |
+
position: absolute;
|
| 90 |
+
top: 20px;
|
| 91 |
+
right: 20px;
|
| 92 |
+
background: rgba(15, 23, 42, 0.85);
|
| 93 |
+
border: 2px solid #3b82f6;
|
| 94 |
+
padding: 12px 20px;
|
| 95 |
+
border-radius: 12px;
|
| 96 |
+
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
|
| 97 |
+
z-index: 20;
|
| 98 |
+
backdrop-filter: blur(5px);
|
| 99 |
+
transition: border-color 0.3s, box-shadow 0.3s;
|
| 100 |
}
|
| 101 |
+
.mood-title { font-size: 11px; color: #cbd5e1; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
|
| 102 |
+
#moodValue { font-size: 22px; font-weight: bold; color: #f8fafc; }
|
| 103 |
</style>
|
| 104 |
</head>
|
| 105 |
<body>
|
| 106 |
|
| 107 |
+
<h2>🤖 AI Vision: Gestures & Mood</h2>
|
| 108 |
+
<p>Analisis Pose Tangan & Kondisi Mood Real-Time v17</p>
|
| 109 |
|
| 110 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 111 |
|
|
|
|
| 114 |
</div>
|
| 115 |
|
| 116 |
<div class="monitor-container">
|
| 117 |
+
<!-- Floating Panel Mood -->
|
| 118 |
+
<div id="moodTrackerContainer">
|
| 119 |
+
<div class="mood-title">Kondisi Mood Kamu</div>
|
| 120 |
+
<div id="moodValue">Menganalisis...</div>
|
| 121 |
+
</div>
|
| 122 |
+
|
| 123 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
| 124 |
<canvas id="outputCanvas" width="640" height="480"></canvas>
|
| 125 |
|
|
|
|
| 127 |
<img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
|
| 128 |
</div>
|
| 129 |
|
| 130 |
+
<!-- Audio -->
|
| 131 |
<audio id="audio1" src="suara1.mp3"></audio>
|
| 132 |
<audio id="audio2" src="suara2.mp3"></audio>
|
| 133 |
<audio id="audio3" src="suara3.mp3"></audio>
|
|
|
|
| 141 |
const startBtn = document.getElementById('startBtn');
|
| 142 |
const statusPose = document.getElementById('statusPose');
|
| 143 |
|
| 144 |
+
const moodTrackerContainer = document.getElementById('moodTrackerContainer');
|
| 145 |
+
const moodValue = document.getElementById('moodValue');
|
| 146 |
+
|
| 147 |
const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
|
| 148 |
const sounds = [
|
| 149 |
document.getElementById('audio1'), document.getElementById('audio2'),
|
|
|
|
| 152 |
];
|
| 153 |
|
| 154 |
let currentActivePoses = [];
|
| 155 |
+
let currentFaceLandmarks = null;
|
| 156 |
|
| 157 |
function getDistance(p1, p2) {
|
| 158 |
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 159 |
}
|
| 160 |
|
| 161 |
+
// --- FUNGSI ANALISIS MOOD DARI WAJAH ---
|
| 162 |
+
function classifyMood(faceLandmarks) {
|
| 163 |
+
// Titik acuan anatomi bibir dan mata
|
| 164 |
+
const leftMouth = faceLandmarks[61];
|
| 165 |
+
const rightMouth = faceLandmarks[291];
|
| 166 |
+
const topLip = faceLandmarks[13];
|
| 167 |
+
const bottomLip = faceLandmarks[14];
|
| 168 |
+
const leftEye = faceLandmarks[33];
|
| 169 |
+
const rightEye = faceLandmarks[263];
|
| 170 |
+
|
| 171 |
+
// Hitung lebar, tinggi mulut, dan skala wajah (lebar mata)
|
| 172 |
+
const mouthWidth = getDistance(leftMouth, rightMouth);
|
| 173 |
+
const mouthHeight = getDistance(topLip, bottomLip);
|
| 174 |
+
const faceScale = getDistance(leftEye, rightEye);
|
| 175 |
+
|
| 176 |
+
// Cari rasio agar akurat tidak peduli jarak wajah ke kamera
|
| 177 |
+
const smileRatio = mouthWidth / faceScale;
|
| 178 |
+
const openRatio = mouthHeight / faceScale;
|
| 179 |
+
|
| 180 |
+
if (openRatio > 0.15) {
|
| 181 |
+
return { text: "Terkejut 😲", color: "#a855f7" }; // Ungu
|
| 182 |
+
} else if (smileRatio > 0.52) { // Ambang batas senyum
|
| 183 |
+
return { text: "Senang 😊", color: "#10b981" }; // Hijau
|
| 184 |
+
} else {
|
| 185 |
+
return { text: "Netral 😐", color: "#3b82f6" }; // Biru
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
function classifyPose(landmarks) {
|
| 190 |
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 191 |
const middleOpen = landmarks[12].y < landmarks[10].y;
|
|
|
|
| 193 |
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 194 |
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 195 |
|
| 196 |
+
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
|
| 197 |
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak Terbuka", color: "#3b82f6" };
|
| 198 |
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 199 |
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
|
|
|
| 204 |
return null;
|
| 205 |
}
|
| 206 |
|
| 207 |
+
// Inisialisasi Face Mesh
|
|
|
|
|
|
|
| 208 |
const faceMesh = new FaceMesh({locateFile: (file) => {
|
| 209 |
return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`;
|
| 210 |
}});
|
| 211 |
+
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: true, minDetectionConfidence: 0.7, minTrackingConfidence: 0.7 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
|
|
|
| 213 |
faceMesh.onResults((results) => {
|
| 214 |
if (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) {
|
| 215 |
currentFaceLandmarks = results.multiFaceLandmarks[0];
|
|
|
|
| 218 |
}
|
| 219 |
});
|
| 220 |
|
| 221 |
+
// Inisialisasi Hands
|
|
|
|
|
|
|
| 222 |
const hands = new Hands({locateFile: (file) => {
|
| 223 |
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`;
|
| 224 |
}});
|
| 225 |
+
hands.setOptions({ maxNumHands: 2, modelComplexity: 1, minDetectionConfidence: 0.7, minTrackingConfidence: 0.7 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
hands.onResults((results) => {
|
| 228 |
canvasCtx.save();
|
| 229 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 230 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
| 231 |
|
| 232 |
+
// --- RENDER WAJAH ---
|
| 233 |
if (currentFaceLandmarks) {
|
|
|
|
| 234 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
|
|
|
|
|
|
|
| 235 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
|
| 236 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYEBROW, {color: '#ec4899', lineWidth: 2});
|
| 237 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
|
|
|
|
| 240 |
drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});
|
| 241 |
}
|
| 242 |
|
| 243 |
+
// --- RENDER TANGAN ---
|
| 244 |
let detectedPosesThisFrame = [];
|
| 245 |
anims.forEach(a => a.style.display = 'none');
|
| 246 |
|
|
|
|
| 251 |
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 252 |
|
| 253 |
let pose = classifyPose(landmarks);
|
| 254 |
+
if (pose) detectedPosesThisFrame.push({ ...pose, handIndex: index, wrist: landmarks[0] });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
});
|
| 256 |
}
|
| 257 |
canvasCtx.restore();
|
| 258 |
|
| 259 |
+
// --- LOGIKA UPDATE MOOD & POSE ---
|
| 260 |
+
|
| 261 |
+
// 1. Update Panel Mood
|
| 262 |
+
if (currentFaceLandmarks) {
|
| 263 |
+
let mood = classifyMood(currentFaceLandmarks);
|
| 264 |
+
|
| 265 |
+
// GABUNGAN WAJAH & TANGAN: Jika senyum + pose positif (Thumbs Up, Peace, Okay)
|
| 266 |
+
let isPositivePose = detectedPosesThisFrame.some(p => p.id === 1 || p.id === 2 || p.id === 3);
|
| 267 |
+
if (mood.text === "Senang 😊" && isPositivePose) {
|
| 268 |
+
mood.text = "Sangat Senang! ✨";
|
| 269 |
+
mood.color = "#eab308"; // Kuning/Gold
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
moodValue.textContent = mood.text;
|
| 273 |
+
moodValue.style.color = mood.color;
|
| 274 |
+
moodTrackerContainer.style.borderColor = mood.color;
|
| 275 |
+
moodTrackerContainer.style.boxShadow = `0 0 15px ${mood.color}80`; // Tambah efek glow
|
| 276 |
+
} else {
|
| 277 |
+
moodValue.textContent = "Wajah Tidak Terlihat";
|
| 278 |
+
moodValue.style.color = "#94a3b8";
|
| 279 |
+
moodTrackerContainer.style.borderColor = "#334155";
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
// 2. Update Teks Tangan & Animasi GIF
|
| 283 |
if (detectedPosesThisFrame.length > 0) {
|
| 284 |
let uniquePoseNames = [...new Set(detectedPosesThisFrame.map(p => p.name))];
|
| 285 |
statusPose.textContent = uniquePoseNames.join(" & ");
|
| 286 |
statusPose.style.color = detectedPosesThisFrame[0].color;
|
| 287 |
|
|
|
|
| 288 |
detectedPosesThisFrame.forEach((pose, i) => {
|
| 289 |
if (pose.id === 1 && anims[i]) {
|
| 290 |
const wrist = pose.wrist;
|
| 291 |
+
const leftPos = ((1 - wrist.x) * canvasElement.width) - 75;
|
| 292 |
+
const topPos = (wrist.y * canvasElement.height) + 30;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
anims[i].style.display = 'block';
|
| 295 |
anims[i].style.left = `${leftPos}px`;
|
|
|
|
| 325 |
}
|
| 326 |
});
|
| 327 |
|
|
|
|
|
|
|
|
|
|
| 328 |
startBtn.addEventListener('click', () => {
|
| 329 |
startBtn.style.display = 'none';
|
| 330 |
statusPose.textContent = "Menyiapkan Kamera...";
|
|
|
|
| 333 |
|
| 334 |
const camera = new Camera(videoElement, {
|
| 335 |
onFrame: async () => {
|
| 336 |
+
await faceMesh.send({image: videoElement});
|
| 337 |
+
await hands.send({image: videoElement});
|
|
|
|
| 338 |
},
|
| 339 |
width: 640,
|
| 340 |
height: 480
|