From e8aa50c1161e8b8746a335b2691f4174b20086f8 Mon Sep 17 00:00:00 2001 From: Andrew B Date: Wed, 19 May 2021 15:59:49 +0300 Subject: [PATCH] Minor polishing of checks in Transformation class to allow "rotated" versions of calibration data --- K4AdotNet/K4AdotNet.xml | 29 +++++++------ K4AdotNet/Sensor/Transformation.cs | 68 +++++++++++++++--------------- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/K4AdotNet/K4AdotNet.xml b/K4AdotNet/K4AdotNet.xml index dca2218..e6a7e69 100644 --- a/K4AdotNet/K4AdotNet.xml +++ b/K4AdotNet/K4AdotNet.xml @@ -7166,7 +7166,7 @@ Azure Kinect transformation functionality. Can be used to transform images and depth maps between cameras and to reproject depth map to 3D space. - It uses data for transformations. + It uses data for transformations. @@ -7198,6 +7198,9 @@ Raised on object disposing (only once). + + Calibration data for which this transformation was created. + Depth mode for which this transformation was created. @@ -7206,8 +7209,8 @@ Transforms the depth map into the geometry of the color camera. - Input depth map to be transformed. Not . Must have resolution of depth camera in mode. - Output depth image. Not . Must have resolution of color camera in resolution. + Input depth map to be transformed. Not . Must have resolution of depth camera. + Output depth image. Not . Must have resolution of color camera. This produces a depth image for which each pixel matches the corresponding pixel coordinates of the color camera. The contents will be filled with the depth values derived from in the color @@ -7220,10 +7223,10 @@ Transforms the depth map into the geometry of the color camera. - Input depth map to be transformed. Not . Must have resolution of depth camera in mode. - Input custom image to be transformed. In or format. Not . Must have resolution of depth camera in mode. - Output depth image. Not . Must have resolution of color camera in resolution. - Output custom image. Not . Must have resolution of color camera in resolution and be of the same format as . + Input depth map to be transformed. Not . Must have resolution of depth camera. + Input custom image to be transformed. In or format. Not . Must have resolution of depth camera. + Output depth image. Not . Must have resolution of color camera. + Output custom image. Not . Must have resolution of color camera and be of the same format as . Parameter that controls how pixels in should be interpolated when transformed to color camera space. if linear interpolation should be used. @@ -7267,9 +7270,9 @@ Transforms a color image into the geometry of the depth camera. - Input depth map. Not . Must have resolution of depth camera in mode. - Input color image to be transformed. Not . Must have resolution of color camera in resolution. - Output color image. Not . Must have resolution of depth camera in mode. + Input depth map. Not . Must have resolution of depth camera. + Input color image to be transformed. Not . Must have resolution of color camera. + Output color image. Not . Must have resolution of depth camera. This produces a color image for which each pixel matches the corresponding pixel coordinates of the depth camera. @@ -7288,7 +7291,7 @@ Transforms the depth image into 3 planar images representing X, Y and Z-coordinates of corresponding 3D points. - Input depth image to be transformed to point cloud. Not . Must have resolution of camera. + Input depth image to be transformed to point cloud. Not . Must have resolution. Geometry in which depth map was computed ( or ). Output XYZ image for point cloud data. Not . Must have resolution of camera. @@ -7686,7 +7689,9 @@ Special timeout value: infinite waiting. - + + +System.Diagnostics.CodeAnalysis.AllowNullAttribute"> Specifies that is allowed as an input even if the corresponding type disallows it. diff --git a/K4AdotNet/Sensor/Transformation.cs b/K4AdotNet/Sensor/Transformation.cs index fa47049..e30aac5 100644 --- a/K4AdotNet/Sensor/Transformation.cs +++ b/K4AdotNet/Sensor/Transformation.cs @@ -12,6 +12,7 @@ namespace K4AdotNet.Sensor public sealed class Transformation : IDisposablePlus { private readonly NativeHandles.HandleWrapper handle; + private readonly Calibration calibration; /// /// Creates transformation object for a give calibration data. @@ -37,8 +38,7 @@ public Transformation(in Calibration calibration) this.handle = handle; this.handle.Disposed += Handle_Disposed; - DepthMode = calibration.DepthMode; - ColorResolution = calibration.ColorResolution; + this.calibration = calibration; } private void Handle_Disposed(object sender, EventArgs e) @@ -63,15 +63,18 @@ public void Dispose() /// public event EventHandler? Disposed; + /// Calibration data for which this transformation was created. + public Calibration Calibration => calibration; + /// Depth mode for which this transformation was created. - public DepthMode DepthMode { get; } + public DepthMode DepthMode => calibration.DepthMode; /// Resolution of color camera for which this transformation was created. - public ColorResolution ColorResolution { get; } + public ColorResolution ColorResolution => calibration.ColorResolution; /// Transforms the depth map into the geometry of the color camera. - /// Input depth map to be transformed. Not . Must have resolution of depth camera in mode. - /// Output depth image. Not . Must have resolution of color camera in resolution. + /// Input depth map to be transformed. Not . Must have resolution of depth camera. + /// Output depth image. Not . Must have resolution of color camera. /// /// This produces a depth image for which each pixel matches the corresponding pixel coordinates of the color camera. /// The contents will be filled with the depth values derived from in the color @@ -83,8 +86,8 @@ public void Dispose() /// This method cannot be called for disposed object. public void DepthImageToColorCamera(Image depthImage, Image transformedDepthImage) { - CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, DepthMode); - CheckImageParameter(nameof(transformedDepthImage), transformedDepthImage, ImageFormat.Depth16, ColorResolution); + CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, calibration.DepthCameraCalibration); + CheckImageParameter(nameof(transformedDepthImage), transformedDepthImage, ImageFormat.Depth16, calibration.ColorCameraCalibration); var res = NativeApi.TransformationDepthImageToColorCamera(handle.ValueNotDisposed, Image.ToHandle(depthImage), Image.ToHandle(transformedDepthImage)); @@ -93,10 +96,10 @@ public void DepthImageToColorCamera(Image depthImage, Image transformedDepthImag } /// Transforms the depth map into the geometry of the color camera. - /// Input depth map to be transformed. Not . Must have resolution of depth camera in mode. - /// Input custom image to be transformed. In or format. Not . Must have resolution of depth camera in mode. - /// Output depth image. Not . Must have resolution of color camera in resolution. - /// Output custom image. Not . Must have resolution of color camera in resolution and be of the same format as . + /// Input depth map to be transformed. Not . Must have resolution of depth camera. + /// Input custom image to be transformed. In or format. Not . Must have resolution of depth camera. + /// Output depth image. Not . Must have resolution of color camera. + /// Output custom image. Not . Must have resolution of color camera and be of the same format as . /// /// Parameter that controls how pixels in should be interpolated when transformed to color camera space. /// if linear interpolation should be used. @@ -142,10 +145,10 @@ public void DepthImageToColorCameraCustom( Image transformedDepthImage, Image transformedCustomImage, TransformationInterpolation interpolation, int invalidCustomValue) { - CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, DepthMode); - CheckImageParameter(nameof(customImage), customImage, ImageFormat.Custom8, ImageFormat.Custom16, DepthMode); - CheckImageParameter(nameof(transformedDepthImage), transformedDepthImage, ImageFormat.Depth16, ColorResolution); - CheckImageParameter(nameof(transformedCustomImage), transformedCustomImage, customImage.Format, ColorResolution); + CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, calibration.DepthCameraCalibration); + CheckImageParameter(nameof(customImage), customImage, ImageFormat.Custom8, ImageFormat.Custom16, calibration.DepthCameraCalibration); + CheckImageParameter(nameof(transformedDepthImage), transformedDepthImage, ImageFormat.Depth16, calibration.ColorCameraCalibration); + CheckImageParameter(nameof(transformedCustomImage), transformedCustomImage, customImage.Format, calibration.ColorCameraCalibration); var res = NativeApi.TransformationDepthImageToColorCameraCustom(handle.ValueNotDisposed, Image.ToHandle(depthImage), Image.ToHandle(customImage), @@ -156,9 +159,9 @@ public void DepthImageToColorCameraCustom( } /// Transforms a color image into the geometry of the depth camera. - /// Input depth map. Not . Must have resolution of depth camera in mode. - /// Input color image to be transformed. Not . Must have resolution of color camera in resolution. - /// Output color image. Not . Must have resolution of depth camera in mode. + /// Input depth map. Not . Must have resolution of depth camera. + /// Input color image to be transformed. Not . Must have resolution of color camera. + /// Output color image. Not . Must have resolution of depth camera. /// /// This produces a color image for which each pixel matches the corresponding pixel coordinates of the depth camera. /// @@ -176,9 +179,9 @@ public void DepthImageToColorCameraCustom( /// This method cannot be called for disposed object. public void ColorImageToDepthCamera(Image depthImage, Image colorImage, Image transformedColorImage) { - CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, DepthMode); - CheckImageParameter(nameof(colorImage), colorImage, ImageFormat.ColorBgra32, ColorResolution); - CheckImageParameter(nameof(transformedColorImage), transformedColorImage, ImageFormat.ColorBgra32, DepthMode); + CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, calibration.DepthCameraCalibration); + CheckImageParameter(nameof(colorImage), colorImage, ImageFormat.ColorBgra32, calibration.ColorCameraCalibration); + CheckImageParameter(nameof(transformedColorImage), transformedColorImage, ImageFormat.ColorBgra32, calibration.DepthCameraCalibration); var res = NativeApi.TransformationColorImageToDepthCamera(handle.ValueNotDisposed, Image.ToHandle(depthImage), Image.ToHandle(colorImage), Image.ToHandle(transformedColorImage)); @@ -187,7 +190,7 @@ public void ColorImageToDepthCamera(Image depthImage, Image colorImage, Image tr } /// Transforms the depth image into 3 planar images representing X, Y and Z-coordinates of corresponding 3D points. - /// Input depth image to be transformed to point cloud. Not . Must have resolution of camera. + /// Input depth image to be transformed to point cloud. Not . Must have resolution. /// Geometry in which depth map was computed ( or ). /// Output XYZ image for point cloud data. Not . Must have resolution of camera. /// @@ -213,13 +216,13 @@ public void DepthImageToPointCloud(Image depthImage, CalibrationGeometry camera, { if (camera == CalibrationGeometry.Depth) { - CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, DepthMode); - CheckImageParameter(nameof(xyzImage), xyzImage, ImageFormat.Custom, DepthMode); + CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, calibration.DepthCameraCalibration); + CheckImageParameter(nameof(xyzImage), xyzImage, ImageFormat.Custom, calibration.DepthCameraCalibration); } else if (camera == CalibrationGeometry.Color) { - CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, ColorResolution); - CheckImageParameter(nameof(xyzImage), xyzImage, ImageFormat.Custom, ColorResolution); + CheckImageParameter(nameof(depthImage), depthImage, ImageFormat.Depth16, calibration.ColorCameraCalibration); + CheckImageParameter(nameof(xyzImage), xyzImage, ImageFormat.Custom, calibration.ColorCameraCalibration); } else { @@ -252,13 +255,10 @@ private static void CheckImageParameter(string paramName, Image paramValue, Imag private static string CombineExpectedFormatsForMessage(ImageFormat format1, ImageFormat format2) => format1 == format2 ? format1.ToString() : (format1.ToString() + " or " + format2.ToString()); - private static void CheckImageParameter(string paramName, Image paramValue, ImageFormat expectedFormat, DepthMode depthMode) - => CheckImageParameter(paramName, paramValue, expectedFormat, expectedFormat, depthMode.WidthPixels(), depthMode.HeightPixels()); - - private static void CheckImageParameter(string paramName, Image paramValue, ImageFormat expectedFormat1, ImageFormat expectedFormat2, DepthMode depthMode) - => CheckImageParameter(paramName, paramValue, expectedFormat1, expectedFormat2, depthMode.WidthPixels(), depthMode.HeightPixels()); + private static void CheckImageParameter(string paramName, Image paramValue, ImageFormat expectedFormat, CameraCalibration cameraCalibration) + => CheckImageParameter(paramName, paramValue, expectedFormat, expectedFormat, cameraCalibration.ResolutionWidth, cameraCalibration.ResolutionHeight); - private static void CheckImageParameter(string paramName, Image paramValue, ImageFormat expectedFormat, ColorResolution colorResolution) - => CheckImageParameter(paramName, paramValue, expectedFormat, expectedFormat, colorResolution.WidthPixels(), colorResolution.HeightPixels()); + private static void CheckImageParameter(string paramName, Image paramValue, ImageFormat expectedFormat1, ImageFormat expectedFormat2, CameraCalibration cameraCalibration) + => CheckImageParameter(paramName, paramValue, expectedFormat1, expectedFormat2, cameraCalibration.ResolutionWidth, cameraCalibration.ResolutionHeight); } }