C++ vs C# Camera Extrinsics
Describe the bug
In C++, I can transform from a source to a target coordinate system by using the 2D extrinsics array:
calibration.extrinsics[K4A_CALIBRATION_TYPE_ACCEL][K4A_CALIBRATION_TYPE_DEPTH]
In C#, the Extrinsics array is 1D, thus it's unclear how to transform from one system to another.
To Reproduce
- Create an Azure Kinect C# project or use an existing one.
- Find your
Deviceobject. - Call
device.GetCalibration().DeviceExtrinsics. - Notice that the array is 1D instead of 2D.
Also, compare the C++ documentation to the C# documentation.
Both pages state:
The extrinsic parameters allow 3D coordinate conversions between depth camera, color camera, the IMU's gyroscope and accelerometer. To transform from a source to a target 3D coordinate system, use the parameters stored under extrinsics[source][target].
Am I probably missing something here? Is there a way to transform from one system to another in C#?
Exploring the content of the device.GetCalibration().DeviceExtrinsics, it seems to me that the 1D array can be indexed as:
DeviceExtrinsics[(int)CalibrationDeviceType.Num * (int)source + (int)target]
where source and target are of type CalibrationDeviceType.
This will obtain the parameters needed to transform from a source to a target 3D coordinate system.
Until there is a fix available, can the AK team confirm this is correct?
For anyone reading this, @Zumra's comment is correct. Until there's an official API, you can use the following extension method to transform between a source and a target calibration device:
public static class CalibrationExtensions
{
public static Extrinsics Extrinsics(this Calibration calibration,
CalibrationDeviceType from, CalibrationDeviceType to)
{
int index = (int)CalibrationDeviceType.Num * (int)from + (int)to;
return calibration.DeviceExtrinsics[index];
}
}
Usage:
Device _device = Device.Open();
// ...
Calibration calibration = _device.GetCalibration();
Extrinsics accelToDepth = calibration.Extrinsics(CalibrationDeviceType.Accel, CalibrationDeviceType.Depth);
float[] rotation = accelToDepth.Rotation;
That's how you can implement floor tracking in C# 😉