Пример #1
0
        /// <summary>Adds a Azure Kinect sensor capture to the tracker input queue to generate its body tracking result asynchronously.</summary>
        /// <param name="capture">It should contain the depth data compatible with <see cref="DepthMode"/> for this function to work. Not <see langword="null"/>.</param>
        /// <param name="timeout">
        /// Specifies the time the function should block waiting to add the sensor capture to the tracker process queue.
        /// Default value is <see cref="Timeout.NoWait"/>, which means checking of the status without blocking.
        /// Passing <see cref="Timeout.Infinite"/> will block indefinitely until the capture is added to the process queue.
        /// </param>
        /// <returns>
        /// <see langword="true"/> - if a sensor capture is successfully added to the processing queue.
        /// <see langword="false"/> - if the queue is still full (see <see cref="IsQueueFull"/> property) before the <paramref name="timeout"/> elapses.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="capture"/> cannot be <see langword="null"/>.</exception>
        /// <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))
        {
            if (capture == null)
            {
                throw new ArgumentNullException(nameof(capture));
            }

            var res = NativeApi.TrackerEnqueueCapture(handle.ValueNotDisposed, Capture.ToHandle(capture), timeout);

            if (res == NativeCallResults.WaitResult.Timeout)
            {
                return(false);
            }
            if (res == NativeCallResults.WaitResult.Failed)
            {
                handle.CheckNotDisposed();      // to throw ObjectDisposedException() if failure is a result of disposing

                using (var depthImage = capture.DepthImage)
                {
                    if (depthImage == null)
                    {
                        throw new ArgumentException(
                                  "Capture should contain the depth data.",
                                  nameof(capture));
                    }
                    if (depthImage.Format != ImageFormat.Depth16)
                    {
                        throw new ArgumentException(
                                  $"Invalid format of depth data in capture: expected {ImageFormat.Depth16} but was {depthImage.Format}.",
                                  nameof(capture));
                    }
                    if (depthImage.WidthPixels != DepthMode.WidthPixels() || depthImage.HeightPixels != DepthMode.HeightPixels())
                    {
                        throw new ArgumentException(
                                  $"Invalid resolution of depth data in capture: expected {DepthMode.WidthPixels()}x{DepthMode.HeightPixels()} pixels but was {depthImage.WidthPixels}x{depthImage.HeightPixels} pixels.",
                                  nameof(capture));
                    }
                }

                throw new BodyTrackingException("Cannot add new capture to body tracking pipeline. See logs for details.");
            }

            Interlocked.Increment(ref queueSize);
            QueueSizeIncreased?.Invoke(this, EventArgs.Empty);

            return(true);
        }
Пример #2
0
        public bool TryEnqueueCapture(Sensor.Capture capture, Timeout timeout = default(Timeout))
        {
            if (capture == null)
                throw new ArgumentNullException(nameof(capture));

            var res = NativeApi.TrackerEnqueueCapture(handle.ValueNotDisposed, Sensor.Capture.ToHandle(capture), timeout);
            if (res == NativeCallResults.WaitResult.Timeout)
                return false;
            if (res == NativeCallResults.WaitResult.Failed)
            {
                handle.CheckNotDisposed();      // to throw ObjectDisposedException() if failure is a result of disposing
                throw new BodyTrackingException("Cannot add new capture to body tracking pipeline");
            }

            Interlocked.Increment(ref queueSize);
            QueueSizeIncreased?.Invoke(this, EventArgs.Empty);

            return true;
        }