trifinger_cameras.charuco_board_handler module¶
Class for Charuco board detection and camera calibration.
- class trifinger_cameras.charuco_board_handler.CharucoBoardHandler(size_x: int, size_y: int, square_size: float, marker_size: float, camera_matrix=None, dist_coeffs=None)[source]¶
Bases:
object
Provides different actions using a Charuco Board.
- calibrate(files: List[str], visualize: bool = False)[source]¶
Calibrate camera given a directory of images.
Loads the given images and uses them for Charuco-based camera calibration. The resulting coefficients are printed to stdout and stored internally so they are used when detecting boards later on.
- Parameters:
files (list) – List of image files.
visualize (bool) – If True, visualize the detected corners when loading the images and visualize again after the calibration including the pose of the board.
- detect_board(image)[source]¶
Detect the board in the given image.
- Parameters:
image – Intput image.
- Returns:
Tuple containing:
charuco_corners: Pixel-positions of the detected corners. charuco_ids: IDs of the detected corners. rvec: Orientation of the board given as a Rodrigues vector.
Only if camera matrix is set.
tvec: Translation of the board. Only if camera matrix is set.
- Return type:
(tuple)
- detect_board_in_camera_stream(device=0)[source]¶
Show images from a camera and visualize the board if it is detected.
The function will loop forever. Press “q” in the image window to stop.
- Parameters:
device (int) – ID of the video capture device (e.g. a webcam).
- detect_board_in_files(files: List[str], visualize: bool = False)[source]¶
Detect the board in multiple files.
Tries to detect the Charuco board in the given list of image files.
- Parameters:
files – List of paths to image files.
visualize (bool) – If True, each image is shown for one second, visualizing the board if it is detected.
- Returns:
Tuple containing
- all_corners: List of lists of pixel-positions of detected
charuco corners (one element per image).
- all_ids: List of lists of IDs of detected charuco corners
(one element per image).
- image_shape: Tuple with width and height of the images
(assumes all images have same size!)
- Return type:
tuple
- detect_board_in_image(filename, visualize=False)[source]¶
Detect the board in the given image.
Returns the pose of the board if it is detected and also prints these values to stdout.
- Parameters:
filename (str) – Path to the image file.
visualize (bool) – If True, the result is visualized (press “q” to close the image window).
- Returns:
Tuple containing
rvec: Orientation of the board as a Rodrigues vector.
tvec: Translation of the board.
Values are None if the board is not detected.
- Return type:
(tuple)
- save_board(filename, dpi=300)[source]¶
Save the board as image.
- Parameters:
filename (str) – Output filename.
dpi (int) – Dots per inch. Used to determine the pixel size of the image based on the size of the squares. Note that OpenCV does not store the dpi value itself in the image file.
- visualize_board(image, charuco_corners, charuco_ids, rvec, tvec, wait_key)[source]¶
Visualize a detected board in the image.
Visualizes the detected board (corners and pose if given) in the image and shows it using cv2.imshow.
- Parameters:
image – Image in which the board was detected.
charuco_corners – See return value of detect_board().
charuco_ids – See return value of detect_board().
rvec – See return value of detect_board().
tvec – See return value of detect_board().
wait_key – Value that is passed to cv2.waitKey() when showing the image.
- Returns:
- True if the User pressed “q” in the image window,
otherwise False.
- Return type:
(bool)