Spaces:
Running
Running
Update index.html
Browse files- index.html +31 -41
index.html
CHANGED
|
@@ -109,7 +109,7 @@
|
|
| 109 |
<body>
|
| 110 |
|
| 111 |
<h2>🤖 AI Vision: Smooth Tracking</h2>
|
| 112 |
-
<p>By Rizki
|
| 113 |
|
| 114 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 115 |
|
|
@@ -164,36 +164,6 @@
|
|
| 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 analyzeFaceBiometrics(faceLandmarks) {
|
| 198 |
// 1. Analisis Mood
|
| 199 |
const leftMouth = faceLandmarks[61]; const rightMouth = faceLandmarks[291];
|
|
@@ -219,15 +189,11 @@
|
|
| 219 |
const jawWidth = getDistance(leftJaw, rightJaw);
|
| 220 |
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 221 |
|
| 222 |
-
// FITUR DEBUGGING
|
| 223 |
-
// Fungsi .toFixed(3) digunakan untuk mengambil 3 angka di belakang koma
|
| 224 |
let angkaRasio = jawToCheekRatio.toFixed(3);
|
| 225 |
|
| 226 |
let genderText = ""; let genderColor = "";
|
| 227 |
|
| 228 |
-
// ========================================================
|
| 229 |
-
// UBAH ANGKA 0.820 DI BAWAH INI UNTUK MENYESUAIKAN AKURASI
|
| 230 |
-
// ========================================================
|
| 231 |
if (jawToCheekRatio > 0.820) {
|
| 232 |
genderText = `Pria 👨 (${angkaRasio})`;
|
| 233 |
genderColor = "#60a5fa";
|
|
@@ -238,8 +204,29 @@
|
|
| 238 |
|
| 239 |
return { moodText, moodColor, genderText, genderColor };
|
| 240 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
const faceMesh = new FaceMesh({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`; }});
|
| 242 |
-
|
|
|
|
|
|
|
| 243 |
|
| 244 |
faceMesh.onResults((results) => {
|
| 245 |
currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null;
|
|
@@ -247,8 +234,8 @@
|
|
| 247 |
|
| 248 |
const hands = new Hands({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; }});
|
| 249 |
|
| 250 |
-
//
|
| 251 |
-
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.
|
| 252 |
|
| 253 |
hands.onResults((results) => {
|
| 254 |
canvasCtx.save();
|
|
@@ -351,8 +338,11 @@
|
|
| 351 |
|
| 352 |
const camera = new Camera(videoElement, {
|
| 353 |
onFrame: async () => {
|
| 354 |
-
|
| 355 |
-
await
|
|
|
|
|
|
|
|
|
|
| 356 |
},
|
| 357 |
width: 640,
|
| 358 |
height: 480
|
|
|
|
| 109 |
<body>
|
| 110 |
|
| 111 |
<h2>🤖 AI Vision: Smooth Tracking</h2>
|
| 112 |
+
<p>By Rizki Ardiansyah (Optimized)</p>
|
| 113 |
|
| 114 |
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 115 |
|
|
|
|
| 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 |
// 1. Analisis Mood
|
| 169 |
const leftMouth = faceLandmarks[61]; const rightMouth = faceLandmarks[291];
|
|
|
|
| 189 |
const jawWidth = getDistance(leftJaw, rightJaw);
|
| 190 |
const jawToCheekRatio = jawWidth / cheekWidth;
|
| 191 |
|
| 192 |
+
// FITUR DEBUGGING
|
|
|
|
| 193 |
let angkaRasio = jawToCheekRatio.toFixed(3);
|
| 194 |
|
| 195 |
let genderText = ""; let genderColor = "";
|
| 196 |
|
|
|
|
|
|
|
|
|
|
| 197 |
if (jawToCheekRatio > 0.820) {
|
| 198 |
genderText = `Pria 👨 (${angkaRasio})`;
|
| 199 |
genderColor = "#60a5fa";
|
|
|
|
| 204 |
|
| 205 |
return { moodText, moodColor, genderText, genderColor };
|
| 206 |
}
|
| 207 |
+
|
| 208 |
+
function classifyPose(landmarks) {
|
| 209 |
+
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 210 |
+
const middleOpen = landmarks[12].y < landmarks[10].y;
|
| 211 |
+
const ringOpen = landmarks[16].y < landmarks[14].y;
|
| 212 |
+
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 213 |
+
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 214 |
+
|
| 215 |
+
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "✊ Kepalan", color: "#ef4444" };
|
| 216 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "🖐️ Telapak", color: "#3b82f6" };
|
| 217 |
+
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "✌️ Victory", color: "#a855f7" };
|
| 218 |
+
if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "👉 Tunjuk & Jempol", color: "#eab308" };
|
| 219 |
+
|
| 220 |
+
const thumbIndexTipDist = getDistance(landmarks[4], landmarks[8]);
|
| 221 |
+
if (thumbIndexTipDist < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "👌 Okay", color: "#10b981" };
|
| 222 |
+
|
| 223 |
+
return null;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
const faceMesh = new FaceMesh({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`; }});
|
| 227 |
+
|
| 228 |
+
// SOLUSI LAG 1: refineLandmarks diubah ke false, confidence diturunkan ke 0.5
|
| 229 |
+
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 230 |
|
| 231 |
faceMesh.onResults((results) => {
|
| 232 |
currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null;
|
|
|
|
| 234 |
|
| 235 |
const hands = new Hands({locateFile: (file) => { return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; }});
|
| 236 |
|
| 237 |
+
// SOLUSI LAG 2: modelComplexity 0, confidence diturunkan ke 0.5
|
| 238 |
+
hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
|
| 239 |
|
| 240 |
hands.onResults((results) => {
|
| 241 |
canvasCtx.save();
|
|
|
|
| 338 |
|
| 339 |
const camera = new Camera(videoElement, {
|
| 340 |
onFrame: async () => {
|
| 341 |
+
// SOLUSI LAG 3: Gunakan Promise.all agar AI Wajah dan Tangan memproses secara paralel, BUKAN antri
|
| 342 |
+
await Promise.all([
|
| 343 |
+
faceMesh.send({image: videoElement}),
|
| 344 |
+
hands.send({image: videoElement})
|
| 345 |
+
]);
|
| 346 |
},
|
| 347 |
width: 640,
|
| 348 |
height: 480
|