sksurgerycalibration.video.video_calibration_utils module

Various utilities, converters etc., to help video calibration.

sksurgerycalibration.video.video_calibration_utils.array_contains_tracking_data(array_to_check)[source]

Returns True if the array contains some tracking data.

sksurgerycalibration.video.video_calibration_utils.convert_numpy2d_to_opencv(image_points)[source]

Converts numpy array to Vector of 1x2 vectors containing float32.

Parameters:image_points – numpy [Mx2] array.
Returns:vector (length M), of 1x2 vectors of float32.
sksurgerycalibration.video.video_calibration_utils.convert_numpy3d_to_opencv(object_points)[source]

Converts numpy array to Vector of 1x3 vectors containing float32.

Parameters:object_points – numpy [Mx3] array.
Returns:vector (length M), of 1x3 vectors of float32.
sksurgerycalibration.video.video_calibration_utils.convert_pd_to_opencv(ids, object_points, image_points)[source]

The PointDetectors from scikit-surgeryimage aren’t quite compatible with OpenCV.

sksurgerycalibration.video.video_calibration_utils.detect_points_in_canonical_space(point_detector, minimum_points_per_frame, video_data, images, camera_matrix, distortion_coefficients, reference_ids, reference_image_points, reference_image_size)[source]

Method that does the bulk of the heavy lifting in Datta 2009.

Parameters:
  • point_detector
  • minimum_points_per_frame
  • video_data
  • images
  • camera_matrix
  • distortion_coefficients
  • reference_ids
  • reference_image_points
  • reference_image_size
Returns:

sksurgerycalibration.video.video_calibration_utils.detect_points_in_stereo_canonical_space(left_point_detector, right_point_detector, minimum_points_per_frame, left_video_data, left_images, left_camera_matrix, left_distortion_coeffs, right_video_data, right_images, right_camera_matrix, right_distortion_coeffs, reference_ids, reference_image_points, reference_image_size)[source]

Method that does the bulk of the heavy lifting in Datta 2009.

The reason we need a combined stereo one, instead of calling the mono one twice, is because at any point, if either left or right channel fails feature detection, we need to drop that image from BOTH channels.

Parameters:
  • left_point_detector
  • right_point_detector
  • minimum_points_per_frame
  • left_video_data
  • left_images
  • left_camera_matrix
  • left_distortion_coeffs
  • right_video_data
  • right_images
  • right_camera_matrix
  • right_distortion_coeffs
  • reference_ids
  • reference_image_points
  • reference_image_size
Returns:

sksurgerycalibration.video.video_calibration_utils.distort_points(image_points, camera_matrix, distortion_coeffs)[source]

Distorts image points, reversing the effects of cv2.undistortPoints.

Slow, but should do for now, for offline calibration at least.

Parameters:
  • image_points – undistorted image points.
  • camera_matrix – [3x3] camera matrix
  • distortion_coeffs – [1x5] distortion coefficients
Returns:

distorted points

sksurgerycalibration.video.video_calibration_utils.extrinsic_matrix_to_vecs(transformation_matrix)[source]

Method to convert a [4x4] rigid body matrix to an rvec and tvec.

Parameters:transformation_matrix – [4x4] rigid body matrix.

:return [3x1] Rodrigues rotation vec, [3x1] translation vec

sksurgerycalibration.video.video_calibration_utils.extrinsic_vecs_to_matrix(rvec, tvec)[source]

Method to convert rvec and tvec to a 4x4 matrix.

Parameters:
  • rvec – [3x1] ndarray, Rodrigues rotation params
  • rvec – [3x1] ndarray, translation params
Returns:

[3x3] ndarray, Rotation Matrix

sksurgerycalibration.video.video_calibration_utils.filter_common_points_all_images(left_ids, left_object_points, left_image_points, right_ids, right_image_points, minimum_points)[source]

Loops over each images’s data, filtering per image. See: filter_common_points_per_image :return: Vectors of outputs from filter_common_points_per_image

sksurgerycalibration.video.video_calibration_utils.filter_common_points_per_image(left_ids, left_object_points, left_image_points, right_ids, right_image_points, minimum_points)[source]

For stereo calibration, we need common points in left and right. Remember that a point detector, may provide different numbers of points for left and right, and they may not be sorted.

Parameters:
  • left_ids – ndarray of integer point ids
  • left_object_points – Vector of Vector of 1x3 float 32
  • left_image_points – Vector of Vector of 1x2 float 32
  • right_ids – ndarray of integer point ids
  • right_image_points – Vector of Vector of 1x2 float 32
  • minimum_points – the number of minimum common points to accept
Returns:

common ids, object_points, left_image_points, right_image_points

sksurgerycalibration.video.video_calibration_utils.map_points_from_canonical_to_original(images_array, image_index, video_data, ids, object_points, image_points, homography, camera_matrix, distortion_coeffs)[source]

Utility method to map image points, detected in a canonical face on image, back to the original image space.

Parameters:
  • images_array
  • image_index
  • video_data
  • ids
  • object_points
  • image_points
  • homography
  • camera_matrix
  • distortion_coeffs
Returns:

sksurgerycalibration.video.video_calibration_utils.match_points_by_id(ids_1, points_1, ids_2, points_2)[source]

Returns an ndarray of matched points, matching by their identifier.

Parameters:
  • ids_1 – ndarray [Mx1] list of ids for points_1
  • points_1 – ndarray [Mx2 or 3] of 2D or 3D points
  • ids_2 – ndarray [Nx1] list of ids for points_2
  • points_2 – ndarray [Nx2 or 3] of 2D or 3D points
Returns:

ndarray. Number of rows is the number of common points by ids.