-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetVisionStuff.js
38 lines (36 loc) · 1.14 KB
/
getVisionStuff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
HandLandmarker,
FilesetResolver,
} from "https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]";
const video = document.getElementById("webcam");
video.width = window.innerWidth;
async function getVisionStuff() {
// MediaPipe
const filesetResolver = await FilesetResolver.forVisionTasks(
"https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/wasm"
);
const handLandmarker = await HandLandmarker.createFromOptions(
filesetResolver,
{
baseOptions: {
modelAssetPath: `https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,
delegate: "GPU",
},
runningMode: "VIDEO",
numHands: 2,
}
);
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices
.getUserMedia({ video: { facingMode: "user" } })
.then(function (stream) {
video.srcObject = stream;
video.play();
})
.catch(function (error) {
console.error("Unable to access the camera/webcam.", error);
});
}
return { video, handLandmarker };
}
export default getVisionStuff;