예제 #1
0
        /// <inheritdoc/>
        protected override void ProcessSensorFrame(IResearchModeSensorFrame sensorFrame, ResearchModeSensorResolution resolution, ulong frameTicks, DateTime originatingTime)
        {
            var shouldOutputDepthImage = this.Configuration.OutputDepthImage &&
                                         (originatingTime - this.DepthImage.LastEnvelope.OriginatingTime) > this.Configuration.OutputMinInterval;

            var shouldOutputDepthImageCameraView = this.Configuration.OutputDepthImageCameraView &&
                                                   (originatingTime - this.DepthImageCameraView.LastEnvelope.OriginatingTime) > this.Configuration.OutputMinInterval;

            var shouldOutputInfraredImage = this.Configuration.OutputInfraredImage &&
                                            (originatingTime - this.InfraredImage.LastEnvelope.OriginatingTime) > this.Configuration.OutputMinInterval;

            var shouldOutputInfraredImageCameraView = this.Configuration.OutputInfraredImageCameraView &&
                                                      (originatingTime - this.InfraredImageCameraView.LastEnvelope.OriginatingTime) > this.Configuration.OutputMinInterval;

            if (shouldOutputDepthImage ||
                shouldOutputDepthImageCameraView ||
                shouldOutputInfraredImage ||
                shouldOutputInfraredImageCameraView)
            {
                var depthFrame       = sensorFrame as ResearchModeSensorDepthFrame;
                int depthImageWidth  = (int)resolution.Width;
                int depthImageHeight = (int)resolution.Height;

                // Process and post the depth image if need be
                if (shouldOutputDepthImage || shouldOutputDepthImageCameraView)
                {
                    byte[] sigmaBuffer = null;
                    var    depthBuffer = depthFrame.GetBuffer();

                    if (this.isLongThrow)
                    {
                        sigmaBuffer = depthFrame.GetSigmaBuffer(); // Long-throw only
                        Debug.Assert(depthBuffer.Length == sigmaBuffer.Length, "Depth and sigma buffers should be of equal size!");
                    }

                    using var depthImage = DepthImagePool.GetOrCreate(
                              depthImageWidth,
                              depthImageHeight,
                              DepthValueSemantics.DistanceToPoint,
                              0.001);
                    Debug.Assert(depthImage.Resource.Size == depthBuffer.Length * sizeof(ushort), "DepthImage size does not match raw depth buffer size!");

                    unsafe
                    {
                        ushort *depthData = (ushort *)depthImage.Resource.ImageData.ToPointer();
                        for (int i = 0; i < depthBuffer.Length; ++i)
                        {
                            bool invalid = this.isLongThrow ?
                                           ((sigmaBuffer[i] & InvalidMask) > 0) :
                                           (depthBuffer[i] >= InvalidAhatValue);

                            *depthData++ = invalid ? (ushort)0 : depthBuffer[i];
                        }
                    }

                    if (shouldOutputDepthImage)
                    {
                        this.DepthImage.Post(depthImage, originatingTime);
                    }

                    if (shouldOutputDepthImageCameraView)
                    {
                        using var depthImageCameraView = new DepthImageCameraView(depthImage, this.GetCameraIntrinsics(), this.GetCameraPose());
                        this.DepthImageCameraView.Post(depthImageCameraView, originatingTime);
                    }
                }

                // Process and post the infrared image if need be
                if (shouldOutputInfraredImage || shouldOutputInfraredImageCameraView)
                {
                    var infraredBuffer = depthFrame.GetAbDepthBuffer();
                    using var infraredImage = ImagePool.GetOrCreate(depthImageWidth, depthImageHeight, PixelFormat.Gray_16bpp);
                    Debug.Assert(infraredImage.Resource.Size == infraredBuffer.Length * sizeof(ushort), "InfraredImage size does not match raw infrared buffer size!");

                    unsafe
                    {
                        fixed(ushort *p = infraredBuffer)
                        {
                            infraredImage.Resource.CopyFrom((IntPtr)p);
                        }
                    }

                    if (shouldOutputInfraredImage)
                    {
                        this.InfraredImage.Post(infraredImage, originatingTime);
                    }

                    if (shouldOutputInfraredImageCameraView)
                    {
                        using var infraredImageCameraView = new ImageCameraView(infraredImage, this.GetCameraIntrinsics(), this.GetCameraPose());
                        this.InfraredImageCameraView.Post(infraredImageCameraView, originatingTime);
                    }
                }
            }
        }
예제 #2
0
        /// <inheritdoc/>
        protected override void ProcessSensorFrame(IResearchModeSensorFrame sensorFrame, ResearchModeSensorResolution resolution, ulong frameTicks, DateTime originatingTime)
        {
            var shouldOutputImage = this.Configuration.OutputImage &&
                                    (originatingTime - this.Image.LastEnvelope.OriginatingTime) > this.Configuration.OutputMinInterval;

            var shouldOutputImageCameraView = this.Configuration.OutputImageCameraView &&
                                              (originatingTime - this.ImageCameraView.LastEnvelope.OriginatingTime) > this.Configuration.OutputMinInterval;

            if (shouldOutputImage || shouldOutputImageCameraView)
            {
                var vlcFrame    = sensorFrame as ResearchModeSensorVlcFrame;
                var imageBuffer = vlcFrame.GetBuffer();
                int imageWidth  = (int)resolution.Width;
                int imageHeight = (int)resolution.Height;

                using var image = ImagePool.GetOrCreate(imageWidth, imageHeight, PixelFormat.Gray_8bpp);
                Debug.Assert(image.Resource.Size == imageBuffer.Length * sizeof(byte), "Image size does not match raw image buffer size!");
                image.Resource.CopyFrom(imageBuffer);

                if (shouldOutputImage)
                {
                    this.Image.Post(image, originatingTime);
                }

                if (shouldOutputImageCameraView)
                {
                    using var imageCameraView = new ImageCameraView(image, this.GetCameraIntrinsics(), this.GetCameraPose());
                    this.ImageCameraView.Post(imageCameraView, originatingTime);
                }
            }
        }