-
-
Notifications
You must be signed in to change notification settings - Fork 598
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
Projecting the mesh to 2d correctly in Python #140
Comments
Thank you very much, and thanks for the feedback! I'm actually currently working on improving the python bindings and pip package, but it'll be at least a few weeks. In any case what you're trying to do is in principle trivial and I did it in the past in python - as you mentioned there's probably just a small mistake somewhere, let's find it. You're correct that the 3D mesh is always centered, that's by design - it lives in the 3D model space. It should end up at the correct location by applying the modelview, projection and viewport transform (in that order). Exactly what you did in principle. If you could check the following:
What you could maybe most easily do is construct a 4x4 viewport matrix like I do here for the Matlab bindings: https://github.com/patrikhuber/eos/blob/master/matlab/include/mexplus_eos_types.hpp#L496-L503 Let me know whether that works, it really should! |
Here is a small C++ application that builds an explicit : https://github.com/headupinclouds/hunter_eos_example/blob/master/eos-dlib-test.cpp#L60-L66
Adding an explicit viewport matrix (as above) to the python code should help =>
|
Hello, I implemented the viewport matrix as suggested
But the result is still somehow off. Any suggestion? |
@tobyclh Hi! Hmm. I'll try to find some time to have a look over the next days. At this point I still believe it could be some user error at some point in your code, but I'm not sure. |
Okay I figured it out. so it was the fact that the 68 marker uses [x, y] but opencv draws in [y, x]. |
@tobyclh: Haha! Oh yea... I'm glad that you figured it out! Yep, OpenCV specifies most things in (y, x), because their images are "matrices" (cv::Mat) and the access there is specified as (row, column) - row is of course y in an image, and column is x. Whereas everywhere else, we normally use the [x, y] syntax. @kylemcdonald Were you able to solve your problem too? |
Never saw this before |
@tobyclh I follow your idea,but why I couldn't get the fitting mesh fit on the face correctly?Any suggestions to my problem?Thank youfile:///C:/Users/kary/Downloads/3d_mesh_fitting.html |
I've just written a python script that projects the 3D mesh points to 2D and it works without a problem. So I don't think there are any issues in the library with regards to this. I've used the Anybody feel free to re-open if there are any questions left. |
@tobyclh hi~ I wonder how i can get the projection matrix and the modelview, your code could get the viewport, but we know we need modelview, viewport, projection matrix, then we can finnaly get the projetction results. |
@patrikhuber can you share the code in python? |
@qinhaifangpku @ivomarvan I don't have the code for that to hand or potentially I didn't save it back then. I might some day find the time to add it to the python There is one open issue (#219) where there might be an issue with the projection in Python in Release builds or the PyPi build but in Debug configuration it worked fine for a colleague of mine. |
Why do you need to recenter it to the center of the image? I get everything you said, except that part |
For future ppl having problems with this: |
How would one modify the code from gigadeplex such that the texture is rendered as well? In other words, rendering the entire 3D model over the 2D image. |
First, thanks so much for this great library! :)
I'm trying to project the mesh returned by eos back onto the original image. I can see there are examples of doing this in C++ but I'm working on Python for now. What I've noticed is that the mesh always seems to be centered on the image.
https://gist.github.com/kylemcdonald/fadf8e8778d14a918bd8275d2807e283
My suspicion is that either:
I looked into the eos source to try and find an example, and checked the glm::project function, but couldn't find any clear indicators of what I'm doing wrong. If you have any advice I would really appreciate it. Thanks!
The text was updated successfully, but these errors were encountered: