-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Models methods & properties (WIP) #93
Changes from 23 commits
10d0ead
59c01c5
c179590
0cdb95f
7fc82e0
c7e19e2
d66cb0c
3f8dcbd
6c12478
c29a9d0
803f19b
912bfb3
4212958
17c6799
5c93541
f4a1ea2
b51a9c6
00779e1
e9c3470
1b9a59c
f775050
3124626
db4d49e
cb3640e
0f5997f
e296126
c765187
b833365
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ Within each pose, we only want to draw the skeleton connections that the model h | |
|
||
We iterate through the connections array, with each item being a link of `pointA` and `pointB`. For instance, `connections[1]` is `[0, 2]`, where 0 is the index of `pointA` and 2 is the index of `pointB`. Thus, `let pointAIndex = connections[j][0];` means we get the starting point (pointA) of the link `j`, and `let pointBIndex = connections[j][1];` means we get the ending point (pointB) of the link `j`. | ||
|
||
Use the indices to retrieve the `pointA` and `pointB` objects from the `pose.keypoints`. As with all keypoints, `pointA` is an object with properties `x`, `y`, and `score`. | ||
Use the indices to retrieve the `pointA` and `pointB` objects from the `pose.keypoints`. As with all keypoints, `pointA` is an object with properties `x`, `y`, and `confidence`. | ||
|
||
```javascript | ||
for (let j = 0; j < connections.length; j++) { | ||
|
@@ -240,12 +240,52 @@ let bodypose = ml5.bodypose(?model, ?options, ?callback); | |
|
||
- **options**: Optional. An object to change the default configuration of the model. The available options differ depending on which of the two underlying models are used. | ||
|
||
See See the [MoveNet documentation](https://github.com/tensorflow/tfjs-models/tree/master/pose-detection/src/movenet#create-a-detector) and the [BlazePose documentation](https://github.com/tensorflow/tfjs-models/tree/master/pose-detection/src/blazepose_tfjs#create-a-detector) for more information on available options. | ||
The default and available options are: | ||
|
||
- **callback(bodypose, error)**: Optional. A "callback" function that runs when the model has been successfully loaded. Most ml5.js example call `ml5.bodyPose()` in the p5.js `preload()` function and no callback is needed. | ||
```javascript | ||
{ | ||
modelType: "MULTIPOSE_LIGHTNING" // "MULTIPOSE_LIGHTNING", "SINGLEPOSE_LIGHTNING", or "SINGLEPOSE_THUNDE" | ||
enableSmoothing: true, | ||
minPoseScore: 0.25, | ||
multiPoseMaxDimension: 256, | ||
enableTracking: true, | ||
trackerType: "boundingBox", // "keypoint" or "boundingBox" | ||
trackerConfig: {}, | ||
modelUrl: undefined, | ||
} | ||
``` | ||
|
||
Options for both models: | ||
- _modelType_ - Optional | ||
- String: The type of model to use. Default: "MULTIPOSE_LIGHTNING". | ||
- _enableSmoothing_ - Optional | ||
- Boolean: Whether to smooth the pose landmarks across different input images to reduce jitter. Default: true. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for point that out! It was in the previous commit but I accidentally removed it when solving conflict when updating. Will fix it now. |
||
Options for the BlazePose model only: | ||
- _runtime_ - Optional | ||
- String: Either "tfjs" or "mediapipe". Default: "tfjs" | ||
- _enableSegmentation_ - Optional | ||
- Boolean: A boolean indicating whether to generate the segmentation mask. | ||
- _smoothSegmentation_ - Optional | ||
- Boolean: whether to filters segmentation masks across different input images to reduce jitter. | ||
|
||
For using custom or offline models | ||
- _modelUrl_ - Optional | ||
- String: The file path or URL to the MoveNet model. | ||
- _solutionPath_ - Optional | ||
- String: The file path or URL to the mediaPipe BlazePose model. | ||
- _detectorModelUrl_ - Optional | ||
- String: The file path or URL to the tfjs BlazePose detector model. | ||
- _landmarkModelUrl_ - Optional | ||
- String: The file path or URL to the tfjs BlazePose landmark model. | ||
|
||
See See the [MoveNet documentation](https://github.com/tensorflow/tfjs-models/tree/master/pose-detection/src/movenet#create-a-detector) and the [BlazePose documentation](https://github.com/tensorflow/tfjs-models/tree/master/pose-detection/src/blazepose_tfjs#create-a-detector) for more information on available options. | ||
|
||
- **callback(bodypose)**: Optional. A "callback" function that runs when the model has been successfully loaded. Most ml5.js example call `ml5.bodyPose()` in the p5.js `preload()` function and no callback is needed. | ||
|
||
**Returns:** | ||
The bodyPose object. | ||
|
||
- **Object**: The bodyPose object. This object contains the methods to start and stop the pose detection process. | ||
|
||
### bodypose.detectStart() | ||
|
||
|
@@ -257,16 +297,15 @@ bodypose.detectStart(media, callback); | |
|
||
**Parameters:** | ||
|
||
- **media**: An HMTL or p5.js image, video, or canvas element to run the estimation on. | ||
|
||
- **callback(results, error)**: A callback function to handle the results of the pose estimation. See below for an example of the model's results: | ||
- **media**: An HTML or p5.js image, video, or canvas element to run the estimation on. | ||
- **callback(results)**: A callback function to handle the results of the pose estimation. See below for an example of the model's results: | ||
|
||
```javascript | ||
[ | ||
{ | ||
box: { width, height, xMax, xMin, yMax, yMin }, | ||
id: 1, | ||
keypoints: [{ x, y, score, name }, ...], | ||
keypoints: [{ x, y, confidence, name }, ...], | ||
left_ankle: { x, y, confidence }, | ||
left_ear: { x, y, confidence }, | ||
left_elbow: { x, y, confidence }, | ||
|
@@ -302,8 +341,8 @@ bodypose.detectStart(media, callback); | |
{ | ||
box: { width, height, xMax, xMin, yMax, yMin }, | ||
id: 1, | ||
keypoints: [{ x, y, z, score, name }, ...], | ||
keypoints3D: [{ x, y, z, score, name }, ...], | ||
keypoints: [{ x, y, z, confidence, name }, ...], | ||
keypoints3D: [{ x, y, z, confidence, name }, ...], | ||
left_ankle: { x, y, z, confidence }, | ||
left_ear: { x, y, z, confidence }, | ||
left_elbow: { x, y, z, confidence }, | ||
|
@@ -324,6 +363,26 @@ This method can be called to stop the continuous pose estimation process. | |
bodypose.detectStop(); | ||
``` | ||
|
||
For example, you can toggle the pose estimation with click event in p5.js by using this function as follows: | ||
|
||
```javascript | ||
// Toggle detection when mouse is pressed | ||
function mousePressed() { | ||
toggleDetection(); | ||
} | ||
|
||
// Call this function to start and stop detection | ||
function toggleDetection() { | ||
if (isDetecting) { | ||
bodypose.detectStop(); | ||
isDetecting = false; | ||
} else { | ||
bodyPose.detectStart(video, gotPoses); | ||
isDetecting = true; | ||
} | ||
} | ||
``` | ||
|
||
### bodypose.detect() | ||
|
||
This method runs the pose estimation on an image once, not continuously! | ||
|
@@ -336,4 +395,39 @@ bodypose.detect(media, ?callback); | |
|
||
- **media**: An HTML or p5.js image, video, or canvas element to run the estimation on. | ||
|
||
- **callback(output, error)**: Optional. A callback function to handle the results of the pose estimation. See the results above for an example of the model's output. | ||
- **callback(results)**: Optional. A callback function to handle the results of the pose estimation. See the results above for an example of the model's output. | ||
|
||
### bodypose.getSkeleton() | ||
|
||
This method returns an array of arrays, where each sub-array contains the indices of the connected keypoints. | ||
|
||
```javascript | ||
const connections = bodypose.getSkeleton(); | ||
``` | ||
|
||
**Returns:** | ||
|
||
- **Array**: An array of arrays representing the connections between keypoints. For example, using BlazePose model will returns: | ||
|
||
```js | ||
[ | ||
[0,1], | ||
[0,4], | ||
[1,2], | ||
... | ||
[28,32], | ||
[29,31], | ||
[30,32] | ||
] | ||
``` | ||
|
||
This array represents the connections between keypoints, please refer to these images to understand the connections: | ||
<center> | ||
<h3>MoveNet</h3> | ||
<img style="display:block; max-width:30%" alt="MoveNet keypoint diagram" src="https://camo.githubusercontent.com/c3641b718d7e613b2ce111a6a4575e88ca35a60cb325efdd9113c453b2a09301/68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f6d6f76656e65742f636f636f2d6b6579706f696e74732d3530302e706e67"> | ||
</center> <br/> | ||
<center> | ||
<h3>BlazePose</h3> | ||
<img style="display:block; max-width:30%" alt="BlazePose keypoint diagram" src="https://camo.githubusercontent.com/17082997c33fc6d2544c4aea33d9898860cf902ed5a0b865527d1dd91bbc7efa/68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f6d65646961706970652f626c617a65706f73652d6b6579706f696e74732d757064617465642e706e67"> | ||
</center> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered we still have error, it's just we don't use it in example code. We could double check this after soft launch, feel free to create a Issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will consider putting it back with the
?
indicating that it is optional. It is actually quite important for debugging.