Skip to content

Commit d87e80a

Browse files
fkavacheVache Katsadze
andauthored
Updated sample unity BT application (#70)
* Updated sample unity BT application Co-authored-by: Vache Katsadze <v-vkatsadze@microsoft.com>
1 parent 2e36876 commit d87e80a

File tree

4 files changed

+110
-98
lines changed

4 files changed

+110
-98
lines changed

body-tracking-samples/sample_unity_bodytracking/Assets/Scripts/SkeletalTrackingProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class SkeletalTrackingProvider : BackgroundDataProvider
1111
bool readFirstFrame = false;
1212
TimeSpan initialTimestamp;
1313

14-
public SkeletalTrackingProvider(int id): base(id)
14+
public SkeletalTrackingProvider(int id) : base(id)
1515
{
1616
Debug.Log("in the skeleton provider constructor");
1717
}
@@ -39,11 +39,11 @@ protected override void RunBackgroundThreadAsync(int id, CancellationToken token
3939
WiredSyncMode = WiredSyncMode.Standalone,
4040
});
4141

42-
UnityEngine.Debug.Log("Open K4A device successful. id " + id + "sn:" + device.SerialNum );
42+
UnityEngine.Debug.Log("Open K4A device successful. id " + id + "sn:" + device.SerialNum);
4343

4444
var deviceCalibration = device.GetCalibration();
4545

46-
using (Tracker tracker = Tracker.Create(deviceCalibration, new TrackerConfiguration() { ProcessingMode = TrackerProcessingMode.Cuda, SensorOrientation = SensorOrientation.Default }))
46+
using (Tracker tracker = Tracker.Create(deviceCalibration, new TrackerConfiguration() { ProcessingMode = TrackerProcessingMode.Gpu, SensorOrientation = SensorOrientation.Default }))
4747
{
4848
UnityEngine.Debug.Log("Body tracker created.");
4949
while (!token.IsCancellationRequested)
@@ -127,4 +127,4 @@ protected override void RunBackgroundThreadAsync(int id, CancellationToken token
127127
token.ThrowIfCancellationRequested();
128128
}
129129
}
130-
}
130+
}
Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
if not exist Assets\Plugins mkdir Assets\Plugins
2-
set BODY_TRACKING_SDK_PATH=C:\Program Files\Azure Kinect Body Tracking SDK\
3-
set BODY_TRACKING_TOOLS_PATH="%BODY_TRACKING_SDK_PATH%tools\"
4-
set BODY_TRACKING_LIB_PATH="%BODY_TRACKING_SDK_PATH%sdk\netstandard2.0\release\"
5-
copy %BODY_TRACKING_LIB_PATH%Microsoft.Azure.Kinect.BodyTracking.dll Assets\Plugins
6-
copy %BODY_TRACKING_LIB_PATH%Microsoft.Azure.Kinect.BodyTracking.pdb Assets\Plugins
7-
copy %BODY_TRACKING_LIB_PATH%Microsoft.Azure.Kinect.BodyTracking.deps.json Assets\Plugins
8-
copy %BODY_TRACKING_LIB_PATH%Microsoft.Azure.Kinect.BodyTracking.xml Assets\Plugins
9-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.dll Assets\Plugins
10-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.pdb Assets\Plugins
11-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.deps.json Assets\Plugins
12-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.xml Assets\Plugins
13-
copy %BODY_TRACKING_TOOLS_PATH%cublas64_11.dll Assets\Plugins
14-
copy %BODY_TRACKING_TOOLS_PATH%cublasLt64_11.dll Assets\Plugins
15-
copy %BODY_TRACKING_TOOLS_PATH%cudart64_110.dll Assets\Plugins
16-
copy packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll Assets\Plugins
17-
copy packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll Assets\Plugins
18-
copy packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll Assets\Plugins
19-
copy packages\System.Reflection.Emit.Lightweight.4.6.0\lib\netstandard2.0\System.Reflection.Emit.Lightweight.dll Assets\Plugins
20-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\native\amd64\release\depthengine_2_0.dll Assets\Plugins
21-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\native\amd64\release\k4a.dll Assets\Plugins
22-
copy packages\Microsoft.Azure.Kinect.Sensor.1.4.1\lib\native\amd64\release\k4arecord.dll Assets\Plugins
23-
copy %BODY_TRACKING_TOOLS_PATH%onnxruntime.dll Assets\Plugins
24-
copy %BODY_TRACKING_TOOLS_PATH%k4abt.dll Assets\Plugins
25-
copy %BODY_TRACKING_TOOLS_PATH%cudnn64_8.dll .\
26-
copy %BODY_TRACKING_TOOLS_PATH%cudnn_cnn_infer64_8.dll .\
27-
copy %BODY_TRACKING_TOOLS_PATH%cudnn_ops_infer64_8.dll .\
28-
copy %BODY_TRACKING_TOOLS_PATH%onnxruntime.dll .\
29-
copy %BODY_TRACKING_TOOLS_PATH%dnn_model_2_0_op11.onnx .\
30-
copy %BODY_TRACKING_TOOLS_PATH%cublas64_11.dll .\
31-
copy %BODY_TRACKING_TOOLS_PATH%cublasLt64_11.dll .\
32-
copy %BODY_TRACKING_TOOLS_PATH%cudart64_110.dll .\
33-
copy %BODY_TRACKING_TOOLS_PATH%cufft64_10.dll .\
2+
3+
set PACKAGE_BTSDK=packages\Microsoft.Azure.Kinect.BodyTracking.1.1.2
4+
set PACKAGE_ONNXRUNTIME=packages\Microsoft.Azure.Kinect.BodyTracking.ONNXRuntime.1.10.0
5+
set PACKAGE_SENSOR_SDK=packages\Microsoft.Azure.Kinect.Sensor.1.4.1
6+
set PACKAGE_SYSTEM_BUFFERS=packages\System.Buffers.4.4.0
7+
set PACKAGE_SYSTEM_MEMORY=packages\System.Memory.4.5.3
8+
set PACKAGE_SYSTEM_RUNTIME_SERVICES=packages\System.Runtime.CompilerServices.Unsafe.4.5.2
9+
set PACKAGE_SYSTEM_REFLECTION=packages\System.Reflection.Emit.Lightweight.4.6.0
10+
11+
copy %PACKAGE_SENSOR_SDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.dll Assets\Plugins
12+
copy %PACKAGE_SENSOR_SDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.pdb Assets\Plugins
13+
copy %PACKAGE_SENSOR_SDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.deps.json Assets\Plugins
14+
copy %PACKAGE_SENSOR_SDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.Sensor.xml Assets\Plugins
15+
copy %PACKAGE_SENSOR_SDK%\lib\native\amd64\release\depthengine_2_0.dll Assets\Plugins
16+
copy %PACKAGE_SENSOR_SDK%\lib\native\amd64\release\k4a.dll Assets\Plugins
17+
copy %PACKAGE_SENSOR_SDK%\lib\native\amd64\release\k4arecord.dll Assets\Plugins
18+
copy %PACKAGE_SYSTEM_BUFFERS%\lib\netstandard2.0\System.Buffers.dll Assets\Plugins
19+
copy %PACKAGE_SYSTEM_MEMORY%\lib\netstandard2.0\System.Memory.dll Assets\Plugins
20+
copy %PACKAGE_SYSTEM_RUNTIME_SERVICES%\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll Assets\Plugins
21+
copy %PACKAGE_SYSTEM_REFLECTION%\lib\netstandard2.0\System.Reflection.Emit.Lightweight.dll Assets\Plugins
22+
23+
copy %PACKAGE_BTSDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.BodyTracking.dll Assets\Plugins
24+
copy %PACKAGE_BTSDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.BodyTracking.pdb Assets\Plugins
25+
copy %PACKAGE_BTSDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.BodyTracking.deps.json Assets\Plugins
26+
copy %PACKAGE_BTSDK%\lib\netstandard2.0\Microsoft.Azure.Kinect.BodyTracking.xml Assets\Plugins
27+
copy %PACKAGE_BTSDK%\lib\native\amd64\release\k4abt.dll Assets\Plugins
28+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\directml.dll Assets\Plugins
29+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime.dll Assets\Plugins
30+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime_providers_cuda.dll Assets\Plugins
31+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime_providers_shared.dll Assets\Plugins
32+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime_providers_tensorrt.dll Assets\Plugins
33+
34+
copy %PACKAGE_BTSDK%\content\dnn_model_2_0_op11.onnx .\
35+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\directml.dll .\
36+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime.dll .\
37+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime_providers_cuda.dll .\
38+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime_providers_shared.dll .\
39+
copy %PACKAGE_ONNXRUNTIME%\lib\native\amd64\release\onnxruntime_providers_tensorrt.dll .\

body-tracking-samples/sample_unity_bodytracking/README.md

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
### Directions for getting started:
44

5-
65
#### 1) First get the latest nuget packages of libraries:
76

87
Open the sample_unity_bodytracking project in Unity.
@@ -20,42 +19,41 @@ Update-Package -reinstall
2019

2120
The latest libraries will be put in the Packages folder under sample_unity_bodytracking
2221

22+
#### 2) Next add these libraries to the Assets/Plugins folder:
2323

24-
#### 2) Next download the latest Body Tracking Package
25-
26-
Go to: https://docs.microsoft.com/en-us/azure/kinect-dk/body-sdk-download and follow the directions to install the sdk for version 1.1.0
27-
28-
The default location for the SDK is: C:\Program Files\Azure Kinect Body Tracking SDK
29-
30-
**You can download the SDK wherever you like but you will then need to update the paths in the MoveLibraryFiles.bat file**
31-
32-
set BODY_TRACKING_SDK_PATH="YOUR PATH HERE"
33-
24+
You can do this by hand or just **run the batch file MoveLibraryFile.bat** in the sample_unity_bodytracking directory
3425

35-
#### 3) Next add these libraries to the Assets/Plugins folder:
36-
37-
You can do this by hand or just run the batch file MoveLibraryFile.bat in the sample_unity_bodytracking directory
38-
39-
40-
From Wherever You Installed Azure Kinect Body Tracking SDK\sdk\netstandard2.0\release
26+
From Packages/Microsoft.Azure.Kinect.BodyTracking.1.1.2/lib/netstandard2.0
4127

4228
- Microsoft.Azure.Kinect.BodyTracking.deps.json
4329
- Microsoft.Azure.Kinect.BodyTracking.xml
4430
- Microsoft.Azure.Kinect.BodyTracking.dll
4531
- Microsoft.Azure.Kinect.BodyTracking.pdb
4632

33+
From Packages/Microsoft.Azure.Kinect.BodyTracking.1.1.2/lib/native/amd64/release/
34+
35+
- k4abt.dll
36+
37+
From Packages/Microsoft.Azure.Kinect.BodyTracking.ONNXRuntime.1.10.0/lib/native/amd64/release
38+
39+
- directml.dll
40+
- onnxruntime.dll
41+
- onnxruntime_providers_cuda.dll
42+
- onnxruntime_providers_shared.dll
43+
- onnxruntime_providers_tensorrt.dll
44+
4745
From Packages/Microsoft.Azure.Kinect.Sensor.1.4.1/lib/netstandard2.0
4846

4947
- Microsoft.Azure.Kinect.Sensor.deps.json
5048
- Microsoft.Azure.Kinect.Sensor.xml
5149
- Microsoft.Azure.Kinect.Sensor.dll
5250
- Microsoft.Azure.Kinect.Sensor.pdb
5351

54-
From Azure Kinect Body Tracking SDK\tools
52+
From Packages/Microsoft.Azure.Kinect.Sensor.1.4.1/lib/native/amd64/release
5553

56-
- cudart64_110.dll
57-
- cublas64_11.dll
58-
- cublasLt64_11.dll
54+
- depthengine_2_0.dll
55+
- k4a.dll
56+
- k4arecord.dll
5957

6058
From Packages/System.Buffers.4.4.0/lib/netstandard2.0
6159

@@ -73,71 +71,77 @@ From Packages/System.Runtime.CompilerServices.Unsafe.4.5.2/lib/netstandard2.0
7371

7472
- System.Runtime.CompilerServices.Unsafe.dll
7573

76-
From Packages/Microsoft.Azure.Kinect.Sensor.1.4.1/lib/native/amd64/release
7774

78-
- depthengine_2_0.dll
79-
- k4a.dll
80-
- k4arecord.dll
75+
#### 3) Then add these libraries to the sample_unity_bodytracking project root directory that contains the Assets folder:
8176

82-
From Azure Kinect Body Tracking SDK\sdk\windows-desktop\amd64\release\bin
77+
You can do this by hand or just **run the batch file MoveLibraryFile.bat** in the sample_unity_bodytracking directory
8378

84-
- k4abt.dll
79+
From Packages/Microsoft.Azure.Kinect.BodyTracking.1.1.2/content
80+
81+
- dnn_model_2_0_op11.onnx
82+
83+
From Packages/Microsoft.Azure.Kinect.BodyTracking.ONNXRuntime.1.10.0/lib/native/amd64/release
84+
85+
- directml.dll
8586
- onnxruntime.dll
87+
- onnxruntime_providers_cuda.dll
88+
- onnxruntime_providers_shared.dll
89+
- onnxruntime_providers_tensorrt.dll
8690

8791

88-
#### 4) Then add these libraries to the sample_unity_bodytracking project root directory that contains the Assets folder
92+
#### 4) Next make sure you have all the [required DLLs for ONNX Runtime execution](https://docs.microsoft.com/en-us/azure/kinect-dk/body-sdk-setup#required-dlls-for-onnx-runtime-execution-environments):
8993

90-
From Azure Kinect Body Tracking SDK\tools\
94+
First, download and install [Visual C++ Redistributable](https://docs.microsoft.com/en-us/azure/kinect-dk/body-sdk-setup#visual-c-redistributable-for-visual-studio-2015).
9195

92-
- cudnn64_8.dll
93-
- cudnn_cnn_infer64_8.dll
94-
- cudnn_ops_infer64_8.dll
96+
Additionally:
9597

96-
From Azure Kinect Body Tracking SDK\tools\
98+
**For CUDA**:
99+
* Download and install appropriate version of CUDA and make sure that CUDA_PATH exists as an environment variable (e.g C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4).
100+
* Download and install appropriate version of cuDNN and add a value to the PATH environment variable for it (e.g C:\Program Files\NVIDIA GPU Computing Toolkit\cuda-8.2.2.6\bin).
97101

98-
- cudart64_110.dll
99-
- cublas64_11.dll
100-
- cublasLt64_11.dll
101-
- cufft64_10.dll
102+
**For TensorRT**:
103+
* Download and install appropriate version of CUDA and make sure that CUDA_PATH exists as an environment variable (e.g C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4).
104+
* Download and install appropriate version of TensorRT and add a value to the PATH environment variable for it (e.g C:\Program Files\NVIDIA GPU Computing Toolkit\TensorRT-8.2.1.8\lib).
102105

103-
From Azure Kinect Body Tracking SDK\tools\
106+
**For DirectML**:
107+
* Copy the **directml.dll** from the sample_unity_bodytracking folder to the unity editor directory (e.g C:\Program Files\Unity\Hub\Editor\2019.1.2f1\Editor)
104108

105-
- onnxruntime.dll
106109

107-
From Azure Kinect Body Tracking SDK\tools\
110+
#### 5) Then specify Execution Provider for the tracking:
108111

109-
- dnn_model_2_0_op11.onnx
112+
In the ...\sample_unity_bodytracking\Assets\Scripts\SkeletalTrackingProvider.cs change the ProcessingMode to the one you want.
113+
114+
* TrackerProcessingMode.GPU (Defaults to DirectML for Windows)
115+
* TrackerProcessingMode.CPU
116+
* TrackerProcessingMode.Cuda
117+
* TrackerProcessingMode.TensorRT
118+
* TrackerProcessingMode.DirectML
110119

111120

112-
#### 5) Open the Unity Project and under Scenes/ select the Kinect4AzureSampleScene
121+
#### 6) Open the Unity Project and under Scenes/ select the Kinect4AzureSampleScene:
113122

114123
![alt text](./UnitySampleGettingStarted.png)
115124

116125

117126
Press play.
118127

119-
#### If you wish to create a new scene just:
120128

121-
1) create a gameobject and add the component for the main.cs script
122-
2) go to the prefab folder and drop in the Kinect4AzureTracker prefab
123-
3) now drag the gameobject for the Kinect4AzureTracker onto the Tracker slot in the main object in the inspector.
129+
#### If you wish to create a new scene:
124130

131+
* Create a gameobject and add the component for the main.cs script.
132+
* Go to the prefab folder and drop in the Kinect4AzureTracker prefab.
133+
* Now drag the gameobject for the Kinect4AzureTracker onto the Tracker slot in the main object in the inspector.
125134

126-
### Finally if you Build a Standalone Executable
127-
####Then you will need to put these files in the same directory with the .exe:
128135

129-
- onnxruntime.dll
130-
- onnxruntime_providers_cuda.dll
131-
- onnxruntime_providers_shared.dll
132-
- onnxruntime_providers_tensorrt.dll
133-
- dnn_model_2_0_op11.onnx
134-
- dnn_model_2_0_lite_op11.onnx
135-
- cudnn64_8.dll
136-
- cudnn_cnn_infer64_8.dll
137-
- cudnn_ops_infer64_8.dll
138-
- cudart64_110.dll
139-
- cublas64_11.dll
140-
- cublasLt64_11.dll
141-
- cufft64_10.dll
142-
- directml.dll
136+
### Finally if you Build a Standalone Executable:
137+
138+
You will need to put [required DLLs for ONNX Runtime execution](https://docs.microsoft.com/en-us/azure/kinect-dk/body-sdk-setup#required-dlls-for-onnx-runtime-execution-environments) in the same directory with the .exe:
139+
140+
You can copy ONNXRuntime and DirectML files from nuget package by hand or from sample_unity_bodytracking directory after running **the batch file MoveLibraryFile.bat** (Step #3)
141+
142+
For the CUDA/cuDNN/TensorRT DLLs (Step #4) you can either have them in the PATH environment variable or copy required set of DLLs from the installation locations:
143143

144+
e.g.
145+
* from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin for the CUDA files.
146+
* from C:\Program Files\NVIDIA GPU Computing Toolkit\cuda-8.2.2.6\bin for the cuDNN files.
147+
* from C:\Program Files\NVIDIA GPU Computing Toolkit\TensorRT-8.2.1.8\lib for the TensorRT files.

body-tracking-samples/sample_unity_bodytracking/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="Microsoft.Azure.Kinect.BodyTracking" version="1.1.2" targetFramework="net471" />
4+
<package id="Microsoft.Azure.Kinect.BodyTracking.ONNXRuntime" version="1.10.0" targetFramework="net471" />
35
<package id="Microsoft.Azure.Kinect.Sensor" version="1.4.1" targetFramework="net471" />
46
<package id="System.Buffers" version="4.4.0" targetFramework="net471" />
57
<package id="System.Memory" version="4.5.3" targetFramework="net471" />

0 commit comments

Comments
 (0)