-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
58 lines (54 loc) · 1.75 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import './index.css'
import './style.css'
import javascriptLogo from './javascript.svg'
import viteLogo from '/vite.svg'
import { setupCounter } from './counter.js'
import {
GestureRecognizer,
FilesetResolver,
} from '@mediapipe/tasks-vision';
import {
askWebcamPermissions,
captureCamera
} from './webcam';
import {
predictWebcam
} from './predict';
window.onload = async () => {
const vision = await FilesetResolver.forVisionTasks("https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/wasm");
console.log(vision);
const gestureRecognizer = await GestureRecognizer.createFromOptions(vision, {
baseOptions: {
modelAssetPath:
"/gesture_recognizer.task",
delegate: "GPU"
},
runningMode: "VIDEO",
numHands: 2
});
const video = document.querySelector("#video-container video");
const canvas = document.querySelector("#video-container canvas");
const ctx = canvas.getContext("2d");
await askWebcamPermissions();
await captureCamera(video);
video.addEventListener("loadeddata", () => predictWebcam(video, gestureRecognizer, ctx));
}
//const poses = await detector.estimatePoses(image);
//document.querySelector('#app').innerHTML = `
// <div>
// <a href="https://vitejs.dev" target="_blank">
// <img src="${viteLogo}" class="logo" alt="Vite logo" />
// </a>
// <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
// <img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
// </a>
// <h1>Hello Vite!</h1>
// <div class="card">
// <button id="counter" type="button"></button>
// </div>
// <p class="read-the-docs">
// Click on the Vite logo to learn more
// </p>
// </div>
//`
setupCounter(document.querySelector('#counter'))