sksurgerycalibration.video.video_calibration_metrics module

Video calibration metrics, used in cost functions for optimisation, and as measures of error generally.

sksurgerycalibration.video.video_calibration_metrics.compute_mono_2d_err(object_points, image_points, rvecs, tvecs, camera_matrix, distortion, return_residuals=False)[source]

Function to compute mono reprojection (SSE) error, or residuals over multiple views of a mono camera.

Parameters:
  • object_points – Vector of Vector of 1x3 of type float32
  • image_points – Vector of Vector of 1x2 of type float32
  • rvecs – Vector of [3x1] ndarray, Rodrigues rotations for each camera
  • tvecs – Vector of [3x1] ndarray, translations for each camera
  • camera_matrix – [3x3] ndarray
  • distortion – [1x5] ndarray
  • return_residuals – If True returns a big array of residuals for LM.
Returns:

SSE re-reprojection error, number_samples OR residuals

sksurgerycalibration.video.video_calibration_metrics.compute_mono_2d_err_handeye(model_points: List[T], image_points: List[T], camera_matrix: numpy.ndarray, camera_distortion: numpy.ndarray, hand_tracking_array: List[T], model_tracking_array: List[T], handeye_matrix: numpy.ndarray, pattern2marker_matrix: numpy.ndarray)[source]

Function to compute mono reprojection error (SSE), mapping from the calibration pattern coordinate system to the camera coordinate system, via tracking matrices and hand-eye calibration.

Parameters:
  • model_points (List) – Vector of Vector of 1x3 float32
  • image_points (List) – Vector of Vector of 1x2 float32
  • camera_matrix (np.ndarray) – Camera intrinsic matrix
  • camera_distortion (np.ndarray) – Camera distortion coefficients
  • hand_tracking_array

Vector of 4x4 tracking matrices for camera (hand) :type hand_tracking_array: List :param model_tracking_array: Vector of 4x4 tracking matrices for calibration model :type model_tracking_array: List :param handeye_matrix: Handeye matrix :type handeye_matrix: np.ndarray :param pattern2marker_matrix: Pattern to marker matrix :type pattern2marker_matrix: np.ndarray :return: SSE reprojection error, number of samples :rtype: float, float

sksurgerycalibration.video.video_calibration_metrics.compute_mono_3d_err(ids, object_points, image_points, rvecs, tvecs, camera_matrix, distortion)[source]

Function to compute mono reconstruction error (SSE) over multiple views.

Here, to triangulate, we take the i^th camera as left camera, and the i+1^th camera as the right camera, compute l2r, and triangulate.

Note: This may fail if the difference between two successive views is too large, and there are not enough common points.

Parameters:
  • ids – Vector of ndarray of integer point ids
  • object_points – Vector of Vector of 1x3 of type float32
  • image_points – Vector of Vector of 1x2 of type float32
  • rvecs – Vector of [3x1] ndarray, Rodrigues rotations for each camera
  • tvecs – Vector of [3x1] ndarray, translations for each camera
  • camera_matrix – [3x3] ndarray
  • distortion – [1x5] ndarray
Returns:

SSE re-reprojection error, number_samples

sksurgerycalibration.video.video_calibration_metrics.compute_mono_3d_err_handeye(ids: List[T], model_points: List[T], image_points: List[T], camera_matrix: numpy.ndarray, camera_distortion: numpy.ndarray, hand_tracking_array: List[T], model_tracking_array: List[T], handeye_matrix: numpy.ndarray, pattern2marker_matrix: numpy.ndarray)[source]

Function to compute mono reconstruction error (SSE). Calculates new rvec/tvec values for pattern_to_camera based on handeye calibration and then calls compute_mono_3d_err().

Parameters:
  • ids (List) – Vector of ndarray of integer point ids
  • model_points (List) – Vector of Vector of 1x3 float32
  • image_points (List) – Vector of Vector of 1x2 float32
  • camera_matrix (np.ndarray) – Camera intrinsic matrix
  • camera_distortion (np.ndarray) – Camera distortion coefficients
  • hand_tracking_array

Vector of 4x4 tracking matrices for camera (hand) :type hand_tracking_array: List :param model_tracking_array: Vector of 4x4 tracking matrices for calibration model :type model_tracking_array: List :param handeye_matrix: Handeye matrix :type handeye_matrix: np.ndarray :param pattern2marker_matrix: Pattern to marker matrix :type pattern2marker_matrix: np.ndarray :return: SSE reprojection error, number of samples :rtype: float, float

sksurgerycalibration.video.video_calibration_metrics.compute_stereo_2d_err(l2r_rmat, l2r_tvec, left_object_points, left_image_points, left_camera_matrix, left_distortion, right_object_points, right_image_points, right_camera_matrix, right_distortion, left_rvecs, left_tvecs, return_residuals=False)[source]

Function to compute stereo re-projection error (SSE), or residuals, over multiple views.

Parameters:
  • l2r_rmat – [3x3] ndarray, rotation for l2r transform
  • l2r_tvec – [3x1] ndarray, translation for l2r transform
  • left_object_points – Vector of Vector of 1x3 of type float32
  • left_image_points – Vector of Vector of 1x2 of type float32
  • left_camera_matrix – [3x3] ndarray
  • left_distortion – [1x5] ndarray
  • right_object_points – Vector of Vector of 1x3 of type float32
  • right_image_points – Vector of Vector of 1x2 of type float32
  • right_camera_matrix – [3x3] ndarray
  • right_distortion – [1x5] ndarray
  • left_rvecs – Vector of [3x1] ndarray, Rodrigues rotations, left camera
  • left_tvecs – Vector of [3x1] ndarray, translations, left camera
  • return_residuals – if True returns vector of residuals for LM,

otherwise, returns SSE. :return: SSE, number_samples OR residuals

sksurgerycalibration.video.video_calibration_metrics.compute_stereo_2d_err_handeye(common_object_points: List[T], left_image_points: List[T], left_camera_matrix: numpy.ndarray, left_distortion: numpy.ndarray, right_image_points: List[T], right_camera_matrix: numpy.ndarray, right_distortion: numpy.ndarray, hand_tracking_array: List[T], model_tracking_array: List[T], left_handeye_matrix: numpy.ndarray, left_pattern2marker_matrix: numpy.ndarray, right_handeye_matrix: numpy.ndarray, right_pattern2marker_matrix: numpy.ndarray)[source]

Function to compute stereo reprojection error (SSE), taking into account handeye calibration.

Parameters:
  • common_object_points (List) – Vector of Vector of 1x3 float32
  • left_image_points (List) – Vector of Vector of 1x2 float32
  • left_camera_matrix (np.ndarray) – Left camera matrix
  • left_distortion (np.ndarray) – Left camera distortion coefficients
  • right_image_points (List) – Vector of Vector of 1x2 float32
  • right_camera_matrix (np.ndarray) – Right camera matrix
  • right_distortion (np.ndarray) – Right camera distortion coefficients
  • hand_tracking_array

Vector of 4x4 tracking matrices for camera (hand) :type hand_tracking_array: List :param model_tracking_array: Vector of 4x4 tracking matrices for calibration model :type model_tracking_array: List :param left_handeye_matrix: Left handeye transform matrix :type left_handeye_matrix: np.ndarray :param left_pattern2marker_matrix: Left pattern to marker transform matrix :type left_pattern2marker_matrix: np.ndarray :param right_handeye_matrix: Right handeye transform matrix :type right_handeye_matrix: np.ndarray :param right_pattern2marker_matrix: Right pattern to marker transform matrix :type right_pattern2marker_matrix: np.ndarray :return: SSE reprojection error, number of samples :rtype: float, float

sksurgerycalibration.video.video_calibration_metrics.compute_stereo_3d_err_handeye(l2r_rmat: numpy.ndarray, l2r_tvec: numpy.ndarray, common_object_points: List[T], common_left_image_points: List[T], left_camera_matrix: numpy.ndarray, left_distortion: numpy.ndarray, common_right_image_points: List[T], right_camera_matrix: numpy.ndarray, right_distortion: numpy.ndarray, hand_tracking_array: List[T], model_tracking_array: List[T], left_handeye_matrix: numpy.ndarray, left_pattern2marker_matrix: numpy.ndarray)[source]

Function to compute stereo reconstruction error (SSE), taking into account handeye calibration.

Parameters:
  • l2r_rmat (np.ndarray) – Rotation for l2r transform
  • l2r_tvec (np.ndarray) – Translation for l2r transform
  • common_object_points (List) – Vector of Vector of 1x3 float32
  • common_left_image_points (List) – Vector of Vector of 1x2 float32
  • left_camera_matrix (np.ndarray) – Left camera matrix
  • left_distortion (np.ndarray) – Left camera distortion coefficients
  • common_right_image_points (List) – Vector of Vector of 1x2 float32
  • right_camera_matrix (np.ndarray) – Right camera matrix
  • right_distortion (np.ndarray) – Right camera distortion coefficients
  • hand_tracking_array

Vector of 4x4 tracking matrices for camera (hand) :type hand_tracking_array: List :param model_tracking_array: Vector of 4x4 tracking matrices for calibration model :type model_tracking_array: List :param left_handeye_matrix: Left handeye transform matrix :type left_handeye_matrix: np.ndarray :param left_pattern2marker_matrix: Left pattern to marker transform matrix :type left_pattern2marker_matrix: np.ndarray :return: SSE reconstruction error, number of samples :rtype: float, float

sksurgerycalibration.video.video_calibration_metrics.compute_stereo_3d_error(l2r_rmat, l2r_tvec, common_object_points, common_left_image_points, left_camera_matrix, left_distortion, common_right_image_points, right_camera_matrix, right_distortion, left_rvecs, left_tvecs, return_residuals=False)[source]

Function to compute stereo reconstruction error (SSE), or residuals over multiple views.

Parameters:
  • l2r_rmat – [3x3] ndarray, rotation for l2r transform
  • l2r_tvec – [3x1] ndarray, translation for l2r transform
  • common_object_points – Vector of Vector of 1x3 of type float32
  • common_left_image_points – Vector of Vector of 1x2 of type float32
  • left_camera_matrix – [3x3] ndarray
  • left_distortion – [1x5] ndarray
  • common_right_image_points – Vector of Vector of 1x2 of type float32
  • right_camera_matrix – [3x3] ndarray
  • right_distortion – [1x5] ndarray
  • left_rvecs – Vector of [3x1] ndarray, Rodrigues rotations, left camera
  • left_tvecs – Vector of [3x1] ndarray, translations, left camera
  • return_residuals – if True returns vector of residuals for LM,

otherwise, returns SSE. :return: SSE re-reprojection error, number_samples