upsp.cam_cal_utils.photogrammetry

get_occlusions_targets(rmat, tvec, tgts, vis_checker)[source]

Wrapper around visibility methods

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (np.ndarray (3, 1), float) – Translation vector from camera to object

  • tgts (list of dict) – Each target is a dict with (at a minimum) a ‘tvec’, and ‘norm’ attribute. The ‘tvec’ attribute gives the target’s location and the ‘norm’ attribute gives the target’s normal vector

  • vis_checker (VisibilityChecker) – Visibility checker object with the relevant BVH and oblique viewing angle

Returns

occlusions – The first element of each tuple is a boolean. This boolean denotes if there was an occlusion or not. The second element of each tuple is the point that the occlusion happens. If there was no occlusion (the boolean from the first element would be False), the value [0, 0, 0] is returned.

Return type

list of tuple

get_visible_targets(rmat, tvec, tgts, vis_checker)[source]

Wrapper around is_visible()

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (np.ndarray (3, 1), float) – Translation vector from camera to object

  • tgts (list of dict) – Each target is a dict with (at a minimum) a ‘tvec’, and ‘norm’ attribute. The ‘tvec’ attribute gives the target’s location and the ‘norm’ attribute gives the target’s normal vector. Both are np.ndarrays (n, 3) of floats. Returned targets will have the same additionalk attributes as the input targets

  • vis_checker (VisibilityChecker) – Visibility checker object with the relevant BVH and oblique viewing angle

Returns

List of visible targets. Returned targets are references to input targets. Returned list is the subset of the input targets that are visible to the camera

Return type

list of dict

invTransform(R, t)[source]

Returns the inverse transformation of the given R and t

Parameters
Returns

isRotationMatrix(R)[source]

Checks if a matrix is a valid rotation matrix

Parameters

R (numpy.ndarray, shape (3, 3), float) – Rotation Matrix

Returns

True if R is a valid rotation matrix, and False if it is not

Return type

bool

isRotationMatrixRightHanded(R)[source]

Returns True if matrix is right handed, and False it is not

Parameters

R (np.ndarray (3, 3), float) – Rotation Matrix

Returns

True if R is a right handed rotation matrix, and False if it is not

Return type

boolean

project_3d_point(rmat, tvec, cameraMatrix, distCoeffs, obj_pts, ret_jac=False, ret_full_jac=False)[source]

Projects targets into an image.

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (numpy.ndarray, shape (3, 1), float) – Translation vector from camera to object

  • cameraMatrix (numpy.ndarray, shape (3, 3), float) – The (openCV formatted) camera matrix for the camera

  • distCoeffs (np.ndarray (1, 5), float) – The (openCV formatted) distortion coefficients for the camera

  • obj_pts (numpy.ndarray, shape (n, 3), float) – The 3D position of the points on the object (relative to the object frame) to be projected

  • ret_jac (bool, optional, default False) – If True, returns the Jacobian. If False only the projection is returned

  • ret_full_jac (bool, optional, default False) – If True, returns full 15 term Jacobian (delta rvec, delta tvec, delta focal length, delta principal point, delta distortion). If False, returns the 6 term Jacobian (delta rvec, delta tvec)

Returns

  • projs, numpy.ndarray, shape (n, 2), float – Projected pixel positions

  • jacs (numpy.ndarray, shape (n, 2, 6) or (n, 2, 15), float) – Jacobian of the projected pixel location. Only returned if ret_jac is True. jacs[i] is associated with projs[i]. jacs[:, 0, :] is the x axis, jacs[:, 1, :] is the y axis. Axis 2 of jacs is the partial derivative related to the inputs (delta rvec, delta tvec, etc).

project_targets(rmat, tvec, cameraMatrix, distCoeffs, tgts, dims=None)[source]

Projects targets into an image.

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (np.ndarray (3, 1), float) – Translation vector from camera to object

  • cameraMatrix (numpy.ndarray, shape (3, 3), float) – The (openCV formatted) camera matrix for the camera

  • distCoeffs (numpy.ndarray, shape (5, 1) or (5,), float) – The (openCV formatted) distortion coefficients for the camera

  • tgts (list of dict) – Each target is a dict with (at a minimum) ‘tvec’ and ‘target_type’ attributes. The ‘tvec’ attribute gives the target’s location and ‘target_type’ is a string denoting the type of target (most commonly ‘dot’ or ‘kulite’)

  • dims (array_like, length 2, optional) – Dimensions of image in (width, height). If not None, any targets that get projected outside the image (x < 0, x > dims[1], y < 0, y > dims[0]) will be None rather than having a value

Returns

List of target projections. Each target projections is a dict with the attributes ‘target_type’ and ‘proj’. If dims is not None, some target projections may be None instead

Return type

list of dict

reprojection_error(rmat, tvec, cameraMatrix, distCoeffs, tgts, img_targets)[source]

Calculates RMS reprojection error

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (numpy.ndarray, shape (3, 1), float) – Translation vector from camera to object

  • cameraMatrix (numpy.ndarray, shape (3, 3), float) – The (openCV formatted) camera matrix for the camera

  • distCoeffs (numpy.ndarray, shape (1, 5), float) – The (openCV formatted) distortion coefficients for the camera

  • tgts (list of dict) – Each target is a dict with (at a minimum) ‘tvec’, ‘norm’, and ‘target_type’ attributes. The ‘tvec’ attribute gives the target’s location and the ‘norm’ attribute gives the target’s normal vector. ‘target_type’ is a string denoting the type of target (most commonly ‘dot’ or ‘kulite’)

  • img_targets (list of dict) – Each img_target is a dict with (at a minimum) a ‘center’ attribute. The ‘center’ attribute gives the pixel position of the target’s center in the image. img_targets[i] is associated with tgts[i]

Returns

rms, max_dist – RMS distance and maximum distance

Return type

float

rot(angle, axis)[source]

Rotation matrix for angle-axis transformation

An identity matrix is rotated about the given axis by the given angle (in degrees)

Parameters
  • angle (float) – angle of rotation (in degrees) about the given axis

  • axis ({'x', 'y', 'z'}) – axis to rotate about

Returns

Rotation matrix of an identity matrix rotated about the given axis by the given amount

Return type

numpy.ndarray, shape (3, 3), float

rotationMatrixToTunnelAngles(R)[source]

Converts rotation matrix to tunnel angles

Parameters

R (numpy.ndarray, shape (3, 3), float) – Rotation Matrix

Returns

Array of tunnel angle (alpha, beta, phi)

Return type

np.ndarray (3, 1), float

See also

isRotationMatrix

Checks if a matrix is a valid rotation matrix

transform_3d_point(rmat, tvec, obj_pts)[source]

Transform 3D points from the object frame to the camera frame.

rmat and tvec are the transformation from the camera to the object’s frame. obj_pts[i] is the position of point i relative to the object frame. The function returns the points relative to the camera.

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (np.ndarray (3, 1), float) – Translation vector from camera to object

  • obj_pts (np.ndarray (n, 3), float) – List-like of 3D positions. The positions are relative to the object frame defined by rmat and tvec

Returns

Array of transformed points. return[i] is the transformed obj_pts[i]

Return type

np.ndarray (n, 3) of floats

transform_targets(rmat, tvec, tgts)[source]

Transform the targets by the given transformation values.

rmat and tvec are the transformation from the camera to the object’s frame. tgts[i]['tvec'] is the position of target i relative to the object frame. tgts[i]['norm'] is the normal of target i relative to the object frame. The function returns the targets such that ‘tvec’ and ‘norm’ are relative to the camera.

Parameters
  • rmat (numpy.ndarray, shape (3, 3), float) – Rotation matrix from camera to object

  • tvec (numpy.ndarray, shape (3, 1), float) – Translation vector from camera to object

  • tgts (list of dict) – Each target is a dict with (at a minimum) a ‘tvec’, and ‘norm’ attribute. ‘tvec’ is the position of the target relative to the object frame. ‘norm’ is he normal of the target relative to the object frame. All other attributes will be copied to the transformed targets.

Returns

tgts_tf – List of targets. Each target has the attributes of the input targets, except the transformed targets are transformed to be relative to the camera

Return type

list of dict