Beispiel #1
0
        /// <summary>
        /// Reads an IMU sample from the device.
        /// </summary>
        /// <param name="timeout">Time to wait for an IMU sample.</param>
        /// <returns>The next unread IMU sample from the device.</returns>
        /// <remarks>Gets the next sample in the streamed sequence of IMU samples from the device.
        /// If a new sample is not currently available, this function will block until the timeout is reached.
        /// The API will buffer at least two camera capture intervals worth of samples before dropping the oldest sample. Callers needing to capture all data need to ensure they read the data as fast as the data is being produced on average.
        /// </remarks>
        public ImuSample GetImuSample(TimeSpan timeout)
        {
            lock (this)
            {
                if (this.disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                using (LoggingTracer tracer = new LoggingTracer())
                {
                    NativeMethods.k4a_imu_sample_t  sample = new NativeMethods.k4a_imu_sample_t();
                    NativeMethods.k4a_wait_result_t result = NativeMethods.k4a_device_get_imu_sample(this.handle, sample, (int)timeout.TotalMilliseconds);

                    if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_TIMEOUT)
                    {
                        throw new TimeoutException("Timed out waiting for IMU sample");
                    }

                    AzureKinectException.ThrowIfNotSuccess(tracer, result);

                    return(sample.ToImuSample());
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reads a sensor capture.
        /// </summary>
        /// <param name="timeout">Time to wait for a capture.</param>
        /// <returns>A Capture object holding image data.</returns>
        /// <remarks>
        /// Gets the next capture in the streamed sequence of captures from the camera.
        /// If a new capture is not currently available, this function will block until the timeout is reached.
        /// The SDK will buffer at least two captures worth of data before dropping the oldest capture.
        /// Callers needing to capture all data need to ensure they read the data as fast as the data is being produced on average.
        /// </remarks>
        public Capture GetCapture(TimeSpan timeout)
        {
            lock (this)
            {
                if (this.disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                using (LoggingTracer tracer = new LoggingTracer())
                {
                    NativeMethods.k4a_wait_result_t result = NativeMethods.k4a_device_get_capture(this.handle, out NativeMethods.k4a_capture_t capture, (int)timeout.TotalMilliseconds);

                    if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_TIMEOUT)
                    {
                        throw new TimeoutException("Timed out waiting for capture");
                    }

                    AzureKinectException.ThrowIfNotSuccess(tracer, result);

                    if (capture.IsInvalid)
                    {
                        throw new AzureKinectException("k4a_device_get_capture did not return a valid capture handle");
                    }

                    return(new Capture(capture));
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Throws an <see cref="AzureKinectOpenDeviceException"/> if the result of the function
 /// is not a success.
 /// </summary>
 /// <param name="tracer">The tracer is that is capturing logging messages.</param>
 /// <param name="result">The result native function to call.</param>
 /// <typeparam name="T">The type of result to expect from the function call.</typeparam>
 internal static new void ThrowIfNotSuccess <T>(LoggingTracer tracer, T result)
     where T : System.Enum
 {
     if (!AzureKinectException.IsSuccess(result))
     {
         throw new AzureKinectOpenDeviceException($"result = {result}", tracer.LogMessages);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Throws an <see cref="AzureKinectOpenDeviceException"/> if the result of the function
 /// is not a success.
 /// </summary>
 /// <param name="function">The native function to call.</param>
 /// <typeparam name="T">The type of result to expect from the function call.</typeparam>
 internal static new void ThrowIfNotSuccess <T>(Func <T> function)
     where T : System.Enum
 {
     using (LoggingTracer tracer = new LoggingTracer())
     {
         T result = function();
         if (!AzureKinectException.IsSuccess(result))
         {
             throw new AzureKinectOpenDeviceException($"result = {result}", tracer.LogMessages);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Transform a 3D point of a source coordinate system into a 3D point of the target coordinate system.
        /// </summary>
        /// <param name="sourcePoint3D">The 3D coordinates in millimeters representing a point in <paramref name="sourceCamera"/>.</param>
        /// <param name="sourceCamera">The current camera.</param>
        /// <param name="targetCamera">The target camera.</param>
        /// <returns>A point in 3D coordiantes of <paramref name="targetCamera"/> stored in millimeters.</returns>
        public Vector3?TransformTo3D(Vector3 sourcePoint3D, CalibrationDeviceType sourceCamera, CalibrationDeviceType targetCamera)
        {
            using (LoggingTracer tracer = new LoggingTracer())
            {
                AzureKinectException.ThrowIfNotSuccess(tracer, NativeMethods.k4a_calibration_3d_to_3d(
                                                           ref this,
                                                           ref sourcePoint3D,
                                                           sourceCamera,
                                                           targetCamera,
                                                           out Vector3 target_point3d));

                return(target_point3d);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Transform a 3D point of a source coordinate system into a 2D pixel coordinate of the target camera.
        /// </summary>
        /// <param name="sourcePoint3D">The 3D coordinate in millimeters representing a point in <paramref name="sourceCamera"/> coordinate system.</param>
        /// <param name="sourceCamera">The current camera.</param>
        /// <param name="targetCamera">The target camera.</param>
        /// <returns>The 2D pixel coordinate in <paramref name="targetCamera"/> coordinates or null if the point is not valid in that coordinate system.</returns>
        public Vector2?TransformTo2D(Vector3 sourcePoint3D, CalibrationDeviceType sourceCamera, CalibrationDeviceType targetCamera)
        {
            using (LoggingTracer tracer = new LoggingTracer())
            {
                AzureKinectException.ThrowIfNotSuccess(tracer, NativeMethods.k4a_calibration_3d_to_2d(
                                                           ref this,
                                                           ref sourcePoint3D,
                                                           sourceCamera,
                                                           targetCamera,
                                                           out Vector2 target_point2d,
                                                           out bool valid));

                return(valid ? (Vector2?)target_point2d : null);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Get the Azure Kinect color sensor control value.
        /// </summary>
        /// <param name="command">Color sensor control command.</param>
        /// <param name="mode">The mode of the color control option.</param>
        /// <returns>The value of the color control option.</returns>
        public int GetColorControl(ColorControlCommand command, out ColorControlMode mode)
        {
            lock (this)
            {
                if (this.disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                using (LoggingTracer tracer = new LoggingTracer())
                {
                    AzureKinectException.ThrowIfNotSuccess(tracer, NativeMethods.k4a_device_get_color_control(this.handle, command, out mode, out int value));
                    return(value);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Transform a 2D pixel coordinate from color camera into a 2D pixel coordinate of the depth camera.
        /// </summary>
        /// <param name="sourcePoint2D">The 2D pixel color camera coordinates.</param>
        /// <param name="depth">The depth image.</param>
        /// <returns>The 2D pixel in depth camera coordinates, or null if the source point is not valid in the depth camera coordinate system.</returns>
        public Vector2?TransformColor2DToDepth2D(Vector2 sourcePoint2D, Image depth)
        {
            if (depth == null)
            {
                throw new ArgumentNullException(nameof(depth));
            }

            using (LoggingTracer tracer = new LoggingTracer())
                using (Image depthReference = depth.Reference())
                {
                    AzureKinectException.ThrowIfNotSuccess(tracer, NativeMethods.k4a_calibration_color_2d_to_depth_2d(
                                                               ref this,
                                                               ref sourcePoint2D,
                                                               depthReference.DangerousGetHandle(),
                                                               out Vector2 target_point2d,
                                                               out bool valid));

                    return(valid ? (Vector2?)target_point2d : null);
                }
        }