sdynpy.signal_processing.sdynpy_camera.camera_matrix_from_image

camera_matrix_from_image(image_points, spatial_points)[source]

Computes camera matrices from at least six points

This function computes camera matrices K (intrinic parameters) and R|T (extrinsic parameters) from a set of points defined on the image (u,v) and in 3D space (x,y,z). It sets up a system of homogeneous linear equations for the camera parameters and solves for them using the singular value decomposition to extract the left singular vector corresponding to the smallest singular value. This vector is the closest vector to the null space of the system of equations.

Parameters
  • image_points (ndarray) – A n x 2 array where n is the number of points being correlated. The first column is the horizontal pixel index from the left side of the image, and the second column is the vertical pixel index from the top of the image. Pixel locations can be extracted from software such as Paint or GIMP, or if the image is plotted using matplotlib.pyplot.imshow.

  • spatial_points (ndarray) – A n x 3 array where n is the number of points being correlated. The rows of spatial_points correpond to the rows of image_points: for a point spatial_points[i,:] in 3D space, its position in the image in pixels is image_points[i,:].

Returns

  • K (ndarray) – A 3 x 3 upper triangular array consisting of the camera intrinisc parameters.

  • RT (ndarray) – A 3 x 4 array where the first three columns are an orthogonal matrix denoting a rotation matrix, and the last column is a translation.

Notes

The return matrix K is of the form:

    [f_u  s  u_0]
K = [ 0  f_v v_0]
    [ 0   0   1 ]

And the matrix RT is of the form:

             [r_xx r_xy r_xz | t_x]
RT = [R|T] = [r_yx r_yy r_yz | t_y]
             [r_zx r_zy r_zz | t_z]

And satisfy the equation:

c*[u v 1].T = K@RT@[x y z 1].T