question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting a proper camera transform

See original GitHub issue

Hello everyone, and first of all thank you @mikedh for the insane work put into this library. I am trying to use this in a few projects, especially for raycasting and some quick renders.

I have been trying for a while to set a custom camera transform, but I only managed to get myself a headache since there seems to be some weird convention going on with transform matrices. My questions are:

  1. How can I use the trimesh.scene.set_camera method to define a camera viewpoint starting from a regular 4x4 matrix containing camera pose and 3D position with respect to the world reference frame?
  2. If there is a differerent convention in defining such reference frames, where can I find more info? Is there anything in the trimesh documentation?

Thank you in advance F

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
Hippogriffcommented, Jun 18, 2021

@fbottarel I found the solution. The camera_transform is world to camera transformation matrix (or reverse, I can’t tell to be honest, try inverse if it doesn’t work). But the weird thing is that you need to rotate your mesh with the following transformation before feeding into the rendering pipeline:

    extra = np.eye(4)
    extra[0, 0] = 0
    extra[0, 1] = 1
    extra[1, 0] = -1
    extra[1, 1] = 0

So if you got pyrender rendering working, then simply pre multily the camera_pose matrix and that’s your camera_transform that trimesh expects.

0reactions
barvin04commented, Jul 11, 2022

Hello everyone, and first of all thank you @mikedh for the insane work put into this library. I am trying to use this in a few projects, especially for raycasting and some quick renders.

I have been trying for a while to set a custom camera transform, but I only managed to get myself a headache since there seems to be some weird convention going on with transform matrices. My questions are:

  1. How can I use the trimesh.scene.set_camera method to define a camera viewpoint starting from a regular 4x4 matrix containing camera pose and 3D position with respect to the world reference frame?
  2. If there is a differerent convention in defining such reference frames, where can I find more info? Is there anything in the trimesh documentation?

Thank you in advance F

Yes, there are some conventions to be followed. Different platforms use different coordinate system. (example)

For LineMOD dataset, I found that you need to multiply y and z axis transformations with -1 to correctly render in Trimesh.

r  = np.multiply( r, np.array([[1, 1, 1], [-1, -1, -1], [-1, -1, -1]])) #rotation
t = np.multiply( t , np.array([1, -1, -1])) #translation
Read more comments on GitHub >

github_iconTop Results From Across the Web

Camera Settings guide – The 15 best photography settings
Camera settings in photography are key to take quality images. Learn the best settings, dials, and buttons with this camera settings guide!
Read more >
Transform Your Photos With This Setting In Camera Raw
FOLLOW MEINSTAGRAM: http://www.instagram.com/jessicakobeissiFACEBOOK: https://www.facebook.com/jessicakphotoSNAPCHAT: ...
Read more >
Easy to Understand Guide to Camera Settings for Beginners
Master your camera settings with this easy-to-follow guide for beginners, including pro tips you can use to keep improving your photography in 2022....
Read more >
Tutorial 13 - Camera Space - OGLdev
This function generates the camera transformation matrix that will be used later by the pipeline class. The U,V and N vectors are calculated...
Read more >
Common Camera Settings for Beginners - Photography Life
Camera Setup · Best Camera Shooting Mode · Best Autofocus Mode · Best Metering Mode · Best Lens Aperture · Best Shutter Speed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found