Chessboard/Point Detectors¶
All of the point detectors share a common get_points(img) method, which is called to locate relevant points in the image, but each detector has a particualar set of initialisation parameters.
Chessboard Detector¶
The chessboard detector requires the dimensions of the chessboard and the square size in mm as arguments to the constructor.
from sksurgeryimage.calibration.chessboard_point_detector import ChessboardPointDetector
number_of_corners = (13, 10)
square_size_mm = 3
detector = ChessboardPointDetector(number_of_corners, square_size_mm)
image = cv2.imread('tests/data/calib-ucl-chessboard/leftImage.png')
ids, object_points, image_points = detector.get_points(image)
We can annoate the detected locations onto the original image:
for idx in range(ids.shape[0]):
text = str(ids[idx][0])
x = int(image_points[idx][0])
y = int(image_points[idx][1])
cv2.putText(image,
text,
(x, y),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
(0, 255, 0),
2,
cv2.LINE_AA)
cv2.imwrite('annotated_image.png', image)
Dotty Grid Detector¶
We will use this pattern to test the dotty grid detector, with 18 rows, 25 columns, 5mm between dot centres, and a resolution of 80 pixels per mm.
First, we generate the dot centres, based on the pattern parameters:
Then we setup the point detector, and pass in the test image. An initial set of intrinsic calibraiton parameters are required for this detector.
We can visualise the results on the original grid, by annotating point markers:
ChARuCo & Chessboard Detector¶
Test image. 19 x 26 Aruco markers with size 5x4mm, 9x14 chessboard pattern with 3mm square sections.
Setup point detector:
ref_image = "tests/data/calibration/pattern_4x4_19x26_5_4_with_inset_9x14.png"
charuco_pattern = cv2.imread(ref_image)
min_points_to_detect = 50
num_squares = [19, 26]
square_size_mm = [5, 4]
chessboard_squares = [9, 14]
chessboard_square_size_mm = 3
filter_markers = True
point_detector = \
CharucoPlusChessboardPointDetector(
charuco_pattern,
minimum_number_of_points=min_points_to_detect,
number_of_charuco_squares=num_squares,
size_of_charuco_squares=square_size_mm,
charuco_filtering=filter_markers,
number_of_chessboard_squares=chessboard_squares,
chessboard_square_size=chessboard_square_size_mm,
)
Detect on image:
ids, object_points, image_points = point_detector.get_points(charuco_pattern)
Annotate image with detected point markers:
for idx in range(ids.shape[0]):
text = str(ids[idx][0])
x = int(image_points[idx][0])
y = int(image_points[idx][1])
cv2.putText(charuco_pattern,
text,
(x, y),
cv2.FONT_HERSHEY_SIMPLEX,
0.5,
(0, 255, 0),
2,
cv2.LINE_AA)