Skip to content

Commit

Permalink
Minor polishings
Browse files Browse the repository at this point in the history
  • Loading branch information
bibigone committed Oct 16, 2019
1 parent 29dde32 commit 119e37a
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 54 deletions.
2 changes: 1 addition & 1 deletion K4AdotNet.Samples.Unity/Assets/Scripts/CaptureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void Awake()
ColorResolution = ColorResolution.R720p,
ColorFormat = ImageFormat.ColorBgra32,
DepthMode = DepthMode.NarrowViewUnbinned,
CameraFps = FrameRate.Fifteen,
CameraFps = FrameRate.Thirty,
};
_device.GetCalibration(Configuration.DepthMode, Configuration.ColorResolution, out var calibration);
Calibration = calibration;
Expand Down
4 changes: 2 additions & 2 deletions K4AdotNet.Samples.Unity/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.2.0f1
m_EditorVersionWithRevision: 2019.2.0f1 (20c1667945cf)
m_EditorVersion: 2019.2.6f1
m_EditorVersionWithRevision: 2019.2.6f1 (fe82a0e88406)
13 changes: 8 additions & 5 deletions K4AdotNet.Samples.Unity/prepare.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ rem You may run it again anytime to update binaries with changes made to K4AdotN
rem Build fresh K4AdotNet binaries (requires path to msbuild.exe set by Developer Command Prompt)
msbuild ..\K4AdotNet -p:Configuration=Debug

rem Copy K4AdotNet binaries to a plugin folder
rem Copy K4AdotNet binaries to "Assets\Plugins\K4AdotNet" folder
xcopy ..\K4AdotNet\bin\Debug\netstandard2.0\* Assets\Plugins\K4AdotNet\ /A /Y

rem Copy K4A Sensor runtime to a plugin folder
rem Copy K4A Sensor runtime to "Assets\Plugins\K4AdotNet" folder
xcopy ..\externals\k4a\windows-desktop\amd64\*.dll Assets\Plugins\K4AdotNet\ /A /Y

rem Copy K4A Body Tracking runtime to a plugin folder (assumes Body Tracking SDK installed into a standard location)
rem If installed to another location then copy k4abt.dll manually
copy /y "C:\Program Files\Azure Kinect Body Tracking SDK\sdk\windows-desktop\amd64\release\bin\k4abt.dll" Assets\Plugins\K4AdotNet\
rem Copy k4abt.dll from K4A Body Tracking runtime to "Assets\Plugins\K4AdotNet" folder (assumes Body Tracking SDK installed into a standard location)
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\k4abt.dll" Assets\Plugins\K4AdotNet\

rem If Body Tracking SDK is installed to another location or you want to have portable solution which does not require installation of Body Tracking SDK
rem then copy manually the following libraries and data files from "tools" folder of Body Tracking SDK to "Assets\Plugins\K4AdotNet" folder of this plugin:
rem k4abt.dll, dnn_model_2_0.onnx, cudnn64_7.dll, cublas64_100.dll, cudart64_100.dll, vcomp140.dll.
41 changes: 41 additions & 0 deletions K4AdotNet.Samples.Unity/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Unity Sample

This sample demonstrate how to work with Sensor and Body data streams from Unity
and how to animate 3D character using body data.

## Preparations

Before first opening a Unity project, run `prepare.cmd` from **VS Developer Command Prompt**.
It will build **K4AdotNet** project and copy necessary binaries to Unity project folders.
You may run the script anytime later to update binaries with changes made to **K4AdotNet** library.

The script assumes that **Azure Kinect Body Tracking SDK** is installed into default location under Program Files.
If it doesn't take place or you want to have portable solution which doesn't depend on presence of Body Tracking SDK on local machine
then copy the following files from `tools` folder of Body Tracking SDK to `Assets\Plugins\K4AdotNet` folder of this plugin:
* `k4abt.dll`,
* `dnn_model_2_0.onnx`,
* `cudnn64_7.dll`,
* `cublas64_100.dll`,
* `cudart64_100.dll`,
* `vcomp140.dll`.

## Dependencies

This plugin depends on the following managed and native libraries and data files:
* **K4AdotNet** managed library (see `..\K4AdotNet\bin\Debug\netstandard2.0` or ``..\K4AdotNet\bin\Release\netstandard2.0`` folder):
* `K4AdotNet.dll`
* `K4AdotNet.deps.json`
* native libraries from **Azure Kinect Sensor SDK 1.3.0** (see `..\externals\k4a\windows-desktop\amd64` folder):
* `depthengine_2_0.dll`
* `k4a.dll`
* `k4arecord.dll`
* native libraries and ONNX-file from **Azure Kinect Body Tracking SDK 0.9.4** (you can download and install MSI package from [here](https://docs.microsoft.com/en-us/azure/kinect-dk/body-sdk-download) and find required files in `tools` subdirectory of installation destination directory):
* `k4abt.dll`,
* `dnn_model_2_0.onnx`,
* `cudnn64_7.dll`,
* `cublas64_100.dll`,
* `cudart64_100.dll`,
* `vcomp140.dll`.

As a rule `prepare.cmd` does the trick, but you can copy all dependencies to `Assets\Plugins\K4AdotNet` folder of this plugin manually.

7 changes: 0 additions & 7 deletions K4AdotNet.Samples.Unity/readme.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public void Dispose()

depthImage.Dispose();
needUpdateBitmap.Dispose();

transformation.Dispose();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

namespace K4AdotNet.Samples.Wpf.BackgroundRemover
{
/// <summary>
/// Interaction logic for ProcessingWindow.xaml
/// </summary>
public partial class ProcessingWindow : Window
{
public ProcessingWindow()
Expand Down
3 changes: 0 additions & 3 deletions K4AdotNet.Samples.Wpf.BackgroundRemover/StartWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace K4AdotNet.Samples.Wpf.BackgroundRemover
{
/// <summary>
/// Interaction logic for StartWindow.xaml
/// </summary>
public partial class StartWindow : Window
{
public StartWindow()
Expand Down
6 changes: 0 additions & 6 deletions K4AdotNet.Samples.Wpf.BodyTracker/SkeletonVisualizer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using K4AdotNet.BodyTracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Media;
Expand All @@ -20,8 +18,6 @@ public SkeletonVisualizer(Dispatcher dispatcher, int widthPixels, int heightPixe
}

this.dispatcher = dispatcher;
this.widthPixels = widthPixels;
this.heightPixels = heightPixels;
this.jointToImageProjector = jointToImageProjector;

// WPF stuff to draw skeleton
Expand Down Expand Up @@ -160,8 +156,6 @@ private Brush JointConfidenceLevelToToBrush(JointConfidenceLevel confidenceLevel
}

private readonly Dispatcher dispatcher;
private readonly int widthPixels;
private readonly int heightPixels;
private readonly Func<Joint, Float2?> jointToImageProjector;
private readonly Rect drawingRect;
private readonly DrawingGroup drawingGroup;
Expand Down
6 changes: 3 additions & 3 deletions K4AdotNet.Samples.Wpf.Common/ActualFpsCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public sealed class ActualFpsCalculator
/// <param name="periodCountForAveraging">Count of refresh periods that is used to calculate FPS. Default value is <c>5</c>.</param>
/// <param name="smoothCoeff">Smoothing coefficient. Default value is <c>0f</c>, which means no smoothing. Value must be in range [0; 1).</param>
public ActualFpsCalculator(
TimeSpan refreshPeriod = default(TimeSpan),
int periodCountForAveraging = default(int),
float smoothCoeff = default(float))
TimeSpan refreshPeriod = default,
int periodCountForAveraging = default,
float smoothCoeff = default)
{
// default values
if (refreshPeriod <= TimeSpan.Zero)
Expand Down
11 changes: 0 additions & 11 deletions K4AdotNet.Samples.Wpf.Viewer/ViewerWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace K4AdotNet.Samples.Wpf.Viewer
{
Expand Down
2 changes: 1 addition & 1 deletion K4AdotNet.Tests.Unit/Sensor/CaptureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void TestObjectDisposedException()
{
var capture = new Capture();
capture.Dispose();
var tmp = capture.TemperatureC; // <- ObjectDisposedException
_ = capture.TemperatureC; // <- ObjectDisposedException
}

[TestMethod]
Expand Down
6 changes: 3 additions & 3 deletions K4AdotNet.Tests.Unit/Sensor/ImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void TestArrayUnpinningOnDispose()
// Force collecting of array
GC.Collect();

Assert.IsFalse(weakReferenceToArray.TryGetTarget(out var notUsed));
Assert.IsFalse(weakReferenceToArray.TryGetTarget(out _));

// Nothing bad if we call dispose second time
image.Dispose();
Expand All @@ -181,7 +181,7 @@ public void TestObjectDisposedException()
{
var image = new Image(ImageFormat.Depth16, testWidth, testHeight);
image.Dispose();
var buffer = image.Buffer; // <- ObjectDisposedException
_ = image.Buffer; // <- ObjectDisposedException
}

#endregion
Expand Down Expand Up @@ -260,7 +260,7 @@ public void TestDuplicateReference()
GC.Collect();

// But array is still alive because refImage keeps it
Assert.IsTrue(weakReferenceToArray.TryGetTarget(out var notUsed));
Assert.IsTrue(weakReferenceToArray.TryGetTarget(out _));

refImage.Dispose();
}
Expand Down
6 changes: 3 additions & 3 deletions K4AdotNet/BodyTracking/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public sealed class Tracker : IDisposablePlus
/// </exception>
/// <seealso cref="Sdk.IsBodyTrackingRuntimeAvailable(out string)"/>
/// <seealso cref="Sdk.TryInitializeBodyTrackingRuntime(out string)"/>
public Tracker(ref Calibration calibration, TrackerConfiguration config = default(TrackerConfiguration))
public Tracker(ref Calibration calibration, TrackerConfiguration config = default)
{
if (!calibration.DepthMode.HasDepth())
throw new ArgumentOutOfRangeException(nameof(calibration) + "." + nameof(calibration.DepthMode));
Expand Down Expand Up @@ -180,7 +180,7 @@ public float TemporalSmoothingFactor
/// <exception cref="ArgumentException"><paramref name="capture"/> doesn't contain depth data compatible with <see cref="DepthMode"/>.</exception>
/// <exception cref="ObjectDisposedException">Object was disposed before this call or has been disposed during this call.</exception>
/// <exception cref="BodyTrackingException">Cannot add capture to the tracker for some unknown reason. See logs for details.</exception>
public bool TryEnqueueCapture(Capture capture, Timeout timeout = default(Timeout))
public bool TryEnqueueCapture(Capture capture, Timeout timeout = default)
{
if (capture == null)
throw new ArgumentNullException(nameof(capture));
Expand Down Expand Up @@ -252,7 +252,7 @@ public void EnqueueCapture(Capture capture)
/// <exception cref="ObjectDisposedException">Object was disposed before this call or has been disposed during this call.</exception>
/// <exception cref="BodyTrackingException">Cannot get body frame for some unknown reason. See logs for details.</exception>
/// <seealso cref="PopResult"/>
public bool TryPopResult(out BodyFrame bodyFrame, Timeout timeout = default(Timeout))
public bool TryPopResult(out BodyFrame bodyFrame, Timeout timeout = default)
{
var res = NativeApi.TrackerPopResult(handle.ValueNotDisposed, out var bodyFrameHandle, timeout);
if (res == NativeCallResults.WaitResult.Timeout)
Expand Down
36 changes: 36 additions & 0 deletions K4AdotNet/K4AdotNet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@
<member name="F:K4AdotNet.BodyTracking.JointType.WristLeft">
<summary>Left wrist joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.HandLeft">
<summary>Left hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.HandTipLeft">
<summary>Tip of left hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.ThumbLeft">
<summary>Left thumb joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.ClavicleRight">
<summary>Right clavicle joint.</summary>
</member>
Expand All @@ -334,6 +343,15 @@
<member name="F:K4AdotNet.BodyTracking.JointType.WristRight">
<summary>Right wrist joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.HandRight">
<summary>Right hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.HandTipRight">
<summary>Tip of right hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.ThumbRight">
<summary>Right thumb joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.JointType.HipLeft">
<summary>Left hip joint.</summary>
</member>
Expand Down Expand Up @@ -623,6 +641,15 @@
<member name="F:K4AdotNet.BodyTracking.Skeleton.WristLeft">
<summary>Left wrist joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.HandLeft">
<summary>Left hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.HandTipLeft">
<summary>Tip of left hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.ThumbLeft">
<summary>Left thumb joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.ClavicleRight">
<summary>Right clavicle joint.</summary>
</member>
Expand All @@ -635,6 +662,15 @@
<member name="F:K4AdotNet.BodyTracking.Skeleton.WristRight">
<summary>Right wrist joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.HandRight">
<summary>Right hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.HandTipRight">
<summary>Tip of right hand joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.ThumbRight">
<summary>Right thumb joint.</summary>
</member>
<member name="F:K4AdotNet.BodyTracking.Skeleton.HipLeft">
<summary>Left hip joint.</summary>
</member>
Expand Down
2 changes: 1 addition & 1 deletion K4AdotNet/Sensor/Calibration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void CreateDummy(DepthMode depthMode, ColorResolution colorResolut
if (depthMode == DepthMode.Off && colorResolution == ColorResolution.Off)
throw new ArgumentOutOfRangeException(nameof(depthMode) + " and " + nameof(colorResolution), $"{nameof(depthMode)} and {nameof(colorResolution)} cannot be equal to Off simultaneously.");

calibration = default(Calibration);
calibration = default;

// depth camera
calibration.DepthMode = depthMode;
Expand Down
10 changes: 5 additions & 5 deletions K4AdotNet/Sensor/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Dispose()
/// <seealso cref="DeviceConnectionLostException"/>
public bool IsConnected
=> !handle.IsDisposed
&& NativeApi.DeviceGetSyncJack(handle.Value, out var notUsed1, out var notUsed2) == NativeCallResults.Result.Succeeded;
&& NativeApi.DeviceGetSyncJack(handle.Value, out _, out _) == NativeCallResults.Result.Succeeded;

/// <summary>Gets the device jack status for the synchronization in connectors.</summary>
/// <remarks>
Expand All @@ -80,7 +80,7 @@ public bool IsSyncInConnected
{
get
{
CheckResult(NativeApi.DeviceGetSyncJack(handle.ValueNotDisposed, out var syncInConnected, out var syncOutConnected));
CheckResult(NativeApi.DeviceGetSyncJack(handle.ValueNotDisposed, out var syncInConnected, out _));
return syncInConnected;
}
}
Expand All @@ -100,7 +100,7 @@ public bool IsSyncOutConnected
{
get
{
CheckResult(NativeApi.DeviceGetSyncJack(handle.ValueNotDisposed, out var syncInConnected, out var syncOutConnected));
CheckResult(NativeApi.DeviceGetSyncJack(handle.ValueNotDisposed, out _, out var syncOutConnected));
return syncOutConnected;
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ public void StopImu()
/// <exception cref="ObjectDisposedException">This method cannot be called for disposed object.</exception>
/// <exception cref="DeviceConnectionLostException">Connection with Azure Kinect device has been lost.</exception>
/// <exception cref="InvalidOperationException">Camera streaming is not running or has been stopped during this call.</exception>
public bool TryGetCapture(out Capture capture, Timeout timeout = default(Timeout))
public bool TryGetCapture(out Capture capture, Timeout timeout = default)
{
var res = NativeApi.DeviceGetCapture(handle.ValueNotDisposed, out var captureHandle, timeout);

Expand Down Expand Up @@ -248,7 +248,7 @@ public Capture GetCapture()
/// <exception cref="ObjectDisposedException">This method cannot be called for disposed object.</exception>
/// <exception cref="DeviceConnectionLostException">Connection with Azure Kinect device has been lost.</exception>
/// <exception cref="InvalidOperationException">IMU streaming is not running or has been stopped during this call.</exception>
public bool TryGetImuSample(out ImuSample imuSample, Timeout timeout = default(Timeout))
public bool TryGetImuSample(out ImuSample imuSample, Timeout timeout = default)
{
var res = NativeApi.DeviceGetImuSample(handle.ValueNotDisposed, out imuSample, timeout);

Expand Down

0 comments on commit 119e37a

Please sign in to comment.