Exemple #1
0
        private void BodyRecognizedCallback(int numBodies)
        {
            try
            {
                self.bodyFrameCount++;

                var bodies  = AzureKinectBodyTracker.GetBody(numBodies);
                var imuData = AzureKinectBodyTracker.GetImuData();

                self.syncContext.Post((s) =>
                {
                    if (!self.isRunning)
                    {
                        return;
                    }
                    for (var i = 0; self.isRunning && (i < AzureKinectBodyTracker.MaxBody); i++)
                    {
                        self.bodyVisualizers[i].Apply((i < bodies.Length) ? bodies[i] : Body.Empty, i);
                    }
                    self.imuVisualizer.Apply(imuData);
                }, null);
            }
            catch (Exception e)
            {
                Debug.Log($"{e.GetType().Name}\n{e.Message}\n{e.StackTrace}");
            }
        }
Exemple #2
0
        private IEnumerator Process()
        {
            var depthTextureId = 1u;

            this.depthTexture = new Texture2D(640, 576, TextureFormat.R16, false);
            this.depthMaterial.mainTexture = this.depthTexture;
            var colorTextureId = 2u;

            this.colorTexture = new Texture2D(1920, 1080, TextureFormat.BGRA32, false);
            this.colorMaterial.mainTexture = this.colorTexture;
            var transformedDepthTextureId = 3u;

            this.transformedDepthTexture = new Texture2D(1920, 1080, TextureFormat.R16, false);
            this.transformedDepthMaterial.mainTexture = this.transformedDepthTexture;

            var callback = AzureKinectBodyTracker.GetTextureUpdateCallback();

            this.commandBuffer.IssuePluginCustomTextureUpdateV2(callback, this.depthTexture, depthTextureId);
            this.commandBuffer.IssuePluginCustomTextureUpdateV2(callback, this.colorTexture, colorTextureId);
            this.commandBuffer.IssuePluginCustomTextureUpdateV2(callback, this.transformedDepthTexture, transformedDepthTextureId);

            AzureKinectBodyTracker.Start(depthTextureId, colorTextureId, transformedDepthTextureId);
            while (true)
            {
                Graphics.ExecuteCommandBuffer(this.commandBuffer);
                yield return(null);
            }
        }
Exemple #3
0
        private IEnumerator Process(DepthMode depthMode, bool cpuOnly)
        {
            var debugDelegate = new AzureKinectBodyTracker.DebugLogDelegate(PluginDebugLogCallBack);
            var debagCallback = Marshal.GetFunctionPointerForDelegate(debugDelegate);

            AzureKinectBodyTracker.SetDebugLogCallback(debagCallback);

            var bodyRecognizedDelegate = new AzureKinectBodyTracker.BodyRecognizedDelegate(this.BodyRecognizedCallback);
            var bodyRecognizedCallback = Marshal.GetFunctionPointerForDelegate(bodyRecognizedDelegate);

            AzureKinectBodyTracker.SetBodyRecognizedCallback(bodyRecognizedCallback);

            var depthTextureId = 1u;
            var depthWidth     = (int)AzureKinectBodyTracker.DepthResolutions[depthMode].x;
            var depthHeight    = (int)AzureKinectBodyTracker.DepthResolutions[depthMode].y;

            this.depthTexture = new Texture2D((depthWidth > 0) ? depthWidth : 1, (depthHeight > 0) ? depthHeight : 1, TextureFormat.R16, false);
            this.depthMaterial.mainTexture = this.depthTexture;
            var colorTextureId = 2u;

            this.colorTexture = new Texture2D(1920, 1080, TextureFormat.BGRA32, false);
            this.colorMaterial.mainTexture = this.colorTexture;
            var transformedDepthTextureId = 3u;

            this.transformedDepthTexture = new Texture2D(1920, 1080, TextureFormat.R16, false);
            this.transformedDepthMaterial.mainTexture = this.transformedDepthTexture;

            var callback      = AzureKinectBodyTracker.GetTextureUpdateCallback();
            var commandBuffer = new CommandBuffer();

            commandBuffer.name = "AzureKinectImagesUpdeate";
            commandBuffer.IssuePluginCustomTextureUpdateV2(callback, this.depthTexture, depthTextureId);
            commandBuffer.IssuePluginCustomTextureUpdateV2(callback, this.colorTexture, colorTextureId);
            commandBuffer.IssuePluginCustomTextureUpdateV2(callback, this.transformedDepthTexture, transformedDepthTextureId);

            try
            {
                AzureKinectBodyTracker.Start(depthTextureId, colorTextureId, transformedDepthTextureId, depthMode, cpuOnly);
                this.currentDepthMode = depthMode;
            }
            catch (K4ABTException)
            {
                this.ProcessFinallize(false);
                yield break;
            }
            this.isRunning = true;
            while (this.isRunning)
            {
                Graphics.ExecuteCommandBuffer(commandBuffer);
                yield return(null);
            }
            AzureKinectBodyTracker.End();
            this.ProcessFinallize();
        }
Exemple #4
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));
            }
        }
Exemple #5
0
        void Start()
        {
            self             = this;
            this.syncContext = SynchronizationContext.Current;

            this.commandBuffer      = new CommandBuffer();
            this.commandBuffer.name = "AzureKinectImagesUpdeate";

            var debugDelegate = new AzureKinectBodyTracker.DebugLogDelegate(PluginDebugLogCallBack);
            var debagCallback = Marshal.GetFunctionPointerForDelegate(debugDelegate);

            AzureKinectBodyTracker.SetDebugLogCallback(debagCallback);

            var bodyRecognizedDelegate = new AzureKinectBodyTracker.BodyRecognizedDelegate(this.BodyRecognizedCallback);
            var bodyRecognizedCallback = Marshal.GetFunctionPointerForDelegate(bodyRecognizedDelegate);

            AzureKinectBodyTracker.SetBodyRecognizedCallback(bodyRecognizedCallback);

            this.StartCoroutine(this.Process());
        }
Exemple #6
0
        private IEnumerator Process(DepthMode depthMode, bool cpuOnly)
        {
            var debugDelegate = new AzureKinectBodyTracker.DebugLogDelegate(PluginDebugLogCallBack);
            var debagCallback = Marshal.GetFunctionPointerForDelegate(debugDelegate);

            AzureKinectBodyTracker.SetDebugLogCallback(debagCallback);

            try
            {
                AzureKinectBodyTracker.Start(0, 0, 0, depthMode, cpuOnly);
                this.currentDepthMode = depthMode;
            }
            catch (K4ABTException)
            {
                this.ProcessFinallize(false);
                yield break;
            }

            var depthImageToPointCloudDelegate = new AzureKinectBodyTracker.DepthImageToPointCloudDelegate(this.DepthImageToPointCloudCallback);
            var depthImageToPointCloudCallback = Marshal.GetFunctionPointerForDelegate(depthImageToPointCloudDelegate);

            AzureKinectBodyTracker.SetDepthImageToPointCloudCallback(depthImageToPointCloudCallback);

            var colorImageToDepthSpaceDelegate = new AzureKinectBodyTracker.ColorImageToDepthSpaceDelegate(this.ColorImageToDepthSpaceCallback);
            var colorImageToDepthSpaceCallback = Marshal.GetFunctionPointerForDelegate(colorImageToDepthSpaceDelegate);

            AzureKinectBodyTracker.SetColorImageToDepthSpaceCallback(colorImageToDepthSpaceCallback);

            this.isRunning = true;
            while (this.isRunning)
            {
                yield return(null);
            }
            AzureKinectBodyTracker.End();
            this.ProcessFinallize();
        }
Exemple #7
0
 public void CalibratedJointPointToggleValueChanged(bool value)
 {
     AzureKinectBodyTracker.SetCalibratedJointPointAvailability(value);
 }
Exemple #8
0
 private void OnApplicationQuit()
 {
     this.StopProcess();
     AzureKinectBodyTracker.End();
 }
Exemple #9
0
 private void OnApplicationQuit()
 {
     this.StopAllCoroutines();
     AzureKinectBodyTracker.End();
 }