instant-ngp icon indicating copy to clipboard operation
instant-ngp copied to clipboard

How to find transformation matrix between camera coordinate system (input via transforms.json file) and bounding box coordinate system?

Open abhikaushik1 opened this issue 2 years ago • 7 comments

abhikaushik1 avatar Apr 26 '23 13:04 abhikaushik1

I am also interested in backprojecting from 2D to 3D... I know in colmap that the reverse operation is [R.T, R.T.dot(t)] (source:https://colmap.github.io/format.html?highlight=inverse), however I don't think it's still applicable after swapping axes, doing the normalization and etc done in colmap2nerf.py...

If you did find a solution to this, I'm very interested in the answer

Student204161 avatar May 29 '23 19:05 Student204161

I used code to get an obj file that I wanted to reproject a three-dimensional point cloud onto a two-dimensional image using transforms.json

num-doc avatar Aug 14 '24 03:08 num-doc

Hi,

sorry for not updating this issue after I found a solution quite a while ago… what I found being the biggest issue was figuring out the coordinate systems that the obj was in and the coordinate system transforms.json are described, because most likely for reprojection into 2d images, we need to transform either of them. Firstly I reproduced the point cloud using equations from a book and the transformation for this was different one required than reprojecting the mesh using pyrender, so it’s best to visually debug it, I’d recommend for anyone who tries this.

Student204161 avatar Aug 14 '24 08:08 Student204161

That's really good news, but I used the traditional world coordinates - camera coordinates - pixel coordinates, and the result was terrible. Can you explain in detail how that was converted.

Thank you very much!

num-doc avatar Aug 14 '24 09:08 num-doc

It’s some time ago I worked with this problem so I can’t remember in top of my head by I’ll post when I get home on my desktop later today

Student204161 avatar Aug 14 '24 09:08 Student204161

For reprojection I can see I flipped the sign in the focal length in x-direction in camera matrix. Then inverted the transformation matrices and used cv2.rodrigues to get the rotation vector as input to cv2.projectPoints - This will give you a reprojected point cloud if you input the vertices. If you use something for projecting the mesh that uses same coordinate system as openCV, then it should be the same with the mesh.

I think the result is dependent on how well colmap/SLAM estimates your projection matrices so i would recommend visualizing them for debugging in the interactive viewer in instant-ngp first if you run on your own dataset and haven't already.

Student204161 avatar Aug 15 '24 11:08 Student204161

image I tried the transformation according to your method, but there is still a problem

num-doc avatar Aug 16 '24 02:08 num-doc