patrikhuber / eos

A lightweight 3D Morphable Face Model library in modern C++
Apache License 2.0
1.92k stars 598 forks source link

Question on loading my own PCA model #14

Closed Xingyu-Lin closed 8 years ago

Xingyu-Lin commented 9 years ago

Hi, thank you for your code, it has been very helpful to me. But when I try to load my own pca model, I wonder how is your triangleList arranged?

patrikhuber commented 9 years ago

Hi Xingyu, Thanks, I'm glad it's helpful!

The triangle_list is a list of triangles that make up the mesh of the model. A mesh consists of vertices - but you also need to know how they're arranged to make up the triangles. triangle_list is just an array with each entry having 3 int's, and these are the vertex indices of one triangle.

Let's say your model has 20 vertices - the first few entries of triangle_list could look like:

{0, 1, 2} // the first triangle consists of vertices 0, 1 and 2
{1, 5, 7} // second triangle consists of vertices 1, 5 and 7
{1, 2, 9} // etc...
...

I hope that answers your question!

Xingyu-Lin commented 9 years ago

Yes, that solve my confuse. One little question regardless of this project: how to get a triangle list when I have the point clouds? OpenCV seems to support only 2D delaunay algorithm.

patrikhuber commented 9 years ago

Cool. In principle, you only need the triangle_list when you call functions like draw_sample, that will return a Mesh. So parts of eos should run without it.

I don't have much experience with mesh triangulation, but it's a standard problem in computer graphics. There must be many libraries out there that you can just quickly use to generate a triangle list. Even Blender can most likely do it, and that might actually be the quickest way!

Xingyu-Lin commented 9 years ago

Yeah, I solved that one through matlab interfere. Now I have another problem:( It seems that when you generate the mesh, you have considered the situation when there is no texture coordinate(I don't know what that is, maybe something for visualise in .obj file?), MorphableModel.hpp,line 173. But when you try to extract texture, you miss the case and in render_affine.pp line 76, in the reference to mesh.texcorrds[i], it will go wrong. Is there an easy way to fix this?

Really curious about what does the texture coordinates do in the morphable model

patrikhuber commented 9 years ago

I see your problem. First of all, think about what you are trying to do: You are trying to extract the texture (i.e. map the image-texture onto the mesh), and for that, I'm sure you understand that your model needs to have texture coordinates. If you're not familiar with texture (or UV) coordinates, it's the standard approach in graphics/games to texture a mesh. Have a quick read through that: UV mapping

So the fix is the following: Do you need/want to extract the original texture?

Let me know if that helps, and if not, I'm sure we can work out a solution :-)

Xingyu-Lin commented 8 years ago

I took a few days on this issue and it seems like once I fit the image into my 3DMM, the texture on the image can be put into correspondence with the vertices naturally. The isomap does not seem necessary?

patrikhuber commented 8 years ago

Yes, after the fitting, you got this correspondence. But the isomap is for storing the texture. How would you store this information instead?

patrikhuber commented 8 years ago

Going to close this as the initial problem seems resolved. Feel free to re-open or create a new issue if you have other issues.