Skip to content
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

FaceMesh faceOval points not in order around the face #67

Closed
dano1234 opened this issue Nov 18, 2023 · 5 comments · Fixed by #68
Closed

FaceMesh faceOval points not in order around the face #67

dano1234 opened this issue Nov 18, 2023 · 5 comments · Fixed by #68

Comments

@dano1234
Copy link

Here is a sketch with old ML5 facemesh making a mask
https://editor.p5js.org/dano/sketches/2ULaz2E0v

Here is a sketch with new ML5 facemesh making a mask
https://editor.p5js.org/dano/sketches/-3gKqxIZD

It appears that all the points for the "faceOval" property come in but they are not in a consecutive order around the face.

As ever thanks for this amazing library

@shiffman
Copy link
Member

I took a quick look at this! I think the order of the points is coming directly from the tf.js model. This is the only documentation I could find.

We also recently merged #45 which added in bounding boxes and center points for all of the parts. I wonder if we should "re-sort" the faceOval points (or any other parts?) @gohai, is this something that you or any of the DURF students encountered?

I made this example many years ago to sort the vertices of a polygon in case it's helpful:

https://editor.p5js.org/codingtrain/sketches/GFlV5R9Ur

@ziyuan-linn maybe you want to take a look at this?

@ziyuan-linn
Copy link
Member

Sounds great! I am happy to look into this.

I think the original facemesh came with an annotations object but the new one didn't, so we are now manually creating the annotations within ml5. Apparently, we forgot to take the order of the vertices into account. I will take a look at the old tfjs facemesh library to see how they generate the annotations object.

In addition to using a vertex-sorting algorithm, we could also consider manually creating a map so we can sort the vertices in linear time.

@gohai
Copy link
Member

gohai commented Nov 29, 2023

Thanks for the report @dano1234! This didn't come up, wasn't attempted, in the summer.

Turns out that MediaPipe, the new underlying model, returns points in a particular order, but for creating contours, we can't simply pair them up sequentially. Here is how Google's own implementation gets this done. And this is the source of these pairings. We should amend addKeypoints to take care of this for the contours it creates.

@ziyuan-linn @shiffman I'd be happy to address this Saturday morning (unless Peter already fixed this while I am writing this message 😅)

gohai added a commit that referenced this issue Dec 2, 2023
…to account

Note: this still doesn't work perfectly for non-contiguous contours, such as lips, but it matches the behavior of Google's demo here: https://storage.googleapis.com/tfjs-models/demos/face-landmarks-detection/index.html?model=mediapipe_face_mesh

This should fix #67.
gohai added a commit that referenced this issue Dec 2, 2023
…to account

Note: this still doesn't work perfectly for non-contiguous contours, such as lips, but it matches the behavior of Google's demo here: https://storage.googleapis.com/tfjs-models/demos/face-landmarks-detection/index.html?model=mediapipe_face_mesh

This should fix #67.
gohai added a commit that referenced this issue Dec 2, 2023
…to account

Note: this still doesn't work perfectly for non-contiguous contours, such as lips, but it matches the behavior of Google's demo here: https://storage.googleapis.com/tfjs-models/demos/face-landmarks-detection/index.html?model=mediapipe_face_mesh

Fixes: #67.
gohai added a commit that referenced this issue Dec 2, 2023
…to account

Note: this still doesn't work perfectly for non-contiguous contours, such as lips, but it matches the behavior of Google's demo here: https://storage.googleapis.com/tfjs-models/demos/face-landmarks-detection/index.html?model=mediapipe_face_mesh

Fixes: #67.
@gohai gohai closed this as completed in #68 Dec 2, 2023
gohai added a commit that referenced this issue Dec 2, 2023
…to account (#68)

Note: this still doesn't work perfectly for non-contiguous contours, such as lips, but it matches the behavior of Google's demo here: https://storage.googleapis.com/tfjs-models/demos/face-landmarks-detection/index.html?model=mediapipe_face_mesh

Fixes: #67.
@gohai
Copy link
Member

gohai commented Dec 2, 2023

@dano1234 Should be fixed in upcoming test builds! (Here's a preview using a local ml5.js.)

We did change the API since the initial build: the points moved to .keypoints, so that every contour also has an (easier to use) .centerX, .centerY properties etc..

@dano1234
Copy link
Author

dano1234 commented Dec 4, 2023

Fantastic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants