File size: 20,501 Bytes
56d74ef
 
 
 
 
ba76729
56d74ef
ba76729
56d74ef
 
 
14dbe28
56d74ef
 
 
888e938
 
553c794
ba76729
 
56d74ef
888e938
 
ba76729
 
 
 
 
 
888e938
ba76729
888e938
ba76729
 
 
 
14ff283
e299c0a
 
ba76729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
888e938
ba76729
 
 
10e28f7
56d74ef
4ce5636
596025e
ba76729
 
 
c466823
b772d35
 
ba76729
 
 
 
 
 
 
e299c0a
ba76729
 
 
 
 
 
 
 
7b7f1dd
 
 
 
 
ba76729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b7f1dd
ba76729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b7f1dd
 
ba76729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56d74ef
 
888e938
 
 
 
 
 
 
56d74ef
 
 
 
ba76729
 
10e28f7
ba76729
 
 
10e28f7
 
 
14dbe28
56d74ef
14dbe28
 
56d74ef
 
ba76729
 
 
 
 
 
f5eca21
 
553c794
56d74ef
f5eca21
56d74ef
ba76729
14ff283
ba76729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14ff283
ba76729
 
14ff283
ba76729
 
 
 
14ff283
 
ba76729
14ff283
bf019bd
ba76729
bf019bd
 
 
 
 
 
 
ba76729
 
 
 
 
bf019bd
 
 
 
ba76729
 
bf019bd
ba76729
10e28f7
ba76729
bf019bd
ba76729
10e28f7
0a5ce69
553c794
10e28f7
0a5ce69
 
 
553c794
 
0a5ce69
ba76729
 
 
 
 
 
 
 
 
 
 
 
0a5ce69
 
ba76729
 
 
0a5ce69
10e28f7
 
ba76729
10e28f7
553c794
d67e49a
ba76729
 
 
 
 
 
 
 
 
 
 
 
0a5ce69
 
 
 
10e28f7
ba76729
10e28f7
 
553c794
ba76729
10e28f7
 
ba76729
 
 
 
 
0a5ce69
 
 
ba76729
 
553c794
ba76729
 
 
 
10e28f7
 
ba76729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a5ce69
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Zero-Team AI - Biometric Dashboard v23</title>
    
    <!-- Library AI MediaPipe -->
    <script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js" crossorigin="anonymous"></script>

    <style>
        body {
            background: radial-gradient(circle at top, #1e293b, #0f172a);
            color: #f8fafc;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex; flex-direction: column; align-items: center;
            margin: 0; padding: 20px; min-height: 100vh; overflow-x: hidden;
        }

        #startBtn {
            background: linear-gradient(135deg, #a855f7, #ec4899);
            color: white; border: none; padding: 15px 40px;
            font-size: 18px; border-radius: 50px; cursor: pointer;
            font-weight: bold; box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
            transition: all 0.3s ease; margin-bottom: 20px;
            text-transform: uppercase; letter-spacing: 1px;
        }
        #startBtn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6); }

        #mainStatus {
            font-size: 20px; font-weight: bold; color: #94a3b8; 
            background: rgba(15, 23, 42, 0.6); padding: 10px 30px; 
            border-radius: 12px; border: 1px solid #334155; margin-bottom: 25px;
            text-align: center;
        }

        /* --- LAYOUT UTAMA --- */
        .dashboard-container {
            display: flex; flex-direction: row; gap: 25px;
            align-items: flex-start; justify-content: center;
            width: 100%; max-width: 1300px;
        }

        /* PANEL KIRI & KANAN */
        .side-panel {
            background: rgba(15, 23, 42, 0.7);
            border: 2px solid #3b82f6; border-radius: 12px;
            padding: 20px; width: 260px;
            box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
            backdrop-filter: blur(10px);
            display: flex; flex-direction: column; gap: 15px;
        }
        .side-panel.pink-border { border-color: #ec4899; box-shadow: 0 0 20px rgba(236, 72, 153, 0.3); }

        .panel-title { font-size: 12px; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #334155; padding-bottom: 8px; margin-bottom: 5px; }
        .data-item { display: flex; flex-direction: column; gap: 4px; }
        .data-label { font-size: 14px; font-weight: bold; color: #f8fafc; }
        .data-value { font-size: 13px; color: #10b981; }

        /* MONITOR TENGAH */
        .center-stage { display: flex; flex-direction: column; align-items: center; gap: 20px; }
        .canvas-container { position: relative; }
        canvas {
            border: 3px solid #06b6d4; box-shadow: 0 0 25px rgba(6, 182, 212, 0.4); 
            border-radius: 16px; background-color: #000;
            width: 640px; height: 480px; object-fit: cover;
            transform: scaleX(-1); 
        }

        .pose1-anim {
            position: absolute; opacity: 0; border-radius: 8px; z-index: 10; 
            border: 2px solid #eab308; box-shadow: 0 0 15px rgba(234, 179, 8, 0.8); 
            pointer-events: none; transition: opacity 0.2s, left 0.1s, top 0.1s; 
            transform: scaleX(-1);
        }

        /* --- INDIKATOR POSE --- */
        .pose-indicators { display: flex; gap: 15px; justify-content: center; width: 100%; }
        .pose-box {
            background: rgba(15, 23, 42, 0.5); border: 1px solid #334155;
            border-radius: 12px; padding: 15px 10px; text-align: center;
            width: 85px; display: flex; flex-direction: column; align-items: center; justify-content: center;
            transition: all 0.2s ease; opacity: 0.6; 
        }
        .pose-emoji { font-size: 26px; margin-bottom: 8px; }
        .pose-name { font-size: 12px; font-weight: bold; color: #64748b; transition: color 0.2s; }
        .pose-box.active {
            border: 2px solid #eab308; background: rgba(234, 179, 8, 0.1); 
            box-shadow: 0 0 15px rgba(234, 179, 8, 0.5); opacity: 1; transform: scale(1.05); 
        }
        .pose-box.active .pose-name { color: #f8fafc; }

    </style>
</head>
<body>

    <button id="startBtn">▶ Mulai Sistem Deteksi</button>
    <div id="mainStatus">Sistem Menunggu Kamera...</div>

    <div class="dashboard-container">
        <!-- PANEL KIRI (Sistem) -->
        <div class="side-panel">
            <div class="data-item" style="margin-bottom: 10px;">
                <div class="data-label" style="font-size: 18px; color: #38bdf8;">⚙️ Zero-Team AI</div>
            </div>
            <div class="data-item"><div class="data-label">👁️ Computer Vision Engine</div></div>
            <div class="data-item"><div class="data-label">🖐️ Mediapipe Hands: v0.10.x</div></div>
            <div class="data-item"><div class="data-label">🎭 Mediapipe FaceMesh: v0.10.x</div></div>
            <div class="data-item" style="margin-top: 20px;">
                <div class="data-label">🛡️ Status Deteksi:</div>
                <div id="statusKiri" class="data-value" style="color: #94a3b8; font-size: 14px;">Standby</div>
            </div>
        </div>

        <!-- TENGAH (Kamera & Indikator Pose) -->
        <div class="center-stage">
            <div class="canvas-container">
                <!-- Video disembunyikan, dirender ke canvas -->
                <video id="videoElement" style="display: none;" autoplay playsinline></video>
                <canvas id="outputCanvas" width="640" height="480"></canvas>
                <img id="pose1Anim1" class="pose1-anim" src="animasi1.gif" alt="Pose 1">
                <img id="pose1Anim2" class="pose1-anim" src="animasi1.gif" alt="Pose 2">
            </div>

            <div class="pose-indicators">
                <div id="boxPose1" class="pose-box"><div class="pose-emoji">👍</div><div class="pose-name">Thumbs Up</div></div>
                <div id="boxPose2" class="pose-box"><div class="pose-emoji">✌️</div><div class="pose-name">Peace</div></div>
                <div id="boxPose3" class="pose-box"><div class="pose-emoji">👌</div><div class="pose-name">Okay</div></div>
                <div id="boxPose4" class="pose-box"><div class="pose-emoji">🖐️</div><div class="pose-name">Open Palm</div></div>
                <div id="boxPose5" class="pose-box"><div class="pose-emoji">✊</div><div class="pose-name">Fist</div></div>
            </div>
        </div>

        <!-- PANEL KANAN (Biometrik Wajah) -->
        <div style="display: flex; flex-direction: column; gap: 20px;">
            <div class="side-panel">
                <div class="panel-title">Kondisi Biometrik (Wajah)</div>
                <div class="data-item">
                    <div class="data-label">Bentuk Wajah</div>
                    <div id="valWajah" class="data-value" style="color: #cbd5e1;">Memindai...</div>
                </div>
                <div class="data-item">
                    <div class="data-label">Bentuk Rahang</div>
                    <div id="valRahang" class="data-value" style="color: #cbd5e1;">Memindai...</div>
                </div>
                <div class="data-item">
                    <div class="data-label">Karakter Alis</div>
                    <div id="valAlis" class="data-value" style="color: #cbd5e1;">Memindai...</div>
                </div>
            </div>

            <div class="side-panel pink-border">
                <div class="data-item">
                    <div class="panel-title">Kondisi Mood</div>
                    <div id="moodValue" class="data-label" style="font-size: 18px;">Menganalisis...</div>
                </div>
                <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>
            </div>
        </div>
    </div>

    <audio id="audio1" src="suara1.mp3"></audio> 
    <audio id="audio2" src="suara2.mp3"></audio> 
    <audio id="audio3" src="suara3.mp3"></audio> 
    <audio id="audio4" src="suara4.mp3"></audio> 
    <audio id="audio5" src="suara5.mp3"></audio> 

    <script>
        const videoElement = document.getElementById('videoElement');
        const canvasElement = document.getElementById('outputCanvas');
        const canvasCtx = canvasElement.getContext('2d');
        const startBtn = document.getElementById('startBtn');
        const mainStatus = document.getElementById('mainStatus');
        const statusKiri = document.getElementById('statusKiri');
        
        const valWajah = document.getElementById('valWajah');
        const valRahang = document.getElementById('valRahang');
        const valAlis = document.getElementById('valAlis');
        const moodValue = document.getElementById('moodValue');
        const genderValue = document.getElementById('genderValue');

        const anims = [document.getElementById('pose1Anim1'), document.getElementById('pose1Anim2')];
        const sounds = [
            document.getElementById('audio1'), document.getElementById('audio2'),
            document.getElementById('audio3'), document.getElementById('audio4'),
            document.getElementById('audio5')
        ];
        const poseBoxes = [
            document.getElementById('boxPose1'), document.getElementById('boxPose2'),
            document.getElementById('boxPose3'), document.getElementById('boxPose4'),
            document.getElementById('boxPose5')
        ];

        let memoryActivePoses = []; 
        let memoryTimer = 0; 
        let currentFaceLandmarks = null; 

        function getDistance(p1, p2) { return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); }

        // --- ALGORITMA BIOMETRIK & HIJAB ---
        function analyzeFaceBiometrics(faceLandmarks) {
            const dahi = faceLandmarks[10]; const dagu = faceLandmarks[152];
            const pipiKiri = faceLandmarks[234]; const pipiKanan = faceLandmarks[454];
            const rahangKiri = faceLandmarks[132]; const rahangKanan = faceLandmarks[361];
            const alisKiri = faceLandmarks[159]; const alisKiriTengah = faceLandmarks[52];
            
            const faceHeight = getDistance(dahi, dagu);
            const faceWidth = getDistance(pipiKiri, pipiKanan);
            const jawWidth = getDistance(rahangKiri, rahangKanan);

            const ratioFace = faceHeight / faceWidth;
            let faceText = "Bulat / Pendek";
            if (ratioFace > 1.35) faceText = "Oval / Heart";
            else if (ratioFace > 1.20) faceText = "Kotak / Simetris";

            const ratioJaw = jawWidth / faceWidth;
            let jawText = "Tirus / V-Shape";
            if (ratioJaw > 0.85) jawText = "Square-Strong";
            else if (ratioJaw > 0.75) jawText = "Tapered / Normal";

            const ratioEyebrow = getDistance(alisKiri, alisKiriTengah) / faceHeight;
            let browText = "Datar / Straight";
            if (ratioEyebrow > 0.055) browText = "Arched-High";
            else if (ratioEyebrow > 0.040) browText = "Melengkung Alami";

            const mouthWidth = getDistance(faceLandmarks[61], faceLandmarks[291]);
            const mouthHeight = getDistance(faceLandmarks[13], faceLandmarks[14]);
            let moodText = "Netral 😐"; let moodColor = "#3b82f6";
            if (mouthHeight / faceWidth > 0.15) { moodText = "Terkejut 😲"; moodColor = "#a855f7"; }
            else if (mouthWidth / faceWidth > 0.52) { moodText = "Senang 😊"; moodColor = "#10b981"; }

            const headRatio = getDistance(dahi, faceLandmarks[168]) / jawWidth;
            let genderText = "Pria 👨"; let genderColor = "#60a5fa";
            if (headRatio < 0.22 || ratioJaw < 0.75) { 
                genderText = "Wanita 👩 (Hijab/Tirus)"; genderColor = "#f472b6"; 
            }

            return { faceText, jawText, browText, moodText, moodColor, genderText, genderColor };
        }

        // --- ALGORITMA POSE ---
        function classifyPose(landmarks) {
            const indexOpen = landmarks[8].y < landmarks[6].y;
            const middleOpen = landmarks[12].y < landmarks[10].y;
            const ringOpen = landmarks[16].y < landmarks[14].y;
            const pinkyOpen = landmarks[20].y < landmarks[18].y;
            const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08; 

            if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 5, name: "Fist" };
            if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) return { id: 4, name: "Open Palm" };
            if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) return { id: 2, name: "Peace" };
            if (thumbOpen && indexOpen && !middleOpen && !ringOpen && !pinkyOpen) return { id: 1, name: "Thumbs Up" };
            if (getDistance(landmarks[4], landmarks[8]) < 0.05 && middleOpen && ringOpen && pinkyOpen) return { id: 3, name: "Okay" };
            
            return null;
        }

        // SETUP AI (Ringan & Cepat)
        const faceMesh = new FaceMesh({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}`});
        faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: false, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
        faceMesh.onResults((results) => { currentFaceLandmarks = (results.multiFaceLandmarks && results.multiFaceLandmarks.length > 0) ? results.multiFaceLandmarks[0] : null; });

        const hands = new Hands({locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`});
        hands.setOptions({ maxNumHands: 2, modelComplexity: 0, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
        
        hands.onResults((results) => {
            canvasCtx.save();
            canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
            canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);

            if (currentFaceLandmarks) {
                drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_TESSELATION, {color: '#06b6d4', lineWidth: 0.5});
                drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_RIGHT_EYE, {color: '#ec4899', lineWidth: 2});
                drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LEFT_EYE, {color: '#ec4899', lineWidth: 2});
                drawConnectors(canvasCtx, currentFaceLandmarks, FACEMESH_LIPS, {color: '#ec4899', lineWidth: 2});

                const bio = analyzeFaceBiometrics(currentFaceLandmarks);
                valWajah.textContent = bio.faceText; valWajah.style.color = "#10b981";
                valRahang.textContent = bio.jawText; valRahang.style.color = "#10b981";
                valAlis.textContent = bio.browText; valAlis.style.color = "#10b981";
                moodValue.textContent = bio.moodText; moodValue.style.color = bio.moodColor;
                genderValue.textContent = bio.genderText; genderValue.style.color = bio.genderColor;
            } else {
                valWajah.textContent = "Wajah Hilang"; valRahang.textContent = "Wajah Hilang"; valAlis.textContent = "Wajah Hilang";
                valWajah.style.color = "#cbd5e1"; valRahang.style.color = "#cbd5e1"; valAlis.style.color = "#cbd5e1";
                moodValue.textContent = "Menganalisis..."; moodValue.style.color = "#f8fafc";
                genderValue.textContent = "Memindai..."; genderValue.style.color = "#f8fafc";
            }

            let currentIds = [];
            anims.forEach(a => a.style.opacity = '0'); 
            poseBoxes.forEach(b => b.classList.remove('active')); 

            if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
                results.multiHandLandmarks.forEach((landmarks, index) => {
                    drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: index === 0 ? '#ec4899' : '#06b6d4', lineWidth: 4});
                    drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
                    
                    let pose = classifyPose(landmarks);
                    if (pose) {
                        currentIds.push(pose.id);
                        poseBoxes[pose.id - 1].classList.add('active'); 
                        
                        if (pose.id === 1 && anims[index]) {
                            const wrist = landmarks[0];
                            anims[index].style.opacity = '1';
                            anims[index].style.left = `${((1 - wrist.x) * canvasElement.width) - 75}px`; 
                            anims[index].style.top = `${(wrist.y * canvasElement.height) + 30}px`;
                            anims[index].style.width = `150px`; 
                        }
                    }
                });
            }
            canvasCtx.restore();

            if (currentIds.length > 0) {
                statusKiri.textContent = "Aktif & Responsif 🟢"; statusKiri.style.color = "#10b981";
                let newPoses = currentIds.filter(id => !memoryActivePoses.includes(id));
                if (newPoses.length > 0) {
                    sounds.forEach(s => { s.pause(); s.currentTime = 0; }); 
                    const soundToPlay = sounds[newPoses[0] - 1];
                    if (soundToPlay) soundToPlay.play();
                }
                memoryActivePoses = currentIds; 
                memoryTimer = Date.now(); 
            } else if (Date.now() - memoryTimer > 500) {
                statusKiri.textContent = "Menunggu Gerakan Jari 🟡"; statusKiri.style.color = "#eab308";
                memoryActivePoses = []; 
            }
        });

        // --- SISTEM START DENGAN FORCE CAMERA PERMISSION ---
        startBtn.addEventListener('click', async () => {
            startBtn.style.display = 'none'; 
            mainStatus.textContent = "Meminta Izin Kamera...";
            mainStatus.style.color = "#eab308"; // Kuning warning
            
            // Unblock Audio
            sounds.forEach(s => { s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{}); });

            try {
                // PAKSA BROWSER MINTA IZIN KAMERA
                const stream = await navigator.mediaDevices.getUserMedia({ video: true });
                videoElement.srcObject = stream;
                
                mainStatus.textContent = "Mendownload Otak AI (Tunggu 5-10 Detik)...";
                mainStatus.style.color = "#38bdf8"; // Biru loading
                
                const camera = new Camera(videoElement, {
                    onFrame: async () => {
                        // Jalankan AI secara PARALEL agar tidak antri / lag
                        await Promise.all([
                            faceMesh.send({image: videoElement}),
                            hands.send({image: videoElement})
                        ]);
                        
                        // Ubah teks saat frame pertama berhasil masuk
                        if (mainStatus.textContent.includes("Mendownload")) {
                            mainStatus.textContent = "Sistem Aktif & Terkoneksi 🚀";
                            mainStatus.style.color = "#10b981"; // Hijau sukses
                        }
                    },
                    width: 640,
                    height: 480
                });
                camera.start();

            } catch (error) {
                // MUNCULKAN ERROR JIKA KAMERA DIBLOKIR / RUSAK
                alert("GAGAL MENGAKSES KAMERA! \nPastikan kamu sudah menekan 'Allow/Izinkan' pada *pop-up* browser. \n\nDetail Error: " + error.message);
                mainStatus.textContent = "Akses Kamera Ditolak / Error 🔴";
                mainStatus.style.color = "#ef4444";
                startBtn.style.display = 'block'; // Munculkan tombol lagi untuk coba ulang
            }
        });
    </script>
</body>
</html>