示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureKinectSensor"/> class.
        /// </summary>
        /// <param name="pipeline">Pipeline to add this component to.</param>
        /// <param name="configuration">Configuration to use for the sensor.</param>
        /// <param name="defaultDeliveryPolicy">An optional default delivery policy for the subpipeline (defaults is LatestMessage).</param>
        /// <param name="bodyTrackerDeliveryPolicy">An optional delivery policy for sending the depth-and-IR images stream to the body tracker (default is LatestMessage).</param>
        public AzureKinectSensor(
            Pipeline pipeline,
            AzureKinectSensorConfiguration configuration = null,
            DeliveryPolicy defaultDeliveryPolicy         = null,
            DeliveryPolicy bodyTrackerDeliveryPolicy     = null)
            : base(pipeline, nameof(AzureKinectSensor), defaultDeliveryPolicy ?? DeliveryPolicy.LatestMessage)
        {
            if (configuration == null)
            {
                configuration = new AzureKinectSensorConfiguration();
            }

            if (configuration.BodyTrackerConfiguration != null)
            {
                if (!configuration.OutputCalibration)
                {
                    throw new Exception($"The body tracker requires that the {nameof(AzureKinectSensor)} component must be configured to output calibration.");
                }

                if (!configuration.OutputInfrared || !configuration.OutputDepth)
                {
                    throw new Exception($"The body tracker requires that the {nameof(AzureKinectSensor)} component must be configured to output both Depth and IR streams.");
                }
            }

            var azureKinectCore = new AzureKinectCore(this, configuration);

            // Connect the sensor streams
            this.ColorImage    = azureKinectCore.ColorImage.BridgeTo(pipeline, nameof(this.ColorImage)).Out;
            this.Imu           = azureKinectCore.Imu.BridgeTo(pipeline, nameof(this.Imu)).Out;
            this.DepthImage    = azureKinectCore.DepthImage.BridgeTo(pipeline, nameof(this.DepthImage)).Out;
            this.InfraredImage = azureKinectCore.InfraredImage.BridgeTo(pipeline, nameof(this.InfraredImage)).Out;
            this.FrameRate     = azureKinectCore.FrameRate.BridgeTo(pipeline, nameof(this.FrameRate)).Out;
            this.Temperature   = azureKinectCore.Temperature.BridgeTo(pipeline, nameof(this.Temperature)).Out;
            this.DepthDeviceCalibrationInfo   = azureKinectCore.DepthDeviceCalibrationInfo.BridgeTo(pipeline, nameof(this.DepthDeviceCalibrationInfo)).Out;
            this.AzureKinectSensorCalibration = azureKinectCore.AzureKinectSensorCalibration.BridgeTo(pipeline, nameof(this.AzureKinectSensorCalibration)).Out;

            // Pipe captures and calibration to the body tracker
            if (configuration.BodyTrackerConfiguration != null)
            {
                var bodyTracker = new AzureKinectBodyTracker(this, configuration.BodyTrackerConfiguration);
                azureKinectCore.DepthAndIRImages.PipeTo(bodyTracker, bodyTrackerDeliveryPolicy ?? DeliveryPolicy.LatestMessage);
                azureKinectCore.AzureKinectSensorCalibration.PipeTo(bodyTracker.AzureKinectSensorCalibration, DeliveryPolicy.Unlimited);
                this.Bodies = bodyTracker.BridgeTo(pipeline, nameof(this.Bodies)).Out;
            }
            else
            {
                // create unused emitter to allow wiring while OutputBodies=false
                this.Bodies = pipeline.CreateEmitter <List <AzureKinectBody> >(this, nameof(this.Bodies));
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureKinectCore"/> class.
        /// </summary>
        /// <param name="pipeline">The pipeline to add the component to.</param>
        /// <param name="config">Configuration to use for the device.</param>
        /// <param name="name">An optional name for the component.</param>
        public AzureKinectCore(Pipeline pipeline, AzureKinectSensorConfiguration config = null, string name = nameof(AzureKinectCore))
        {
            this.pipeline      = pipeline;
            this.name          = name;
            this.configuration = config ?? new AzureKinectSensorConfiguration();

            if (this.configuration.OutputColor)
            {
                if (this.configuration.ColorResolution == ColorResolution.Off)
                {
                    throw new ArgumentException("Invalid configuration: Cannot output color stream when color resolution is set to Off.");
                }

                if (this.configuration.ColorFormat != ImageFormat.ColorBGRA32)
                {
                    throw new NotImplementedException("Invalid configuration: Psi so far only supports BGRA32 pixel format for the AzureKinect color camera");
                }
            }

            if (this.configuration.OutputDepth)
            {
                if (this.configuration.DepthMode == DepthMode.Off)
                {
                    throw new ArgumentException("Invalid configuration: Cannot output depth stream when depth mode is set to Off.");
                }

                if (this.configuration.DepthMode == DepthMode.PassiveIR)
                {
                    throw new ArgumentException("Invalid configuration: Cannot output depth stream when depth mode is set to PassiveIR.");
                }
            }

            if (this.configuration.OutputInfrared && this.configuration.DepthMode == DepthMode.Off)
            {
                throw new ArgumentException("Invalid configuration: Cannot output IR stream when depth mode is set to Off. Try DepthMode=PassiveIR if the intent is to capture only IR.");
            }

            this.DepthImage    = pipeline.CreateEmitter <Shared <DepthImage> >(this, nameof(this.DepthImage));
            this.InfraredImage = pipeline.CreateEmitter <Shared <Image> >(this, nameof(this.InfraredImage));
            this.ColorImage    = pipeline.CreateEmitter <Shared <Image> >(this, nameof(this.ColorImage));
            this.Imu           = pipeline.CreateEmitter <ImuSample>(this, nameof(this.Imu));
            this.DepthDeviceCalibrationInfo   = pipeline.CreateEmitter <IDepthDeviceCalibrationInfo>(this, nameof(this.DepthDeviceCalibrationInfo));
            this.AzureKinectSensorCalibration = pipeline.CreateEmitter <Calibration>(this, nameof(this.AzureKinectSensorCalibration));
            this.FrameRate        = pipeline.CreateEmitter <double>(this, nameof(this.FrameRate));
            this.Temperature      = pipeline.CreateEmitter <float>(this, nameof(this.Temperature));
            this.DepthAndIRImages = pipeline.CreateEmitter <(Shared <DepthImage>, Shared <Image>)>(this, nameof(this.DepthAndIRImages));

            this.DetermineImageDimensions();
        }