HuggingFace-SK commited on
Commit
ecf406d
·
1 Parent(s): b4adec0

color the connections and nodes as the tflite model expects

Browse files
Files changed (1) hide show
  1. templates/browser-detect.html +99 -36
templates/browser-detect.html CHANGED
@@ -1,29 +1,9 @@
1
  <!DOCTYPE html>
2
  <html lang="en"><head></head>
3
  <meta charset="UTF-8">
4
-
5
-
6
- <link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png">
7
-
8
- <meta name="apple-mobile-web-app-title" content="CodePen">
9
-
10
- <link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico">
11
-
12
- <link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-b4b4269c16397ad2f0f7a01bcdf513a1994f4c94b8af2f191c09eb0d601762b1.svg" color="#111">
13
-
14
 
15
 
16
-
17
- <script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-2c7831bb44f98c1391d6a4ffda0e1fd302503391ca806e7fcc7b9b87197aec26.js"></script>
18
-
19
-
20
- <title>CodePen - MediaPipe HandLandmarker Task for web</title>
21
-
22
- <link rel="canonical" href="https://codepen.io/mediapipe-preview/pen/gOKBGPN">
23
-
24
-
25
-
26
-
27
  <style>
28
 
29
 
@@ -45,19 +25,6 @@ body {
45
  </head>
46
 
47
  <body translate="no">
48
- <!-- Copyright 2023 The MediaPipe Authors.
49
-
50
- Licensed under the Apache License, Version 2.0 (the "License");
51
- you may not use this file except in compliance with the License.
52
- You may obtain a copy of the License at
53
-
54
- http://www.apache.org/licenses/LICENSE-2.0
55
-
56
- Unless required by applicable law or agreed to in writing, software
57
- distributed under the License is distributed on an "AS IS" BASIS,
58
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
- See the License for the specific language governing permissions and
60
- limitations under the License. -->
61
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
62
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
63
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
@@ -236,13 +203,89 @@ canvasCtx.stroke();
236
 
237
 
238
  }
239
- for (const landmarks of results.landmarks) {
240
  drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {
241
  color: "#00FF00",
242
  lineWidth: 5
243
  });
244
  drawLandmarks(canvasCtx, landmarks, { color: "#FF0000", lineWidth: 2 });
245
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  var dataurl=cropCanvas(canvasElement,crop_left,crop_top,crop_right-crop_left, crop_bottom-crop_top).toDataURL("image/jpeg", 2);
247
  document.getElementById("output_image").src=dataurl
248
 
@@ -285,6 +328,26 @@ async function predict(inputTensor){
285
 
286
  }
287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
  </script>
290
 
 
1
  <!DOCTYPE html>
2
  <html lang="en"><head></head>
3
  <meta charset="UTF-8">
 
 
 
 
 
 
 
 
 
 
4
 
5
 
6
+ <title>Sign Language Interpreter</title>
 
 
 
 
 
 
 
 
 
 
7
  <style>
8
 
9
 
 
25
  </head>
26
 
27
  <body translate="no">
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
29
  <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
30
  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
 
203
 
204
 
205
  }
206
+ /* for (const landmarks of results.multiHandLandmarks) {
207
  drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {
208
  color: "#00FF00",
209
  lineWidth: 5
210
  });
211
  drawLandmarks(canvasCtx, landmarks, { color: "#FF0000", lineWidth: 2 });
212
+ }*/
213
+ console.log(results)
214
+ const landmarks = results.landmarks;
215
+ if(landmarks[0]){
216
+ var hand=landmarks[0]
217
+
218
+ // Thumb connections
219
+ drawConnection(hand[4], hand[3], '#ffe5b4', 5); // 4-3
220
+ drawConnection(hand[3], hand[2], '#ffe5b4', 5); // 3-2
221
+ drawConnection(hand[2], hand[1], '#ffe5b4', 5); // 2-1
222
+
223
+ // Index connections
224
+ drawConnection(hand[8], hand[7], '#804080', 5); // 8-7
225
+ drawConnection(hand[7], hand[6], '#804080', 5); // 7-6
226
+ drawConnection(hand[6], hand[5], '#804080', 5); // 6-5
227
+
228
+ // Middle connections
229
+ drawConnection(hand[12], hand[11], '#ffcc00', 5); // 12-11
230
+ drawConnection(hand[11], hand[10], '#ffcc00', 5); // 11-10
231
+ drawConnection(hand[10], hand[9], '#ffcc00', 5); // 10-9
232
+
233
+ // Ring connections
234
+ drawConnection(hand[16], hand[15], '#30ff30', 5); // 16-15
235
+ drawConnection(hand[15], hand[14], '#30ff30', 5); // 15-14
236
+ drawConnection(hand[14], hand[13], '#30ff30', 5); // 14-13
237
+
238
+ // Pinky connections
239
+ drawConnection(hand[20], hand[19], '#1565c0', 5); // 20-19
240
+ drawConnection(hand[19], hand[18], '#1565c0', 5); // 19-18
241
+ drawConnection(hand[18], hand[17], '#1565c0', 5); // 18-17
242
+
243
+ drawConnection(hand[0], hand[1], '#808080', 5); // 0-1
244
+ drawConnection(hand[0], hand[5], '#808080', 5); // 0-5
245
+ drawConnection(hand[0], hand[17], '#808080', 5); // 0-17
246
+ drawConnection(hand[5], hand[9], '#808080', 5); // 5-9
247
+ drawConnection(hand[9], hand[13], '#808080', 5); // 9-13
248
+ drawConnection(hand[13], hand[17], '#808080', 5); // 13-17
249
+
250
+ // Thumb
251
+ drawLandmarks(canvasCtx, hand[2], '#ffe5b4'); // Thumb tip (2)
252
+ drawLandmarks(canvasCtx, hand[3], '#ffe5b4'); // Thumb base (3)
253
+ drawLandmarks(canvasCtx, hand[4], '#ffe5b4'); // Thumb base (4)
254
+
255
+ // Index
256
+ drawLandmarks(canvasCtx, hand[6], '#804080'); // Index tip (6)
257
+ drawLandmarks(canvasCtx, hand[7], '#804080'); // Index base (7)
258
+ drawLandmarks(canvasCtx, hand[8], '#804080'); // Index base (8)
259
+
260
+ // Middle
261
+ drawLandmarks(canvasCtx, hand[10], '#ffcc00'); // Middle tip (10)
262
+ drawLandmarks(canvasCtx, hand[11], '#ffcc00'); // Middle base (11)
263
+ drawLandmarks(canvasCtx, hand[12], '#ffcc00'); // Middle base (12)
264
+
265
+ // Ring
266
+ drawLandmarks(canvasCtx, hand[14], '#30ff30'); // Ring tip (14)
267
+ drawLandmarks(canvasCtx, hand[15], '#30ff30'); // Ring base (15)
268
+ drawLandmarks(canvasCtx, hand[16], '#30ff30'); // Ring base (16)
269
+
270
+ // Pinky
271
+ drawLandmarks(canvasCtx, hand[18], '#1565c0'); // Pinky tip (18)
272
+ drawLandmarks(canvasCtx, hand[19], '#1565c0'); // Pinky base (19)
273
+ drawLandmarks(canvasCtx, hand[20], '#1565c0'); // Pinky base (20)
274
+
275
+ drawLandmarks(canvasCtx, hand[0], '#ff3030'); // Wrist (0)
276
+
277
+ drawLandmarks(canvasCtx, hand[1], '#ff3030'); // Palm base (1)
278
+
279
+ drawLandmarks(canvasCtx, hand[5], '#ff3030'); // Index palm (5)
280
+
281
+ drawLandmarks(canvasCtx, hand[9], '#ff3030'); // Middle palm (9)
282
+
283
+ drawLandmarks(canvasCtx, hand[13], '#ff3030'); // Ring palm (13)
284
+
285
+ drawLandmarks(canvasCtx, hand[17], '#ff3030'); // Pinky palm (17)
286
+ }
287
+ // Add more drawing calls for each landmark collection as needed
288
+
289
  var dataurl=cropCanvas(canvasElement,crop_left,crop_top,crop_right-crop_left, crop_bottom-crop_top).toDataURL("image/jpeg", 2);
290
  document.getElementById("output_image").src=dataurl
291
 
 
328
 
329
  }
330
 
331
+ function drawLandmarks(canvasCtx, landmarks, color) {
332
+ canvasCtx.fillStyle = color;
333
+ canvasCtx.strokeStyle = 'white';
334
+ canvasCtx.lineWidth = 1;
335
+ canvasCtx.beginPath();
336
+ canvasCtx.arc(landmarks.x * video.videoWidth, landmarks.y*video.videoHeight, 6, 0, 2 * Math.PI);
337
+ canvasCtx.fill();
338
+ canvasCtx.stroke();
339
+
340
+ }
341
+
342
+ function drawConnection(startNode, endNode, strokeColor, strokeWidth) {
343
+
344
+ canvasCtx.strokeStyle = strokeColor;
345
+ canvasCtx.lineWidth = strokeWidth;
346
+ canvasCtx.beginPath();
347
+ canvasCtx.moveTo(startNode.x * video.videoWidth, startNode.y*video.videoHeight,);
348
+ canvasCtx.lineTo(endNode.x * video.videoWidth, endNode.y*video.videoHeight);
349
+ canvasCtx.stroke();
350
+ }
351
 
352
  </script>
353