public BodyFrame PopFrame(int timeoutInMS = -1)
        {
            lock (this)
            {
                if (this.disposedValue)
                {
                    throw new ObjectDisposedException(nameof(BodyTracker));
                }

                NativeMethods.k4a_wait_result_t result = NativeMethods.k4abt_tracker_pop_result(this.handle, out NativeMethods.k4abt_frame_t frameHandle, timeoutInMS);

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

                AzureKinectException.ThrowIfNotSuccess(() => result);

                if (frameHandle.IsInvalid)
                {
                    throw new AzureKinectException("k4abt_tracker_pop_result did not return a valid body frame handle");
                }

                return(new BodyFrame(frameHandle));
            }
        }
 /// <summary>
 /// Throws an <see cref="AzureKinectException"/> if the result is not <see cref="NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_SUCCEEDED"/>.
 /// </summary>
 /// <param name="result">The result to check.</param>
 internal static void ThrowIfNotSuccess(NativeMethods.k4a_wait_result_t result)
 {
     if (result != NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_SUCCEEDED)
     {
         throw new AzureKinectException($"result = {result}");
     }
 }
Esempio n. 3
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());
                }
            }
        }
Esempio n. 4
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));
                }
            }
        }
Esempio n. 5
0
        public Capture GetCapture(int timeoutInMS = -1)
        {
            lock (this)
            {
                if (disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                NativeMethods.k4a_wait_result_t result = NativeMethods.k4a_device_get_capture(handle, out NativeMethods.k4a_capture_t capture, timeoutInMS);

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

                AzureKinectException.ThrowIfNotSuccess(result);

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

                return(new Capture(capture));
            }
        }
 /// <summary>
 /// Gets the next available body frame.
 /// </summary>
 /// <param name="timeout">The time in milliseconds the function should block waiting for the body frame.
 /// TimeSpan.Zero is a check of the queue without blocking. Passing a value of -1ms will blocking indefinitely.</param>
 /// <returns></returns>
 /// <remarks>
 /// Retrieves the next available body frame result and pop it from the output queue in the <see cref="Tracker"/>. If a new body
 /// frame is not currently available, this function will block up until the timeout is reached.The SDK will buffer at
 /// least three body frames worth of data before stopping new capture being queued by <see cref="EnqueueCapture(Capture, TimeSpan)"/>.
 /// Once body_frame data is read, the user must call Frame.Dispose() to return the allocated memory to the SDK.
 /// </remarks>
 public Frame PopResult(TimeSpan timeout)
 {
     NativeMethods.k4a_wait_result_t result = NativeMethods.k4abt_tracker_pop_result(this.handle.DangerousGetHandle(), out NativeMethods.k4abt_frame_t frame, (int)timeout.TotalMilliseconds);
     if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_TIMEOUT)
     {
         throw new TimeoutException();
     }
     else if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_FAILED)
     {
         throw new AzureKinectException();
     }
     return(new Frame(frame));
 }
        /// <summary>
        /// Add a k4a sensor capture to the tracker input queue to generate its body tracking result asynchronously.
        /// </summary>
        /// <param name="capture">sensor capture returned by <see cref="Device.GetCapture(TimeSpan)"/>() from k4a SDK. It should contain the depth data for this function to work.Otherwise the function will return failure.</param>
        /// <param name="timeout">
        /// Specifies the time the function should block waiting to add the sensor capture to the tracker
        /// process queue. 0 is a check of the status without blocking. Passing a value of TimeSpan.FromMilliseconds(-1) will block
        /// indefinitely until the capture is added to the process queue.
        /// </param>
        /// <remarks>
        /// <para>
        /// Add a k4a capture to the tracker input queue so that it can be processed asynchronously to generate the body tracking
        /// result. The processed results will be added to an output queue maintained by k4abt_tracker_t instance. Call
        /// <see cref="PopResult(TimeSpan)"/> to get the result and pop it from the output queue.
        /// If the input queue or output queue is full, this function will block up until the timeout is reached.
        /// Once body_frame data is read, the user must call <see cref="Frame.Dispose()"/>() to return the allocated memory to the SDK</para>
        /// <para>
        /// Upon successfully insert a sensor capture to the input queue this function will return success.
        /// </para>
        /// <para>
        /// This function returns ::K4A_WAIT_RESULT_FAILED when either the tracker is shut down by k4abt_tracker_shutdown() API,
        /// or an internal problem is encountered before adding to the input queue: such as low memory condition,
        /// sensor_capture_handle not containing the depth data, or other unexpected issues.
        /// </para>
        /// </remarks>
        /// <seealso cref="Tracker"/>
        public void EnqueueCapture(Capture capture, TimeSpan timeout)
        {
            SafeHandleZeroOrMinusOneIsInvalid captureHandle = (SafeHandleZeroOrMinusOneIsInvalid)typeof(Capture).GetField("handle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(capture);

            NativeMethods.k4a_wait_result_t result = NativeMethods.k4abt_tracker_enqueue_capture(this.handle.DangerousGetHandle(), captureHandle.DangerousGetHandle(), (int)timeout.TotalMilliseconds);
            if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_TIMEOUT)
            {
                throw new TimeoutException();
            }
            else if (result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_FAILED)
            {
                throw new AzureKinectException();
            }
        }
        public void EnqueueCapture(Capture capture, int timeoutInMS = -1)
        {
            lock (this)
            {
                if (disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                NativeMethods.k4a_wait_result_t result = BodyTrackingNativeMethods.k4abt_tracker_enqueue_capture(handle, capture.DangerousGetHandle(), timeoutInMS);

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

                AzureKinectException.ThrowIfNotSuccess(result);
            }
        }
        public BodyFrame PopResult(int timeoutInMS = -1)
        {
            lock (this)
            {
                if (disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                NativeMethods.k4a_wait_result_t result = BodyTrackingNativeMethods.k4abt_tracker_pop_result(handle, out BodyTrackingNativeMethods.k4abt_frame_t frame, timeoutInMS);

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

                AzureKinectException.ThrowIfNotSuccess(result);

                return(new BodyFrame(frame));
            }
        }
Esempio n. 10
0
        public ImuSample GetImuSample(int timeoutInMS = -1)
        {
            lock (this)
            {
                if (disposedValue)
                {
                    throw new ObjectDisposedException(nameof(Device));
                }

                ImuSample sample = new ImuSample();
                NativeMethods.k4a_wait_result_t result = NativeMethods.k4a_device_get_imu_sample(handle, sample, timeoutInMS);

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

                AzureKinectException.ThrowIfNotSuccess(result);

                return(sample);
            }
        }
 /// <summary>
 /// Determines if the <see cref="NativeMethods.k4a_wait_result_t"/> is a success.
 /// </summary>
 /// <param name="result">The result to check if it is a success.</param>
 /// <returns><c>True</c> if the result is a success;otherwise <c>false</c>.</returns>
 internal static bool IsSuccess(NativeMethods.k4a_wait_result_t result)
 {
     return(result == NativeMethods.k4a_wait_result_t.K4A_WAIT_RESULT_SUCCEEDED);
 }