Azure-Kinect-Sensor-SDK icon indicating copy to clipboard operation
Azure-Kinect-Sensor-SDK copied to clipboard

C++ vs C# Camera Extrinsics

Open Vangos opened this issue 6 years ago • 2 comments

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

  1. Create an Azure Kinect C# project or use an existing one.
  2. Find your Device object.
  3. Call device.GetCalibration().DeviceExtrinsics.
  4. 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#?

Vangos avatar Jul 29 '20 13:07 Vangos

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?

Zumra avatar Mar 15 '21 12:03 Zumra

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# 😉

Vangos avatar Mar 22 '21 16:03 Vangos