Skip to content

Commit c73a9f3

Browse files
committed
feat: downgrade mediapipe to use drawing utils
1 parent b612d33 commit c73a9f3

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@mediapipe/tasks-vision": "^0.10.20",
12+
"@mediapipe/tasks-vision": "0.10.18",
1313
"@next/third-parties": "^15.1.4",
1414
"next": "15.1.4",
1515
"react": "^19.0.0",

src/app/page.tsx

+15-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from "react";
55
import {
66
FilesetResolver,
77
GestureRecognizer,
8+
DrawingUtils,
89
NormalizedLandmark,
910
} from "@mediapipe/tasks-vision";
1011

@@ -87,8 +88,7 @@ export default function Home() {
8788
} else {
8889
prevX = prevY = 0;
8990
}
90-
91-
drawLandmarks(landmarks, landmarkCanvasCtx, width, height);
91+
drawLandmarks(landmarks, landmarkCanvasCtx, width, height, connected);
9292
});
9393
}
9494

@@ -104,23 +104,18 @@ export default function Home() {
104104
landmarks: NormalizedLandmark[],
105105
ctx: CanvasRenderingContext2D,
106106
width: number,
107-
height: number
107+
height: number,
108+
connected: boolean
108109
) => {
110+
const drawingUtils = new DrawingUtils(ctx);
109111
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,
124119
});
125120
};
126121

@@ -182,6 +177,9 @@ export default function Home() {
182177
className={"fixed inset-0 z-50"}
183178
width={canvasSize[0] || 640}
184179
height={canvasSize[1] || 480}
180+
style={{
181+
transform: "rotateY(180deg)",
182+
}}
185183
/>
186184
<canvas
187185
ref={strokeCanvasRef}

0 commit comments

Comments
 (0)