@@ -6,7 +6,7 @@ let videoWidth, videoHeight,
66 ringFinger : [ 0 , 13 , 14 , 15 , 16 ] ,
77 pinky : [ 0 , 17 , 18 , 19 , 20 ]
88 } ;
9-
9+ let model ;
1010const VIDEO_WIDTH = 640 ;
1111const VIDEO_HEIGHT = 500 ;
1212const mobile = false ;
@@ -15,13 +15,27 @@ const state = {
1515 backend : 'webgl'
1616} ;
1717
18- function drawPoint ( ctx , y , x , r ) {
19- ctx . beginPath ( ) ;
20- ctx . arc ( x , y , r , 0 , 2 * Math . PI ) ;
21- ctx . fill ( ) ;
22- }
23-
2418function drawKeypoints ( ctx , keypoints ) {
19+ function drawPoint ( ctx , y , x , r ) {
20+ ctx . beginPath ( ) ;
21+ ctx . arc ( x , y , r , 0 , 2 * Math . PI ) ;
22+ ctx . fill ( ) ;
23+ }
24+
25+ function drawPath ( ctx , points , closePath ) {
26+ const region = new Path2D ( ) ;
27+ region . moveTo ( points [ 0 ] [ 0 ] , points [ 0 ] [ 1 ] ) ;
28+ for ( let i = 1 ; i < points . length ; i ++ ) {
29+ const point = points [ i ] ;
30+ region . lineTo ( point [ 0 ] , point [ 1 ] ) ;
31+ }
32+
33+ if ( closePath ) {
34+ region . closePath ( ) ;
35+ }
36+ ctx . stroke ( region ) ;
37+ }
38+
2539 const keypointsArray = keypoints ;
2640
2741 for ( let i = 0 ; i < keypointsArray . length ; i ++ ) {
@@ -38,22 +52,6 @@ function drawKeypoints(ctx, keypoints) {
3852 }
3953}
4054
41- function drawPath ( ctx , points , closePath ) {
42- const region = new Path2D ( ) ;
43- region . moveTo ( points [ 0 ] [ 0 ] , points [ 0 ] [ 1 ] ) ;
44- for ( let i = 1 ; i < points . length ; i ++ ) {
45- const point = points [ i ] ;
46- region . lineTo ( point [ 0 ] , point [ 1 ] ) ;
47- }
48-
49- if ( closePath ) {
50- region . closePath ( ) ;
51- }
52- ctx . stroke ( region ) ;
53- }
54-
55- let model ;
56-
5755async function setupCamera ( ) {
5856 if ( ! navigator . mediaDevices || ! navigator . mediaDevices . getUserMedia ) {
5957 throw new Error (
@@ -65,8 +63,6 @@ async function setupCamera() {
6563 'audio' : false ,
6664 'video' : {
6765 facingMode : 'user' ,
68- // Only setting the video to a specified size in order to accommodate a
69- // point cloud, so on mobile devices accept the default size.
7066 width : mobile ? undefined : VIDEO_WIDTH ,
7167 height : mobile ? undefined : VIDEO_HEIGHT
7268 } ,
0 commit comments