sksurgerycalibration.video.video_calibration_wrapper module

Video Calibration functions, that wrap OpenCV functions mainly.

sksurgerycalibration.video.video_calibration_wrapper.mono_handeye_calibration(object_points: List[T], image_points: List[T], camera_matrix: numpy.ndarray, camera_distortion: numpy.ndarray, device_tracking_array: List[T], pattern_tracking_array: List[T], rvecs: List[numpy.ndarray], tvecs: List[numpy.ndarray], override_pattern2marker: numpy.ndarray = None, use_opencv: bool = True, do_bundle_adjust: bool = False)[source]

Wrapper around handeye calibration functions and reprojection / reconstruction error metrics.

Parameters:
  • object_points (List) – Vector of Vectors of 1x3 object points, float32
  • image_points (List) – Vector of Vectors of 1x2 object points, float32
  • ids (List) – Vector of ndarrays containing integer point ids.
  • camera_matrix (np.ndarray) – Camera intrinsic matrix
  • camera_distortion (np.ndarray) – Camera distortion coefficients
  • device_tracking_array (List) – Tracking data for camera (hand)
  • pattern_tracking_array (List) – Tracking data for calibration target
  • rvecs (List[np.ndarray]) – Vector of 3x1 ndarray, Rodrigues rotations for each camera
  • tvecs (List[np.ndarray]) – Vector of [3x1] ndarray, translations for each camera
  • override_pattern2marker – If provided a 4x4 pattern2marker that

is taken as constant. :param use_opencv: If True we use OpenCV based methods, if false, Guofang Xiao’s method. :param do_bundle_adjust: If True we do an additional bundle adjustment at the end. Needs pattern tracking too. :return: Reprojection error, handeye matrix, patter to marker matrix :rtype: float, float, np.ndarray, np.ndarray

sksurgerycalibration.video.video_calibration_wrapper.mono_video_calibration(object_points, image_points, image_size, flags=0)[source]

Calibrates a video camera using Zhang’s 2000 method, as implemented in OpenCV. We wrap it here, so we have a place to add extra validation code, and a space for documentation. The aim is to check everything before we pass it to OpenCV, and raise Exceptions consistently for any error we can detect before we pass it to OpenCV, as OpenCV just dies without throwing exceptions.

  • N = number of images
  • M = number of points for that image
  • rvecs = list of 1x3 Rodrigues rotation parameters
  • tvecs = list of 3x1 translation vectors
  • camera_matrix = [3x3] ndarray containing fx, fy, cx, cy
  • dist_coeffs = [1x5] ndarray, containing distortion coefficients
Parameters:
  • object_points – Vector (N) of Vector (M) of 1x3 points of type float
  • image_points – Vector (N) of Vector (M) of 1x2 points of type float
  • image_size – (x, y) tuple, size in pixels, e.g. (1920, 1080)
  • flags – OpenCV flags to pass to calibrateCamera().
Returns:

RMS projection error, camera_matrix, dist_coeffs, rvecs, tvecs

sksurgerycalibration.video.video_calibration_wrapper.stereo_calibration_extrinsics(common_object_points, common_left_image_points, common_right_image_points, l_rvecs, l_tvecs, override_left_intrinsics, override_left_distortion, override_right_intrinsics, override_right_distortion, override_l2r_rmat, override_l2r_tvec)[source]

Simply re-optimises the extrinsic parameters. :return: error, l_rvecs, l_tvecs

sksurgerycalibration.video.video_calibration_wrapper.stereo_handeye_calibration(l2r_rmat: numpy.ndarray, l2r_tvec: numpy.ndarray, left_ids: List[T], left_object_points: List[T], left_image_points: List[T], right_ids: List[T], right_image_points: List[T], left_camera_matrix: numpy.ndarray, left_camera_distortion: numpy.ndarray, right_camera_matrix: numpy.ndarray, right_camera_distortion: numpy.ndarray, device_tracking_array: List[T], calibration_tracking_array: List[T], left_rvecs: List[numpy.ndarray], left_tvecs: List[numpy.ndarray], override_pattern2marker=None, use_opencv: bool = True, do_bundle_adjust: bool = False)[source]

Wrapper around handeye calibration functions and reprojection / reconstruction error metrics.

Parameters:
  • l2r_rmat (np.ndarray) – [3x3] ndarray, rotation for l2r transform
  • l2r_tvec (np.ndarray) – [3x1] ndarray, translation for l2r transform
  • left_ids (List) – Vector of ndarrays containing integer point ids.
  • left_object_points (List) – Vector of Vector of 1x3 of type float32
  • left_image_points (List) – Vector of Vector of 1x2 of type float32
  • right_ids (List) – Vector of ndarrays containing integer point ids.
  • right_image_points (List) – Vector of Vector of 1x3 of type float32
  • left_camera_matrix (np.ndarray) – Camera intrinsic matrix
  • left_camera_distortion (np.ndarray) – Camera distortion coefficients
  • right_camera_matrix (np.ndarray) – Camera intrinsic matrix
  • right_camera_distortion (np.ndarray) – Camera distortion coefficients
  • device_tracking_array (List) – Tracking data for camera (hand)
  • calibration_tracking_array (List) – Tracking data for calibration target
  • left_rvecs – Vector of 3x1 ndarray, Rodrigues rotations for each

camera :type left_rvecs: List[np.ndarray] :param left_tvecs: Vector of [3x1] ndarray, translations for each camera :type left_tvecs: List[np.ndarray] :param right_rvecs: Vector of 3x1 ndarray, Rodrigues rotations for each camera :type right_rvecs: List[np.ndarray] :param right_tvecs: Vector of [3x1] ndarray, translations for each camera :type right_tvecs: List[np.ndarray] :param override_pattern2marker: If provided a 4x4 pattern2marker that is taken as constant. :param use_opencv: If True we use OpenCV based methods, if false, Guofang Xiao’s method. :param do_bundle_adjust: If True we do an additional bundle adjustment at the end. :return: Reprojection error, reconstruction error, left handeye matrix, left pattern to marker matrix, right handeye, right pattern to marker :rtype: float, float, np.ndarray, np.ndarray, np.ndarray, np.ndarray

sksurgerycalibration.video.video_calibration_wrapper.stereo_video_calibration(left_ids, left_object_points, left_image_points, right_ids, right_object_points, right_image_points, image_size, flags=1, override_left_intrinsics=None, override_left_distortion=None, override_right_intrinsics=None, override_right_distortion=None, override_l2r_rmat=None, override_l2r_tvec=None)[source]

Default stereo calibration, using OpenCV methods.

We wrap it here, so we have a place to add extra validation code, and a space for documentation. The aim is to check everything before we pass it to OpenCV, and raise Exceptions consistently for any error we can detect before we pass it to OpenCV.

Parameters:
  • left_ids – Vector of ndarrays containing integer point ids.
  • left_object_points – Vector of Vectors of 1x3 object points, float32
  • left_image_points – Vector of Vectors of 1x2 object points, float32
  • right_ids – Vector of ndarrays containing integer point ids.
  • right_object_points – Vector of Vectors of 1x3 object points, float32
  • right_image_points – Vector of Vectors of 1x2 object points, float32
  • image_size – (x, y) tuple, size in pixels, e.g. (1920, 1080)
  • flags – OpenCV flags to pass to calibrateCamera().
Returns: