R
R
Roman Volodin2015-02-20 03:04:48
Python
Roman Volodin, 2015-02-20 03:04:48

How to find the position of the camera by three points in space?

412a921c60e647a4a24c6a4e3543f673.png
For some time now, the idea of ​​a script for Blender has been sitting in my head, which would find the position of the camera in space using known points.
Those. we have a photograph, in this case of a chair. It seems to me possible, knowing the position of points in space, knowing the coordinates of the same points in the photograph (as well as the angle of view of the camera), to find the position of the camera. But I don't understand how to approach this problem. Fragments of thoughts like "section of the pyramid", "central projection" and other "stereometry" are spinning in my head.
Prompt in what direction to dig?
The script will be written in the third python, maybe there are some useful packages?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mrrl, 2015-02-20
@Mrl

Not an easy task.
First, you measure the angles between the rays from the photograph, and the distances between the points from the model. Then you denote by x,y,z the unknown distances from the camera to the points (the length of each ray), and write down the equations from the cosine theorem:
x^2-2*a*x*y+y^2=P^2
x^2- 2*b*x*z+z^2=Q^2
y^2-2*c*y*z+z^2=R^2
Here a,b,c are the cosines of the angles between the rays, and P,Q ,R - distances.
The next step is to solve this system. Theoretically, it reduces to an 8th degree equation in one variable z. MAPLE was able to find this polynomial, it takes up a little more screen space. I don't know if this is a good option - maybe yes. You can try to solve the system numerically - sort through different starting values ​​x, y, z and look for the root using Newton's method. But keep in mind that the system is bad - it may well have 4 close roots with positive x, y, z. Or they may not be found - then there will be local minima. It is possible to enumerate the distance x in small increments. For each x, find two options y, two options z, substitute them into the third equation, and start looking for a solution from the best three - you can use Newton's method, but you can also divide the segment in half.
After x,y,z are found, find the position of the center of the camera - as the point of intersection of the three spheres. And then you need to find the right orientation. It's pretty nasty, but shouldn't be very difficult (compared to all the previous steps).

U
Urrus, 2015-02-21
@Urrus

This is a Perspective-n-Point (PnP) task - and it's not as easy as it seems, and is solved in many different ways (like ePnP: cvlabwww.epfl.ch/~lepetit/papers/lepetit_ijcv08.pdf , using RANSAC, etc. .e). In general, there is a lot of mathematics there, so it's better to find a ready-made library that can do such things. I myself used only methods from OpenCV (such as solvePnP (...), solvePnPRansac (...)), it is for python, but it seems to be rather fat to drag it just for the sake of the plugin.

A
Andrey Larin, 2015-02-23
@engine9

Maybe I will not answer correctly, but tracking with video using standard methods is able to restore the distance and path of the camera in space. But the program needs some hints, ranging from points to the direction of the "top" of the scene.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question