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