@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from "react";
5
5
import {
6
6
FilesetResolver ,
7
7
GestureRecognizer ,
8
+ DrawingUtils ,
8
9
NormalizedLandmark ,
9
10
} from "@mediapipe/tasks-vision" ;
10
11
@@ -87,8 +88,7 @@ export default function Home() {
87
88
} else {
88
89
prevX = prevY = 0 ;
89
90
}
90
-
91
- drawLandmarks ( landmarks , landmarkCanvasCtx , width , height ) ;
91
+ drawLandmarks ( landmarks , landmarkCanvasCtx , width , height , connected ) ;
92
92
} ) ;
93
93
}
94
94
@@ -104,23 +104,18 @@ export default function Home() {
104
104
landmarks : NormalizedLandmark [ ] ,
105
105
ctx : CanvasRenderingContext2D ,
106
106
width : number ,
107
- height : number
107
+ height : number ,
108
+ connected : boolean
108
109
) => {
110
+ const drawingUtils = new DrawingUtils ( ctx ) ;
109
111
ctx . clearRect ( 0 , 0 , width , height ) ;
110
- ctx . fillStyle = "white" ;
111
-
112
- landmarks . forEach ( ( landmark , ind ) => {
113
- const x = ( 1 - landmark . x ) * width ;
114
- const y = landmark . y * height ;
115
-
116
- ctx . fillStyle = "#3370d4" ;
117
- if ( ind === THUMB_TIP_INDEX || ind === INDEX_FINGER_TIP_INDEX ) {
118
- ctx . fillStyle = "#c82124" ;
119
- }
120
- ctx . beginPath ( ) ;
121
- ctx . arc ( x , y , 5 , 0 , 2 * Math . PI ) ;
122
- ctx . closePath ( ) ;
123
- ctx . fill ( ) ;
112
+ drawingUtils . drawConnectors ( landmarks , GestureRecognizer . HAND_CONNECTIONS , {
113
+ color : "#00FF00" ,
114
+ lineWidth : connected ? 5 : 2 ,
115
+ } ) ;
116
+ drawingUtils . drawLandmarks ( landmarks , {
117
+ color : "#FF0000" ,
118
+ lineWidth : 1 ,
124
119
} ) ;
125
120
} ;
126
121
@@ -182,6 +177,9 @@ export default function Home() {
182
177
className = { "fixed inset-0 z-50" }
183
178
width = { canvasSize [ 0 ] || 640 }
184
179
height = { canvasSize [ 1 ] || 480 }
180
+ style = { {
181
+ transform : "rotateY(180deg)" ,
182
+ } }
185
183
/>
186
184
< canvas
187
185
ref = { strokeCanvasRef }
0 commit comments