Skip to content

Commit 5259fa0

Browse files
committed
add option filtering
1 parent 27e2378 commit 5259fa0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

examples/Handpose/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function setup() {
77
video = createCapture(VIDEO);
88
video.size(width, height);
99

10-
const options = { maxHands: 2 };
10+
const options = {};
1111
handpose = ml5.handpose(video, options, modelReady);
1212

1313
// This sets up an event that fills the global variable "predictions"

src/Handpose/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ class Handpose extends EventEmitter {
3939
async loadModel() {
4040
const pipeline = handPoseDetection.SupportedModels.MediaPipeHands;
4141
const modelConfig = {
42-
runtime: "mediapipe", // use MediaPipe runtime by default
42+
maxHands: this.config?.maxHands ?? 2, // detect up to 2 hands by default
43+
runtime: this.config?.runtime ?? "mediapipe", // use MediaPipe runtime by default
44+
modelType: this.config?.modelType ?? "full", // use full version of the model by default
4345
solutionPath: "https://cdn.jsdelivr.net/npm/@mediapipe/hands", // fetch model from mediapipe server
44-
...this.config,
4546
};
4647

4748
this.model = await handPoseDetection.createDetector(pipeline, modelConfig);
@@ -66,10 +67,11 @@ class Handpose extends EventEmitter {
6667
throw new Error("No input image found.");
6768
}
6869
await mediaReady(image, false);
69-
const { flipHorizontal } = this.config;
70-
const predictions = await this.model.estimateHands(image, {
71-
flipHorizontal,
72-
});
70+
const options = {
71+
flipHorizontal: this.config?.flipHorizontal ?? false, // do not horizontally flip the prediction by default
72+
};
73+
const predictions = await this.model.estimateHands(image, options);
74+
//TODO: customize the output for easier use
7375
const result = predictions;
7476

7577
this.emit("hand", result);

0 commit comments

Comments
 (0)