So we found out that the AR0234 camera modules are compatible with the ToF. Their specs are close to the IMX296 we originally chose so we'll try with them.
I'm trying to use this script to align the tof to a RGB cam : https://docs.luxonis.com/software/depthai/examples/tof_align/
But I get this error :
[18443010F19A5B1200] [3.2] [9.150] [ImageAlign(4)] [error] Failed to get calibration data: _Map_base::at
Which could make sense since I did not specify the extrinsics between the rgb cameras and the tof. So I'm trying to do that when flashing the calibration. Here is my flashing function :
def flash(self, calib_json_file: str, tof=False) -> None:
"""Flashes the calibration to the camera.
The calibration is read from the calib_json_file and flashed into the camera's eeprom.
"""
now = str(datetime.now()).replace(" ", "_").split(".")[0]
device_calibration_backup_file = Path("./CALIBRATION_BACKUP_" + now + ".json")
deviceCalib = self._device.readCalibration()
deviceCalib.eepromToJsonFile(device_calibration_backup_file)
self._logger.info(f"Backup of device calibration saved to {device_calibration_backup_file}")
os.environ["DEPTHAI_ALLOW_FACTORY_FLASHING"] = "235539980"
ch = dai.CalibrationHandler()
calibration_data = json.load(open(calib_json_file, "rb"))
cameras = calibration_data["cameras"]
camera_poses = calibration_data["camera_poses"]
self._logger.info("Setting intrinsics ...")
for cam_name, params in cameras.items():
K = np.array(params["K"])
D = np.array(params["dist"]).reshape((-1))
im_size = params["image_size"]
cam_socket = get_socket_from_name(cam_name, self.cam_config.name_to_socket)
ch.setCameraIntrinsics(cam_socket, K.tolist(), im_size)
ch.setDistortionCoefficients(cam_socket, D.tolist())
if self.cam_config.fisheye:
self._logger.info("Setting camera type to fisheye ...")
ch.setCameraType(cam_socket, dai.CameraModel.Fisheye)
self._logger.info("Setting extrinsics ...")
left_socket = get_socket_from_name("left", self.cam_config.name_to_socket)
right_socket = get_socket_from_name("right", self.cam_config.name_to_socket)
if tof:
print("FLASHING TOF EXTRINSICS")
tof_socket = get_socket_from_name("tof", self.cam_config.name_to_socket)
print("TOF SOCKET", tof_socket)
T_tof_to_left = np.eye(4)
T_tof_to_left[:3, 3] = [0, -3.2509, 0]
T_left_to_tof = np.linalg.inv(T_tof_to_left)
ch.setCameraExtrinsics(
tof_socket,
left_socket,
T_tof_to_left[:3, :3].tolist(),
T_tof_to_left[:3, 3].tolist(),
specTranslation=T_tof_to_left[:3, 3].tolist(),
)
ch.setCameraExtrinsics(
left_socket,
tof_socket,
T_left_to_tof[:3, :3].tolist(),
T_left_to_tof[:3, 3].tolist(),
specTranslation=T_left_to_tof[:3, 3].tolist(),
)
right_to_left = camera_poses["right_to_left"]
R_right_to_left = np.array(right_to_left["R"])
T_right_to_left = np.array(right_to_left["T"])
T_right_to_left *= 100 # Needs to be in centimeters (?) #Â TODO test
R_left_to_right, T_left_to_right = get_inv_R_T(R_right_to_left, T_right_to_left)
ch.setCameraExtrinsics(
left_socket,
right_socket,
R_right_to_left.tolist(),
T_right_to_left.tolist(),
specTranslation=T_right_to_left.tolist(),
)
ch.setCameraExtrinsics(
right_socket,
left_socket,
R_left_to_right,
T_left_to_right,
specTranslation=T_left_to_right,
)
ch.setStereoLeft(left_socket, np.eye(3).tolist())
ch.setStereoRight(right_socket, R_right_to_left.tolist())
print(
ch.getCameraExtrinsics(dai.CameraBoardSocket.CAM_D, dai.CameraBoardSocket.CAM_C)
) # extrinsics left camera <-> ToF OK
self._logger.info("Flashing ...")
try:
self._device.flashCalibration2(ch)
self._logger.info("Calibration flashed successfully")
except Exception as e:
self._logger.error("Flashing failed")
self._logger.error(e)
exit()
The calibration handler contains the extrinsics between the tof socket CAM_D
and the the rgb camera on CAM_C
print(
ch.getCameraExtrinsics(dai.CameraBoardSocket.CAM_D, dai.CameraBoardSocket.CAM_C)
) # extrinsics left camera <-> ToF OK
The flashing is successful, the rgb cameras are correctly stereo calibrated, the epilines check is good.
But I still have the Failed to get calibration data: _Map_base::at
error when trying the align script.
When trying to read the extrinsics from the flashed calibration like this :
import depthai as dai
device = dai.Device()
calib = device.readCalibration()
print(calib.getCameraExtrinsics(dai.CameraBoardSocket.CAM_D, dai.CameraBoardSocket.CAM_C))
I get this error
RuntimeError: There is no Camera data available corresponding to the the requested source cameraId
That's weird right ? The flashed calibration handler contained this info, but the calibration handler retrieved from after flashing does not. Am I doing something wrong ?
Thanks !