Skip to content

Commit

Permalink
Move gesture recognizer defaults from constants.ts to async create me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
mmounirf committed Apr 1, 2024
1 parent 443b14d commit 6c91043
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/lib/Recognizer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
FilesetResolver,
GestureRecognizer,
type GestureRecognizerOptions,
type GestureRecognizerResult,
} from "@mediapipe/tasks-vision";
import { defaultOptions, defaultWasmFileset } from "./constants";
import type { WasmFileset } from "./types";

/**
Expand Down Expand Up @@ -68,8 +68,31 @@ export default class Recognizer {
vision?: WasmFileset;
options?: GestureRecognizerOptions;
}): Promise<Recognizer> {
/**
* Default WebAssembly fileset required for MediaPipe Task APIs.
* https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm
*/
const defaultWasmFileset = await FilesetResolver.forVisionTasks(
"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm",
);

const recognizerVision = vision || defaultWasmFileset;

/**
* Default options for the gesture recognizer.
*/
const defaultOptions: GestureRecognizerOptions = {
runningMode: "VIDEO",
baseOptions: {
// Pretrained model for gesture recognition.
// https://developers.google.com/mediapipe/solutions/vision/gesture_recognizer#models
modelAssetPath:
"https://storage.googleapis.com/mediapipe-models/gesture_recognizer/gesture_recognizer/float16/1/gesture_recognizer.task",
delegate: "GPU",
},
numHands: 1,
};

const recognizerOptions = options || defaultOptions;

const recognizer = new Recognizer(videoElement, recognizerVision, recognizerOptions);
Expand Down

0 comments on commit 6c91043

Please sign in to comment.