oakutils.calibration package
Module contents
Module for camera calibration utilities.
Classes
- CalibrationData
A class for storing calibration data.
- ColorCalibrationData
A class for storing color camera calibration data.
- MonoCalibrationData
A class for storing mono camera calibration data.
- StereoCalibrationData
A class for storing stereo camera calibration data.
Functions
- create_q_matrix
Creates a Q matrix from a stereo calibration.
- get_camera_calibration
Gets the camera calibration data from any device.
- get_oak1_calibration
Gets the camera calibration data from the OAK-1 device.
- get_oak1_calibration_basic
Gets the camera calibration data from the OAK-1 device, without computed info.
- get_oakd_calibration
Gets the camera calibration data from the OAK-D device.
- get_oakd_calibration_basic
Gets the camera calibration data from the OAK-D device, without computed info.
- get_oakd_calibration_primary_mono
Gets the camera calibration data from the OAK-D device, using the primary mono camera.
- class oakutils.calibration.CalibrationData(rgb: ColorCalibrationData, left: MonoCalibrationData, right: MonoCalibrationData, stereo: StereoCalibrationData, l2rgb_extrinsic: np.ndarray, r2rgb_extrinsic: np.ndarray, rgb2l_extrinsic: np.ndarray, rgb2r_extrinsic: np.ndarray, T_l_rgb: np.ndarray, T_r_rgb: np.ndarray, T_rgb_l: np.ndarray, T_rgb_r: np.ndarray, primary: MonoCalibrationData | None = None)
Bases:
objectAn object to store calibration data for an entire OAK camera.
- rgb
RGB camera calibration data.
- Type:
- left
Left mono camera calibration data.
- Type:
- right
Right mono camera calibration data.
- Type:
- stereo
Stereo camera calibration data.
- Type:
- l2rgb_extrinsic
Extrinsic matrix from the left to the RGB camera.
- Type:
np.ndarray
- r2rgb_extrinsic
Extrinsic matrix from the right to the RGB camera.
- Type:
np.ndarray
- rgb2l_extrinsic
Extrinsic matrix from the RGB to the left camera.
- Type:
np.ndarray
- rgb2r_extrinsic
Extrinsic matrix from the RGB to the right camera.
- Type:
np.ndarray
- T_l_rgb
Translation vector from the left to the RGB camera.
- Type:
np.ndarray
- T_r_rgb
Translation vector from the right to the RGB camera.
- Type:
np.ndarray
- T_rgb_l
Translation vector from the RGB to the left camera.
- Type:
np.ndarray
- T_rgb_r
Translation vector from the RGB to the right camera.
- Type:
np.ndarray
- primary
Primary camera calibration data.
- Type:
Optional[MonoCalibrationData], optional
See also
ColorCalibrationDataClass to store calibration data for a color camera.
MonoCalibrationDataClass to store calibration data for a mono camera.
StereoCalibrationDataClass to store calibration data for stereo cameras.
- T_l_rgb: np.ndarray
- T_r_rgb: np.ndarray
- T_rgb_l: np.ndarray
- T_rgb_r: np.ndarray
- l2rgb_extrinsic: np.ndarray
- left: MonoCalibrationData
- primary: MonoCalibrationData | None = None
- r2rgb_extrinsic: np.ndarray
- rgb2l_extrinsic: np.ndarray
- rgb2r_extrinsic: np.ndarray
- right: MonoCalibrationData
- stereo: StereoCalibrationData
- class oakutils.calibration.ColorCalibrationData(size: tuple[int, int], K: np.ndarray, D: np.ndarray, fx: float, fy: float, cx: float, cy: float, fov: float, fov_rad: float, P: np.ndarray | None = None, valid_region: tuple[int, int, int, int] | None = None, map_1: np.ndarray | None = None, map_2: np.ndarray | None = None, pinhole: PinholeCameraIntrinsic | None = None)
Bases:
objectClass to store calibration data for a color camera.
- K
Camera matrix.
- Type:
np.ndarray
- D
Distortion coefficients.
- Type:
np.ndarray
- P
Projection matrix.
- Type:
Optional[np.ndarray], optional
- valid_region
Valid region of the calibration generated by cv2.getOptimalNewCameraMatrix.
- map_1
Map 1 for undistortion generated by cv2.initUndistortRectifyMap.
- Type:
Optional[np.ndarray], optional
- map_2
Map 2 for undistortion generated by cv2.initUndistortRectifyMap.
- Type:
Optional[np.ndarray], optional
- pinhole
o3d pinhole camera intrinsic.
- Type:
Optional[PinholeCameraIntrinsic], optional
- D: np.ndarray
- K: np.ndarray
- class oakutils.calibration.MonoCalibrationData(size: tuple[int, int], K: np.ndarray, D: np.ndarray, fx: float, fy: float, cx: float, cy: float, fov: float, fov_rad: float, R: np.ndarray, T: np.ndarray, H: np.ndarray, valid_region: tuple[int, int, int, int] | None = None, map_1: np.ndarray | None = None, map_2: np.ndarray | None = None, pinhole: PinholeCameraIntrinsic | None = None)
Bases:
objectClass to store calibration data for a mono camera.
- K
Camera matrix.
- Type:
np.ndarray
- D
Distortion coefficients.
- Type:
np.ndarray
- R
Rotation matrix.
- Type:
np.ndarray
- T
Translation matrix.
- Type:
np.ndarray
- H
Homography matrix.
- Type:
np.ndarray
- valid_region
Valid region of the calibration generated by cv2.stereoRectify.
- map_1
Map 1 for undistortion generated by cv2.initUndistortRectifyMap.
- Type:
Optional[np.ndarray], optional
- map_2
Map 2 for undistortion generated by cv2.initUndistortRectifyMap.
- Type:
Optional[np.ndarray], optional
- pinhole
o3d pinhole camera intrinsic.
- Type:
Optional[PinholeCameraIntrinsic], optional
- D: np.ndarray
- H: np.ndarray
- K: np.ndarray
- R: np.ndarray
- T: np.ndarray
- class oakutils.calibration.StereoCalibrationData(left: MonoCalibrationData, right: MonoCalibrationData, R1: np.ndarray, R2: np.ndarray, T1: np.ndarray, T2: np.ndarray, H_left: np.ndarray, H_right: np.ndarray, l2r_extrinsic: np.ndarray, r2l_extrinsic: np.ndarray, Q_left: np.ndarray, Q_right: np.ndarray, baseline: float, primary: MonoCalibrationData | None = None, Q_primary: np.ndarray | None = None, Q_cv2: np.ndarray | None = None, R1_cv2: np.ndarray | None = None, R2_cv2: np.ndarray | None = None, P1: np.ndarray | None = None, P2: np.ndarray | None = None, valid_region_primary: tuple[int, int, int, int] | None = None, pinhole_primary: PinholeCameraIntrinsic | None = None)
Bases:
objectClass to store calibration data for stereo cameras.
- left
Left camera calibration data.
- Type:
- right
Right camera calibration data.
- Type:
- R1
Rectification transform for the left camera.
- Type:
np.ndarray
- R2
Rectification transform for the right camera.
- Type:
np.ndarray
- T1
Projection matrix for the left camera.
- Type:
np.ndarray
- T2
Projection matrix for the right camera.
- Type:
np.ndarray
- H_left
Homography matrix for the left camera.
- Type:
np.ndarray
- H_right
Homography matrix for the right camera.
- Type:
np.ndarray
- l2r_extrinsic
Extrinsic matrix from the left to the right camera.
- Type:
np.ndarray
- r2l_extrinsic
Extrinsic matrix from the right to the left camera.
- Type:
np.ndarray
- Q_left
Q matrix for the left camera.
- Type:
np.ndarray
- Q_right
Q matrix for the right camera.
- Type:
np.ndarray
- primary
Primary camera calibration data.
- Type:
Optional[MonoCalibrationData], optional
- Q_primary
Q matrix for the primary camera.
- Type:
Optional[np.ndarray], optional
- Q_cv2
Q matrix generated by cv2.stereoRectify.
- Type:
Optional[np.ndarray], optional
- R1_cv2
R1 matrix generated by cv2.stereoRectify.
- Type:
Optional[np.ndarray], optional
- R2_cv2
R2 matrix generated by cv2.stereoRectify.
- Type:
Optional[np.ndarray], optional
- P1
P1 matrix generated by cv2.stereoRectify.
- Type:
Optional[np.ndarray], optional
- P2
P2 matrix generated by cv2.stereoRectify.
- Type:
Optional[np.ndarray], optional
- valid_region_primary
Valid region of the primary camera.
- pinhole_primary
o3d pinhole camera intrinsic for the primary camera.
- Type:
Optional[PinholeCameraIntrinsic], optional
See also
MonoCalibrationDataClass to store calibration data for a mono camera.
- H_left: np.ndarray
- H_right: np.ndarray
- Q_left: np.ndarray
- Q_right: np.ndarray
- R1: np.ndarray
- R2: np.ndarray
- T1: np.ndarray
- T2: np.ndarray
- l2r_extrinsic: np.ndarray
- left: MonoCalibrationData
- primary: MonoCalibrationData | None = None
- r2l_extrinsic: np.ndarray
- right: MonoCalibrationData
- oakutils.calibration.create_q_matrix(fx: float, fy: float, cx: float, cy: float, baseline: float) ndarray
Use to create Q matrix for stereo depth map.
- Parameters:
- Returns:
Q matrix for stereo depth map.
- Return type:
np.ndarray
Note
This uses the OpenCV formula for Q matrix, with an alpha value of 0. Thus, the Q matrix is: [[1, 0, 0, -cx], [0, 1, 0, -cy], [0, 0, 0, (fx + fy) / 2], [0, 0, -1 / baseline, 0]]
- oakutils.calibration.get_camera_calibration(rgb_size: tuple[int, int] | None = None, mono_size: tuple[int, int] | None = None, device: dai.DeviceBase | None = None, *, basic: bool | None = None, is_primary_mono_left: bool | None = None) CalibrationData | ColorCalibrationData
Get the calibration of your OAK camera.
This function will return a different calibration datatype depending on which model camera is being used. OAK-D devices will return a CalibrationData object. OAK-1 devices will return a ColorCalibrationData object.
- Parameters:
device (Optional[dai.DeviceBase], optional) – DepthAI device object.
rgb_size (Optional[Tuple[int, int]], optional) – RGB camera resolution.
mono_size (Optional[Tuple[int, int]], optional) – Mono camera resolution.
basic (Optional[bool], optional) – Whether to get basic calibration data. If True, no computed data will be included such as cv2.remap or o3d.PinholeCameraIntrinsic (even if o3d is available).
is_primary_mono_left (Optional[bool], optional) – Whether the primary mono camera is the left camera. This parameter is only used for cameras with depth imaging onboard.
- Returns:
Object containing all the calibration data.
- Return type:
- Raises:
ValueError – If the camera type is not recognized. If the RGB size is not provided for OAK-1 devices. If the RGB and mono sizes are not provided for OAK-D devices.
- oakutils.calibration.get_oak1_calibration(rgb_size: tuple[int, int], device: DeviceBase | None = None) ColorCalibrationData
Use to create the full ColorCalibrationData object.
This includes the calibration data for the RGB camera.
Note
Requires available OAK device. If device is not provided, dai.Device() will be used.
- Parameters:
- Returns:
Object containing all the calibration data.
- Return type:
- oakutils.calibration.get_oak1_calibration_basic(device: DeviceBase | None = None, rgb_size: tuple[int, int] = (1920, 1080)) ColorCalibrationData
Use to get camera calibration data from OAK-1 device.
Note
Requires available OAK device. If device is not provided, dai.Device() will be used.
- Parameters:
- Returns:
Object containing all the calibration data.
- Return type:
- oakutils.calibration.get_oakd_calibration(rgb_size: tuple[int, int], mono_size: tuple[int, int], device: DeviceBase | None = None, *, is_primary_mono_left: bool | None = None) CalibrationData
Use to create the full CalibrationData object.
This includes the calibration data for the RGB camera, the left mono camera, the right mono camera, and the primary mono camera. As well as all OpenCV and Open3D compatible data for each camera.
- Parameters:
is_primary_mono_left (Optional[bool], optional) – Whether the primary mono camera is the left or right mono camera. Defaults to True.
device (Optional[dai.Device], optional) – DepthAI device object.
- Returns:
Object containing all the calibration data.
- Return type:
- Raises:
RuntimeError – If the mono cameras cannot be found.
- oakutils.calibration.get_oakd_calibration_basic(device: DeviceBase | None = None, rgb_size: tuple[int, int] = (1920, 1080), mono_size: tuple[int, int] = (640, 400)) CalibrationData
Use to get camera calibration data from OAK-D device.
Note
Requires available OAK device. If device is not provided, dai.Device() will be used.
- Parameters:
- Returns:
Object containing all the calibration data.
- Return type:
- oakutils.calibration.get_oakd_calibration_primary_mono(device: DeviceBase | None = None, rgb_size: tuple[int, int] = (1920, 1080), mono_size: tuple[int, int] = (640, 400), *, is_primary_mono_left: bool | None = None) CalibrationData
Use to get the calibration data for both RGB and mono cameras and primary mono camera.
Note
Requires available OAK device.
- Parameters:
- Returns:
Object containing all the calibration data.
- Return type: