K4A.Net — Three-in-one managed .NET library to work with Azure Kinect devices (also known as Kinect for Azure, K4A, Kinect v4). It consists of the following "components":
Sensor API
— access to depth camera, RGB camera, accelerometer and gyroscope, plus device-calibration data and synchronization control- Corresponding namespace:
K4AdotNet.Sensor
- Corresponding native API:
k4a.h
- Corresponding namespace:
Record API
— data recording from device to MKV-files, and data reading from such files- Corresponding namespace:
K4AdotNet.Record
- Corresponding native API:
record.h
andplayback.h
- Corresponding namespace:
Body Tracking API
— body tracking of multiple skeletons including eyes, ears and nose- Corresponding namespace:
K4AdotNet.BodyTracking
- Corresponding native API:
k4abt.h
- Corresponding namespace:
- Written fully on C#
- No unsafe code in library K4AdotNet itself (only
DllImports
) - CLS-compliant (can be used from any .Net-compatible language, including C#, F#, VB.Net)
- Library K4AdotNet is compiled against .NET Standard 2.0 and .NET Framework 4.6.1 target frameworks
- This makes it compatible with .NET Core 2.0 and later, .NET Framework 4.6.1 and later, Unity 2018.1 and later, etc.
- See https://docs.microsoft.com/en-us/dotnet/standard/net-standard for details
- Clean API, which is close to C/C++ native API from Azure Kinect Sensor SDK and Azure Kinect Body Tracking SDK.
- Plus useful helper methods, additional checks and meaningful exceptions.
- Full feature set (all API provided by native SDKs are available in this C# wrapper)
- Up-to-date with the latest versions of native SDKs
- No additional dependencies
- Except dependencies on native libraries (DLLs) from Azure Kinect Sensor SDK and Azure Kinect Body Tracking SDK
- Native libraries from Azure Kinect Sensor SDK are included to repository(see
externals
directory) and NuGet package - But native libraries from Azure Kinect Body Tracking SDK are not included to repository. It is recommended to install Azure Kinect Body Tracking SDK separately. For details see below
- Plenty of powerful samples:
- for .NET Core
- for WPF
- for Unity
- and even more samples will be available soon (stay tuned)
- Well documented
- Unit-tested (more tests are awaited)
- Potentially multi-platform (Windows, Linux)
- But currently tested only under Windows
- And most of samples are written using WPF
- Available as NuGet package: https://www.nuget.org/packages/K4AdotNet
K4AdotNet depends on the following native libraries (DLLs) from Azure Kinect Sensor SDK and Azure Kinect Body Tracking SDK:
Library "component" | Depends on | Version in use | Location in repository | Included in NuGet package |
---|---|---|---|---|
Sensor API | k4a.dll , depthengine_2_0.dll (1) |
1.3.0 | externals/k4a/windows-desktop/amd64 |
YES |
Record API | k4arecord.dll |
1.3.0 | externals/k4a/windows-desktop/amd64 |
YES |
Body Tracking API | k4abt.dll (2), dnn_model_2_0.onnx |
1.0.0 | no(3) |
Notes:
- (1)
depthengine_2_0.dll
is required only if you are usingTransformation
orDevice
classes. All other Sensor API (types fromK4AdotNet.Sensor
namespace) depends only onk4a.dll
. - (2)
k4abt.dll
uses ONNX Runtime —onnxruntime.dll
, which in turn depends on the following NVIDIA cuDNN and NVIDIA CUDA 10.0 libraries:cudnn64_7.dll
,cublas64_100.dll
,cudart64_100.dll
. Also, Visual C++ Redistributable for Visual Studio 2015 is required:vcomp140.dll
. - (3) The full list of libraries and data files required for Body Tracking:
k4abt.dll
(3.7 MB),
dnn_model_2_0.onnx
(159 MB),
cudnn64_7.dll
(333 MB),
cublas64_100.dll
(64 MB),
cudart64_100.dll
(0.4 MB),
vcomp140.dll
(0.2 MB).
It is mostly unpractical to have such bulky files in repositories. For this reason they are not included to the repository. Also, they are not included to NuGet package.
How to use Body Tracking runtime:
- The easiest way to use Body Tracking is to ask user to install Body Tracking SDK by him/herself: https://docs.microsoft.com/en-us/azure/Kinect-dk/body-sdk-setup
- But you can also put all required libraries and data files to the output directory of your project (on post-build step, for example). All required libraries and data files can be found in directory
tools
of Body Tracking SDK. - K4AdotNet is trying to find Body Tracking runtime in the following locations:
- directory with executable file
- directory with K4AdotNet assembly
- installation directory of Body Tracking SDK under
Program Files
- Use
bool Sdk.IsBodyTrackingRuntimeAvailable(out string message)
method to check if Body Tracking runtime and all required components are available/installed - Also, you can optionally call
bool Sdk.TryInitializeBodyTrackingRuntime(out string message)
method on start of your application to initialize Body Tracking runtime (it can take a few seconds)
See https://github.com/bibigone/k4a.net/releases
- More unit and integration tests
- More samples (Recording, 3D view, Box-man, IMU...)
- Find out how to convert MJPEG -> BGRA faster (implementation in
k4a.dll
is very slow) - Test under Linux, samples for Linux (using Avalonia UI Framework?)
- Some hosting for HTML documentation (DocFX + github.io?)
- Open
K4AdotNet.sln
in Visual Studio 2017 or Visual Studio 2019 - Build solution (
Ctrl+Shift+B
) - After that you can run and explore samples:
K4AdotNet.Samples.Core.BodyTrackingSpeed
— sample .NET Core console application to measure speed of Body Tracking.K4AdotNet.Samples.Wpf.Viewer
— sample WPF application to demonstrate usage of Sensor API and Record API.K4AdotNet.Samples.Wpf.BodyTracker
— sample WPF application to demonstrate usage of Body Tracking API.K4AdotNet.Samples.Wpf.BackgroundRemover
— sample WPF application implementing the background removal effect for color picture with the help of depth data.
- Instruction on building Unity sample can be found here.