pythonopencvcameraopencv-solvepnp

Find the translation between two origins based on the camera positions


I have determined the camera position based on two origins in the field of view of the camera. Let's say origin 1 is located at (140,200) and origin 2 is located at (70,180).

Following are the camera positions with respect to origin 1 and origin 2.

X1,Y1,Z1,X2,Y2,Z2 = 0.8361721744324895,-0.5131803297263005,1.3708440418732257,0.09985411281689659,0.3329507542440152,1.342809058827907

whereas the (X1, Y1, Z1) are the camera position with respect to the origin 1 while (X2, Y2, Z2) is the camera position with respect to the origin 2.

I have used the following code to compute the translation between both origins.

dist = math.sqrt((X1-X2) ** 2 + (Y1-Y2) **2 + (Z1-Z2)**2)

However, the value is a scalar and not a vector (XYZ) value of the translation between the origins based on their respective camera positions. How can I get the XYZ distances?


Solution

  • Consider a third origin, apart from your two origins.

    With respect to this third origin, let the position vectors of the camera, first origin, and second origin be r_c, r_1, and r_2, respectively.

    With respect to the first origin, let the position vector of the camera be r_c_1

    With respect to the second origin, let the position vector of the camera be r_c_2

    Using -- as the symbol for vector subtraction, we have:

    r_c_1 = r_c -- r_1

    r_c_2 = r_c -- r_2

    From the above two equations, subtracting one equation from the other, we get:

    r_c_2 -- r_c_1 = (r_c -- r_2) -- (r_c -- r_1)

    which, on simplifying, gives:

    r_c_2 -- r_c_1 = r_1 -- r_2

    In the above equation, the RHS is what you want (the translation vector between the two origins). The LHS is the vector-subtraction between the camera positions under the two origins.

    So, if the vectors are represented in 3-tuple notation, let r_c_1 and r_c_2 be (x1, y1, z1), and (x2, y2, z2), respectively. Then, from the above equation, the require "origin-translation-vector" will (x2-x1, y2-y1, z2-z1)