codrizsain commited on
Commit
07eae2b
·
verified ·
1 Parent(s): 6abfe28

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +154 -0
index.html ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="id">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Hand Detector - Realtime</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>
11
+
12
+ <style>
13
+ /* Desain simpel dark mode ala progamer */
14
+ body {
15
+ background-color: #0f172a; /* Navy dark background */
16
+ color: white;
17
+ font-family: sans-serif;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ margin-top: 20px;
22
+ }
23
+ .monitor-container {
24
+ position: relative;
25
+ margin-top: 20px;
26
+ }
27
+ /* Efek neon biru dan pink pada kanvas */
28
+ canvas {
29
+ border: 2px solid #3b82f6;
30
+ box-shadow: 0 0 15px #ec4899;
31
+ border-radius: 8px;
32
+ background-color: #000;
33
+ max-width: 100%;
34
+ }
35
+ /* GIF diletakkan mengambang di tengah kanvas */
36
+ #responGif {
37
+ position: absolute;
38
+ top: 50%;
39
+ left: 50%;
40
+ transform: translate(-50%, -50%);
41
+ display: none; /* Disembunyikan sampai AI mendeteksi tangan */
42
+ border-radius: 10px;
43
+ z-index: 10;
44
+ width: 250px;
45
+ }
46
+ button {
47
+ background-color: #ec4899;
48
+ color: white;
49
+ border: none;
50
+ padding: 12px 24px;
51
+ font-size: 16px;
52
+ border-radius: 5px;
53
+ cursor: pointer;
54
+ margin-bottom: 10px;
55
+ font-weight: bold;
56
+ }
57
+ button:hover { background-color: #db2777; }
58
+ </style>
59
+ </head>
60
+ <body>
61
+
62
+ <h2>✋ Real-Time Hand Detector</h2>
63
+ <p>Data Pengguna Diproses Langsung di Browser Anda.</p>
64
+
65
+ <button id="startBtn">Mulai Kamera & Izinkan Suara</button>
66
+
67
+ <div class="monitor-container">
68
+ <video id="videoElement" style="display: none;" autoplay playsinline></video>
69
+ <canvas id="outputCanvas" width="640" height="480"></canvas>
70
+ <img id="responGif" src="animasi.gif" alt="Animasi AI">
71
+ </div>
72
+
73
+ <audio id="responAudio" src="suara.mp3"></audio>
74
+
75
+ <script>
76
+ const videoElement = document.getElementById('videoElement');
77
+ const canvasElement = document.getElementById('outputCanvas');
78
+ const canvasCtx = canvasElement.getContext('2d');
79
+ const responGif = document.getElementById('responGif');
80
+ const responAudio = document.getElementById('responAudio');
81
+ const startBtn = document.getElementById('startBtn');
82
+
83
+ let lastTriggerTime = 0;
84
+
85
+ // Inisialisasi MediaPipe Hands
86
+ const hands = new Hands({locateFile: (file) => {
87
+ return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`;
88
+ }});
89
+
90
+ hands.setOptions({
91
+ maxNumHands: 1,
92
+ modelComplexity: 0, // Mode paling ringan
93
+ minDetectionConfidence: 0.5,
94
+ minTrackingConfidence: 0.5
95
+ });
96
+
97
+ // Logika saat AI mendapatkan frame video
98
+ hands.onResults((results) => {
99
+ canvasCtx.save();
100
+ canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
101
+ canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
102
+
103
+ let handDetected = false;
104
+
105
+ if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
106
+ handDetected = true;
107
+ for (const landmarks of results.multiHandLandmarks) {
108
+ // Gambar kerangka tangan dengan warna neon
109
+ drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: '#ec4899', lineWidth: 4});
110
+ drawLandmarks(canvasCtx, landmarks, {color: '#3b82f6', lineWidth: 2});
111
+ }
112
+ }
113
+ canvasCtx.restore();
114
+
115
+ // Logika Trigger
116
+ const currentTime = Date.now() / 1000;
117
+ if (handDetected && (currentTime - lastTriggerTime > 3)) {
118
+
119
+ // Tampilkan GIF dan putar suara
120
+ responGif.style.display = 'block';
121
+ responAudio.currentTime = 0;
122
+ responAudio.play();
123
+ lastTriggerTime = currentTime;
124
+
125
+ // Sembunyikan GIF setelah 2 detik
126
+ setTimeout(() => {
127
+ responGif.style.display = 'none';
128
+ }, 2000);
129
+ }
130
+ });
131
+
132
+ // Event saat tombol ditekan
133
+ startBtn.addEventListener('click', () => {
134
+ startBtn.style.display = 'none'; // Sembunyikan tombol
135
+
136
+ // Pancing izin audio browser
137
+ responAudio.play().then(() => {
138
+ responAudio.pause();
139
+ responAudio.currentTime = 0;
140
+ }).catch(()=>console.log("Audio siap"));
141
+
142
+ // Nyalakan Kamera
143
+ const camera = new Camera(videoElement, {
144
+ onFrame: async () => {
145
+ await hands.send({image: videoElement});
146
+ },
147
+ width: 640,
148
+ height: 480
149
+ });
150
+ camera.start();
151
+ });
152
+ </script>
153
+ </body>
154
+ </html>