sksurgeryimage.calibration.charuco module

Functions to support camera calibration using ChArUco chessboard markers.

sksurgeryimage.calibration.charuco.detect_charuco_points(dictionary, board, image, camera_matrix=None, distortion_coefficients=None, filtering=False)[source]

Extracts ChArUco points. If you can provide camera matrices, it may be more accurate.

Parameters:
  • dictionary – aruco dictionary definition
  • board – aruco board definition
  • image – grey scale image in which to search
  • camera_matrix – if specified, the 3x3 camera intrinsic matrix
  • distortion_coefficients – if specified, the distortion coefficients
  • filtering – if True, filter out wrongly detected markers
Returns:

marker_corners, marker_ids, chessboard_corners, chessboard_ids

sksurgeryimage.calibration.charuco.draw_charuco_corners(image, chessboard_corners, chessboard_ids)[source]

Function to draw chessboard corners on an image.

Parameters:
  • image – input image
  • chessboard_corners – from detect_charuco_points
  • chessboard_ids – from detect_charuco_points
Returns:

new image with corners marked

sksurgeryimage.calibration.charuco.erase_charuco_markers(image, marker_corners)[source]

Method to automatically blank out ChArUco markers, leaving an image that looks like it contains just a chessboard, rather than ChArUco board. It does this by drawing a plain white polygon, with vertices defined by the tag detection process. So, on a synthetic image, this works perfectly. On a real image, due to blurring or other artefacts such as combing, there may be some residual.

Parameters:
  • image – image containing a view of a ChArUco board.
  • marker_corners – detected corners
Returns:

edited image

sksurgeryimage.calibration.charuco.filter_out_wrong_markers(marker_corners, marker_ids, board)[source]

Filters out markers that were mis-labelled. For each inner corner on the ChArUco board, if both neighbouring markers are detected, look at the projected positions of this corner using the perspective transformations obtained form the two markers. If the two positions are not close (further than 20 pixels away), then at least one of the markers is mis-labelled but we won’t know which one. Remove both markers.

Parameters:
  • marker_corners – marker corners detected by OpenCV
  • marker_ids – ids of markers detected
  • board – charuco board definition
Returns:

marker_corners, marker_ids

sksurgeryimage.calibration.charuco.make_charuco_board(dictionary, number_of_squares, size, image_size)[source]

Generates a ChArUco pattern.

Don’t forget to select an image size that is a nice multiple of the square size in millimetres, to avoid any interpolation artefacts. You should check the resultant image has only 2 values, [0|255], and nothing interpolated between these two numbers.

Parameters:
  • dictionary – aruco dictionary definition
  • number_of_squares – tuple of (number in x, number in y)
  • size – tuple of (size of chessboard square, size of internal tag), mm.
  • image_size – tuple of (image width, image height), pixels.
Returns:

image, board

sksurgeryimage.calibration.charuco.make_charuco_with_chessboard(dictionary=<aruco_Dictionary 0x7fb1e48cbe30>, charuco_squares=(19, 26), charuco_size=(5, 4), pixels_per_millimetre=10, chessboard_squares=(9, 14), chessboard_size=3, chessboard_border=0.7)[source]

Helper function to make an image of a calibration target combining ChArUco markers and a chessboard. It’s up to the caller to work out a nice number of pixels per millimetre, so that the resultant image is correctly scaled.

Defaults are as used in SmartLiver project. Not also, that we compute the image and coordinates in portrait, but it’s used in landscape.

Parameters:
  • dictionary – ChArUco dictionary
  • charuco_squares – tuple of (squares in x, squares in y)
  • charuco_size – tuple of (external size, internal tag size) in mm
  • pixels_per_millimetre – which determines size of eventual image.
  • chessboard_squares – tuple of (squares in x, squares in y)
  • chessboard_size – size of chessboard squares in mm
  • chessboard_border – border round chessboard, as fraction of square
Returns:

calibration image