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

Exporting face as UV Texture Map #1698

Closed
mufaawan opened this issue Mar 3, 2021 · 17 comments
Closed

Exporting face as UV Texture Map #1698

mufaawan opened this issue Mar 3, 2021 · 17 comments
Assignees
Labels
legacy:face mesh Issues related to Face Mesh type:feature Enhancement in the New Functionality or Request for a New Solution

Comments

@mufaawan
Copy link

mufaawan commented Mar 3, 2021

I want to store image of detected face as Texture Map. How can I do that? I have identified all normalized landmarks using FaceMesh. How much can I acheive similar to below image?

https://i.pinimg.com/originals/b2/44/ca/b244ca9f645e1c8cf5f365e8f1c73123.jpg
image

image

@sgowroji sgowroji self-assigned this Mar 4, 2021
@sgowroji sgowroji added legacy:face mesh Issues related to Face Mesh stat:awaiting response Waiting for user response type:support General questions labels Mar 4, 2021
@sgowroji
Copy link

sgowroji commented Mar 4, 2021

Hi @mufaawan Could you please share details in which platform are you targeting the above.

@mufaawan
Copy link
Author

mufaawan commented Mar 4, 2021

@sgowroji I would like to have Python based solution. But C++ would also work for me.

@mufaawan
Copy link
Author

mufaawan commented Mar 6, 2021

@sgowroji waiting for response :)

@sgowroji sgowroji added type:feature Enhancement in the New Functionality or Request for a New Solution and removed stat:awaiting response Waiting for user response type:support General questions labels Mar 8, 2021
@sgowroji sgowroji assigned mgyong and unassigned sgowroji Mar 8, 2021
@mgyong
Copy link

mgyong commented Mar 9, 2021

@kostyaby Any comments on this?

@kostyaby
Copy link

Hey @mufaawan,

What you are trying to do is a bit custom, so please be ready to code some additional logic. Luckily, you should be able to implement it in Python as the approach I'm about to suggest only requires the MediaPipe Face Mesh solution

First, you need'll some face topology that establishes semantic relationship between 3D positions of the face mesh vertices and some 2D texture coordinates. I'd start with the canonical face model used in MediaPipe Face Geometry module (UV visualization; Face Geometry formats: metadata schema, mesh 3D schema, metadata text). What you need at this point is XYZ <-> UV correspondence + triangular topology, so grabbing them from the Face Geometry metadata file is a good starting point for now (you can tweak the mapping / topology later if needed)

The next thing you need is to warp the image by applying UV -> XYZ mapping. You'll do it triangle-by-triangle of the chosen topology like in this OpenCV tutorial. First, use cv::getAffineTransform to compute an affine transform matrix for two sets of three 2D point (XYZ coords <-> UV coords for a single triangle). Then, use that matrix with cv::warpAffine to warp a triangular patch of the input camera stream into a triangle patch on your result image

Those steps should do the trick. Please, let me know if you have any questions!

@sgowroji
Copy link

Hi @mufaawan, Did you get a chance to go through the above comment. Thanks!

@sgowroji
Copy link

Hi @mufaawan, Assuming you got the clear understanding with the above comments, we are closing this issue. Please feel free to open if you still not clear.

@mufaawan
Copy link
Author

@kostyaby I am here to thank you a lot for the great guidance. I have achieved what I wanted to. I worked last week on what you have guided me with. I really appreciate the details answer.

Thank you @sgowroji for routing my request to relevant person. :)

@JJBT
Copy link

JJBT commented Sep 20, 2021

@mufaawan could you please share a code-snippet that converts face to Texture Map. I would be really appreciate it.

@Hisham-Tariq
Copy link

Hisham-Tariq commented Oct 11, 2021

@mufaawan Hi i need help in my FYP i am trying to create this as a Final Year project of my CS degree i need your help.

@CodingBitsDev
Copy link

I'm currently standing in front of the same problem. I'm struggling to understand the topology part of the explanation. A code example in how to use the face geometry metadata for this would be appreciated.

@kostyaby
Copy link

kostyaby commented Dec 6, 2021

Hey @Renji3,

In graphics, there's a concept of Polygon mesh: in order to represent some 3D objects, you define 2 buffers: vertex buffer (defines vertices of the mesh) and index buffer (defines faces of the mesh; those connect the vertices into some topology). A commonly used kind of polygon meshes is a triangular mesh; for those meshes, faces are always 3D triangles and not any other complex shapes

What you need at this point is XYZ <-> UV correspondence + triangular topology, so grabbing them from the Face Geometry metadata file is a good starting point for now (you can tweak the mapping / topology later if needed)

What I meant by this is that there's a geometry_pipeline_metadata_from_landmarks.pbtxt file which enlists 468 canonical face mesh landmarks; each landmarks is described by 5 float values: 3D position (XYZ) and texture coordinate (UV). These vertex_buffer values have the 5 * 468 float values. First, you'd need to parse those to get the UV values (i.e. every 4th and 5th float values out of 5 consequent ones). Then, you get the XYZ coordinates from the MediaPipe FaceMesh solution - and now for each 3D position XYZ) you have a texture coordinate (UV)

Then, you need to parse these index_buffer values - the first 3 values describe the first triangular mesh face, the second 3 values describe the second triangular mesh face and so on

@apple2373
Copy link

Hi, I was able to implement this. https://github.com/apple2373/mediapipe-facemesh

@wizVR-zhangjun
Copy link

@mufaawan Hi teacher, I have trouble using CV ::getAffineTransform and CV ::warpAffine, can you tell me your core idea

@aishwarya123mathpati
Copy link

Hi Developers!
I want to write or store the mediapipe 468 face landmarks to a FBX file format. I have tried with multiple ways but not able to get solution. I am able to generate obj file, in obj file I am having only face landmarks are there.
I tried with fbx , pyfbx , python fbx sdk but none of the library has helped me to solve this issue.

Thanks in advance!

@mufaawan
Copy link
Author

Hello,
if you still need help you can reach me via email (mufaawan@gmail.com) . We can schedule a zoom call to help get your things done.

@mufaawan
Copy link
Author

Hi Developers! I want to write or store the mediapipe 468 face landmarks to a FBX file format. I have tried with multiple ways but not able to get solution. I am able to generate obj file, in obj file I am having only face landmarks are there. I tried with fbx , pyfbx , python fbx sdk but none of the library has helped me to solve this issue.

Thanks in advance!

Hello,
if you still need help you can reach me via email (mufaawan@gmail.com) . We can schedule a zoom call to help get your things done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy:face mesh Issues related to Face Mesh type:feature Enhancement in the New Functionality or Request for a New Solution
Projects
None yet
Development

No branches or pull requests

10 participants