Given a 3D scene and a 2D image of part of that scene, is it possible to find the position of the camera used to make the image?
I'm going to assume from your question that you have four points in the 2-D space whose locations you know in the 3-D space. (If your real problem is identifying those point, I haven't the foggiest idea where to begin.)
Your question is therefore, where can the camera be to have produced this mapping from model to image?
The camera is performing an affine transformation of the form M x + T = y
, where x
is a vector in 3-space representing the point in the model and y
is the 2-space vector representing the point in the image. Given four values for x
and y
, it's a straightforward matrix-arithmetic problem to solve for M and T (probably best to get MATLAB to help you here.)
Now, how do you translate M and T to position, location, and focal length of the camera? There it gets a little hairy but this page should help you (just remember, you are doing everything backwards).
If you take a random sampling of camera parameters, rendering the scene with each set of parameters, you can take the best matches as a starting point. You can then perform a local optimization of the camera parameters to find those parameters which reproduce the 2D image the closest. It isn't fast, but theoretically you could come up with very good guesses given enough time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With