Skip to content

Commit

Permalink
Minor fixes based on testing, preparations to release version 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bibigone committed May 28, 2020
1 parent e23af7c commit ee822ce
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\Product.props" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ private IEnumerator Start()
yield return new WaitUntil(() => skeletonProvider?.IsInitializationComplete != false);
if (skeletonProvider?.IsAvailable != true)
{
_errorMessage.Show("Cannot initialize Azure Kinect Body Tracking runtime");
_errorMessage.Show(
"Cannot initialize Azure Kinect Body Tracking runtime.\n" +
"Make sure that there are the following files in Assets\\Plugins\\K4AdotNet folder:\n" +
"1. k4abt.dll\n2. dnn_model_2_0.onnx\n3. cudnn64_7.dll\n4. cublas64_100.dll\n5. cudart64_100.dll\n6. onnxruntime.dll\n7. vcomp140.dll");
yield break;
}

Expand Down
8 changes: 7 additions & 1 deletion K4AdotNet.Samples.Unity/prepare.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ xcopy ..\externals\k4a\windows-desktop\amd64\*.dll Assets\Plugins\K4AdotNet\ /A

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\
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\dnn_model_2_0.onnx" Assets\Plugins\K4AdotNet\
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\cudnn64_7.dll" Assets\Plugins\K4AdotNet\
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\cublas64_100.dll" Assets\Plugins\K4AdotNet\
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\cudart64_100.dll" Assets\Plugins\K4AdotNet\
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\onnxruntime.dll" Assets\Plugins\K4AdotNet\
copy /y "%ProgramFiles%\Azure Kinect Body Tracking SDK\tools\vcomp140.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.
rem k4abt.dll, dnn_model_2_0.onnx, cudnn64_7.dll, cublas64_100.dll, cudart64_100.dll, onnxruntime.dll, vcomp140.dll.
42 changes: 28 additions & 14 deletions K4AdotNet/K4AdotNet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5908,12 +5908,9 @@
<param name="format">Format of image. Cannot be <see cref="F:K4AdotNet.Sensor.ImageFormat.ColorMjpg"/>.</param>
<param name="widthPixels">Width of image in pixels. Must be positive.</param>
<param name="heightPixels">Height of image in pixels. Must be positive.</param>
<param name="strideBytes">
Image stride in bytes (the number of bytes per horizontal line of the image). Must be non negative.
If set to 0, the stride will be set to the minimum size given the <paramref name="format"/> and <paramref name="widthPixels"/>.
</param>
<param name="strideBytes">Image stride in bytes (the number of bytes per horizontal line of the image). Must be positive.</param>
<remarks>
Don't use this method to create image with unknown/unspecified stride (like MJPEG).
Don't use this method to create image with unknown/unspecified stride (like <see cref="F:K4AdotNet.Sensor.ImageFormat.ColorMjpg"/> and <see cref="F:K4AdotNet.Sensor.ImageFormat.Custom"/>).
For such formats, size of image in bytes must be specified to create image: <see cref="M:K4AdotNet.Sensor.Image.#ctor(K4AdotNet.Sensor.ImageFormat,System.Int32,System.Int32,System.Int32,System.Int32)"/>.
</remarks>
<exception cref="T:System.ArgumentOutOfRangeException">
Expand All @@ -5929,29 +5926,46 @@
<param name="format">Format of image.</param>
<param name="widthPixels">Width of image in pixels. Must be positive.</param>
<param name="heightPixels">Height of image in pixels. Must be positive.</param>
<param name="strideBytes">
Image stride in bytes (the number of bytes per horizontal line of the image). Must be non negative.
If set to 0, the stride will be set to the minimum size given the <paramref name="format"/> and <paramref name="widthPixels"/>.
</param>
<param name="strideBytes">Image stride in bytes (the number of bytes per horizontal line of the image). Must be non-negative. Zero value can be used for <see cref="F:K4AdotNet.Sensor.ImageFormat.ColorMjpg"/> and <see cref="F:K4AdotNet.Sensor.ImageFormat.Custom"/>.</param>
<param name="sizeBytes">Size of image buffer in size. Non negative. Cannot be less than size calculated from image parameters.</param>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="widthPixels"/> or <paramref name="heightPixels"/> is equal to or less than zero
or <paramref name="strideBytes"/> is less than zero or <paramref name="strideBytes"/> is too small for specified <paramref name="format"/>
or <paramref name="sizeBytes"/> is less than zero or <paramref name="sizeBytes"/> is less than size calculated from <paramref name="heightPixels"/> and <paramref name="strideBytes"/>.
</exception>
</member>
<member name="M:K4AdotNet.Sensor.Image.CreateFromArray``1(``0[],K4AdotNet.Sensor.ImageFormat,System.Int32,System.Int32)">
<summary>Creates new image for specified underlying buffer with specified format and size in pixels.</summary>
<typeparam name="T">Type of array elements in underlying buffer. Must be value type.</typeparam>
<param name="buffer">Underlying buffer for image. Cannot be <see langword="null"/>. Object will pin and keep reference to this array during all lifetime.</param>
<param name="format">Format of image. Must be format with known stride: <see cref="M:K4AdotNet.Sensor.ImageFormats.StrideBytes(K4AdotNet.Sensor.ImageFormat,System.Int32)"/>.</param>
<param name="widthPixels">Width of image in pixels. Must be positive.</param>
<param name="heightPixels">Height of image in pixels. Must be positive.</param>
<returns>Created image. Not <see langword="null"/>.</returns>
<remarks><para>
This version of method can be used only for <paramref name="format"/> with known dependency between image width in pixels and stride in bytes
and cannot be used for other formats. For details see <see cref="M:K4AdotNet.Sensor.ImageFormats.StrideBytes(K4AdotNet.Sensor.ImageFormat,System.Int32)"/>.
For other formats use <see cref="M:K4AdotNet.Sensor.Image.CreateFromArray``1(``0[],K4AdotNet.Sensor.ImageFormat,System.Int32,System.Int32,System.Int32)"/>.
</para><para>
<see cref="P:K4AdotNet.Sensor.Image.Buffer"/> points to pinned array <paramref name="buffer"/> for such images.
</para></remarks>
<exception cref="T:System.ArgumentOutOfRangeException">
<paramref name="widthPixels"/> or <paramref name="heightPixels"/> is equal to or less than zero
or <paramref name="buffer"/> array is too small for specified image parameters.
</exception>
<exception cref="T:System.ArgumentException">
Image stride in bytes cannot be automatically calculated from <paramref name="widthPixels"/> for specified <paramref name="format"/>.
</exception>
<seealso cref="M:K4AdotNet.Sensor.ImageFormats.StrideBytes(K4AdotNet.Sensor.ImageFormat,System.Int32)"/>
</member>
<member name="M:K4AdotNet.Sensor.Image.CreateFromArray``1(``0[],K4AdotNet.Sensor.ImageFormat,System.Int32,System.Int32,System.Int32)">
<summary>Creates new image for specified underlying buffer with specified format and size in pixels.</summary>
<typeparam name="T">Type of array elements in underlying buffer. Must be value type.</typeparam>
<param name="buffer">Underlying buffer for image. Cannot be <see langword="null"/>. Object will pin and keep reference to this array during all lifetime.</param>
<param name="format">Format of image.</param>
<param name="widthPixels">Width of image in pixels. Must be positive.</param>
<param name="heightPixels">Height of image in pixels. Must be positive.</param>
<param name="strideBytes">
Image stride in bytes (the number of bytes per horizontal line of the image). Must be non-negative.
If set to 0, the stride will be set to the minimum size given the <paramref name="format"/> and <paramref name="widthPixels"/>.
</param>
<returns>Created image. Not <see langword="null"/>.</returns>
<param name="strideBytes">Image stride in bytes (the number of bytes per horizontal line of the image). Must be non-negative. Zero value can be used for <see cref="F:K4AdotNet.Sensor.ImageFormat.ColorMjpg"/> and <see cref="F:K4AdotNet.Sensor.ImageFormat.Custom"/>.</param> /// <returns>Created image. Not <see langword="null"/>.</returns>
<remarks><para>
<see cref="P:K4AdotNet.Sensor.Image.Buffer"/> points to pinned array <paramref name="buffer"/> for such images.
</para></remarks>
Expand Down
55 changes: 35 additions & 20 deletions K4AdotNet/Sensor/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ public Image(ImageFormat format, int widthPixels, int heightPixels)
/// <param name="format">Format of image. Cannot be <see cref="ImageFormat.ColorMjpg"/>.</param>
/// <param name="widthPixels">Width of image in pixels. Must be positive.</param>
/// <param name="heightPixels">Height of image in pixels. Must be positive.</param>
/// <param name="strideBytes">
/// Image stride in bytes (the number of bytes per horizontal line of the image). Must be non negative.
/// If set to 0, the stride will be set to the minimum size given the <paramref name="format"/> and <paramref name="widthPixels"/>.
/// </param>
/// <param name="strideBytes">Image stride in bytes (the number of bytes per horizontal line of the image). Must be positive.</param>
/// <remarks>
/// Don't use this method to create image with unknown/unspecified stride (like MJPEG).
/// Don't use this method to create image with unknown/unspecified stride (like <see cref="ImageFormat.ColorMjpg"/> and <see cref="ImageFormat.Custom"/>).
/// For such formats, size of image in bytes must be specified to create image: <see cref="Image(ImageFormat, int, int, int, int)"/>.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException">
Expand All @@ -70,12 +67,11 @@ public Image(ImageFormat format, int widthPixels, int heightPixels, int strideBy
throw new ArgumentOutOfRangeException(nameof(heightPixels));
if (strideBytes < 0)
throw new ArgumentOutOfRangeException(nameof(strideBytes));
if (strideBytes == 0)
throw new InvalidOperationException("Zero stride is used for formats with complex structure like MJPEG. In this case size of image in bytes must be specified to create image.");
if (format.HasKnownBytesPerPixel() && strideBytes < widthPixels * format.BytesPerPixel())
throw new ArgumentOutOfRangeException(nameof(strideBytes));

if (strideBytes == 0 && (format == ImageFormat.ColorMjpg || format == ImageFormat.Custom))
throw new InvalidOperationException($"Size of image in bytes must be specified to create {format} image.");

var res = NativeApi.ImageCreate(format, widthPixels, heightPixels, strideBytes, out var handle);
if (res != NativeCallResults.Result.Succeeded || handle == null || handle.IsInvalid)
throw new ArgumentException($"Cannot create image with format {format}, size {widthPixels}x{heightPixels} pixels and stride {strideBytes} bytes.");
Expand All @@ -88,10 +84,7 @@ public Image(ImageFormat format, int widthPixels, int heightPixels, int strideBy
/// <param name="format">Format of image.</param>
/// <param name="widthPixels">Width of image in pixels. Must be positive.</param>
/// <param name="heightPixels">Height of image in pixels. Must be positive.</param>
/// <param name="strideBytes">
/// Image stride in bytes (the number of bytes per horizontal line of the image). Must be non negative.
/// If set to 0, the stride will be set to the minimum size given the <paramref name="format"/> and <paramref name="widthPixels"/>.
/// </param>
/// <param name="strideBytes">Image stride in bytes (the number of bytes per horizontal line of the image). Must be non-negative. Zero value can be used for <see cref="ImageFormat.ColorMjpg"/> and <see cref="ImageFormat.Custom"/>.</param>
/// <param name="sizeBytes">Size of image buffer in size. Non negative. Cannot be less than size calculated from image parameters.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="widthPixels"/> or <paramref name="heightPixels"/> is equal to or less than zero
Expand All @@ -106,7 +99,7 @@ public Image(ImageFormat format, int widthPixels, int heightPixels, int strideBy
throw new ArgumentOutOfRangeException(nameof(heightPixels));
if (strideBytes < 0)
throw new ArgumentOutOfRangeException(nameof(strideBytes));
if (format.HasKnownBytesPerPixel() && strideBytes > 0 && strideBytes < widthPixels * format.BytesPerPixel())
if (format.HasKnownBytesPerPixel() && strideBytes < widthPixels * format.BytesPerPixel())
throw new ArgumentOutOfRangeException(nameof(strideBytes));
if (sizeBytes <= 0)
throw new ArgumentOutOfRangeException(nameof(sizeBytes));
Expand All @@ -130,23 +123,45 @@ public Image(ImageFormat format, int widthPixels, int heightPixels, int strideBy
/// <summary>Creates new image for specified underlying buffer with specified format and size in pixels.</summary>
/// <typeparam name="T">Type of array elements in underlying buffer. Must be value type.</typeparam>
/// <param name="buffer">Underlying buffer for image. Cannot be <see langword="null"/>. Object will pin and keep reference to this array during all lifetime.</param>
/// <param name="format">Format of image.</param>
/// <param name="format">Format of image. Must be format with known stride: <see cref="ImageFormats.StrideBytes(ImageFormat, int)"/>.</param>
/// <param name="widthPixels">Width of image in pixels. Must be positive.</param>
/// <param name="heightPixels">Height of image in pixels. Must be positive.</param>
/// <param name="strideBytes">
/// Image stride in bytes (the number of bytes per horizontal line of the image). Must be non-negative.
/// If set to 0, the stride will be set to the minimum size given the <paramref name="format"/> and <paramref name="widthPixels"/>.
/// </param>
/// <returns>Created image. Not <see langword="null"/>.</returns>
/// <remarks><para>
/// This version of method can be used only for <paramref name="format"/> with known dependency between image width in pixels and stride in bytes
/// and cannot be used for other formats. For details see <see cref="ImageFormats.StrideBytes(ImageFormat, int)"/>.
/// For other formats use <see cref="CreateFromArray{T}(T[], ImageFormat, int, int, int)"/>.
/// </para><para>
/// <see cref="Buffer"/> points to pinned array <paramref name="buffer"/> for such images.
/// </para></remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="widthPixels"/> or <paramref name="heightPixels"/> is equal to or less than zero
/// or <paramref name="buffer"/> array is too small for specified image parameters.
/// </exception>
/// <exception cref="ArgumentException">
/// Image stride in bytes cannot be automatically calculated from <paramref name="widthPixels"/> for specified <paramref name="format"/>.
/// </exception>
/// <seealso cref="ImageFormats.StrideBytes(ImageFormat, int)"/>
public static Image CreateFromArray<T>(T[] buffer, ImageFormat format, int widthPixels, int heightPixels)
where T : struct
=> CreateFromArray(buffer, format, widthPixels, heightPixels, format.StrideBytes(widthPixels));

/// <summary>Creates new image for specified underlying buffer with specified format and size in pixels.</summary>
/// <typeparam name="T">Type of array elements in underlying buffer. Must be value type.</typeparam>
/// <param name="buffer">Underlying buffer for image. Cannot be <see langword="null"/>. Object will pin and keep reference to this array during all lifetime.</param>
/// <param name="format">Format of image.</param>
/// <param name="widthPixels">Width of image in pixels. Must be positive.</param>
/// <param name="heightPixels">Height of image in pixels. Must be positive.</param>
/// <param name="strideBytes">Image stride in bytes (the number of bytes per horizontal line of the image). Must be non-negative. Zero value can be used for <see cref="ImageFormat.ColorMjpg"/> and <see cref="ImageFormat.Custom"/>.</param> /// <returns>Created image. Not <see langword="null"/>.</returns>
/// <remarks><para>
/// <see cref="Buffer"/> points to pinned array <paramref name="buffer"/> for such images.
/// </para></remarks>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="widthPixels"/> or <paramref name="heightPixels"/> is equal to or less than zero
/// or <paramref name="strideBytes"/> is less than zero or <paramref name="strideBytes"/> is too small for specified <paramref name="format"/>
/// or <paramref name="buffer"/> array is too small for specified image parameters.
/// </exception>
public static Image CreateFromArray<T>(T[] buffer, ImageFormat format, int widthPixels, int heightPixels, int strideBytes = 0)
public static Image CreateFromArray<T>(T[] buffer, ImageFormat format, int widthPixels, int heightPixels, int strideBytes)
where T: struct
{
if (buffer == null)
Expand All @@ -157,7 +172,7 @@ public static Image CreateFromArray<T>(T[] buffer, ImageFormat format, int width
throw new ArgumentOutOfRangeException(nameof(heightPixels));
if (strideBytes < 0)
throw new ArgumentOutOfRangeException(nameof(strideBytes));
if (format.HasKnownBytesPerPixel() && strideBytes > 0 && strideBytes < widthPixels * format.BytesPerPixel())
if (format.HasKnownBytesPerPixel() && strideBytes < widthPixels * format.BytesPerPixel())
throw new ArgumentOutOfRangeException(nameof(strideBytes));
var sizeBytes = buffer.Length * Marshal.SizeOf<T>();
if (strideBytes > 0 && sizeBytes < format.ImageSizeBytes(strideBytes, heightPixels))
Expand Down
4 changes: 2 additions & 2 deletions Product.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>1.3.5</Version>
<AssemblyVersion>1.3.5.0</AssemblyVersion>
<Version>1.4.0</Version>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<PackageReleaseNotes>See https://github.com/bibigone/k4a.net/releases </PackageReleaseNotes>
<Authors>bibigone,baSSiLL</Authors>
<Company />
Expand Down
4 changes: 2 additions & 2 deletions ProductInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.3.5.0")]
[assembly: AssemblyFileVersion("1.3.5.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]

0 comments on commit ee822ce

Please sign in to comment.