Exemplo n.º 1
0
        void UpdateReceiving()
        {
            if (_DepthImageSize != _ReceiverClient.DepthImageSize)
            {
                _DepthImageSize    = _ReceiverClient.DepthImageSize;
                _TrvlDecoder       = new TemporalRVLDecoder(_DepthImageSize);
                _DepthImageRawData = new byte[_DepthImageSize * sizeof(short)];
            }

            if (_DepthImageTexture == null ||
                _DepthImageTexture.width != _ReceiverClient.DepthWidth ||
                _DepthImageTexture.height != _ReceiverClient.DepthHeight)
            {
                int width  = _ReceiverClient.DepthWidth;
                int height = _ReceiverClient.DepthHeight;
                _DepthImageTexture = new Texture2D(width, height, TextureFormat.R16, false);
            }

            if (_ColorImageTexture == null ||
                _ColorImageTexture.width != _ReceiverClient.ColorWidth ||
                _ColorImageTexture.height != _ReceiverClient.ColorHeight)
            {
                int width  = _ReceiverClient.ColorWidth;
                int height = _ReceiverClient.ColorHeight;
                _ColorImageTexture = new Texture2D(width, height, TextureFormat.BGRA32, false);
            }

            Frame frame = _ReceiverClient.GetFrame();

            if (frame != null)
            {
                // Debug.Log("Frame count: " + frame.FrameCount);

                bool   isKeyFrame       = frame.IsKeyFrame;
                byte[] encodedDepthData = frame.EncodedDepthData;

                if (frame.CompressionMethod == CompressionMethod.TemporalRVL)
                {
                    // Temporal RVL decompression
                    _DecodedDepthData = _TrvlDecoder.Decode(encodedDepthData, isKeyFrame);
                }
                else if (frame.CompressionMethod == CompressionMethod.RVL)
                {
                    // RVL decompression
                    RVL.DecompressRVL(encodedDepthData, _DecodedDepthData);
                }

                Buffer.BlockCopy(_DecodedDepthData, 0, _DepthImageRawData, 0, _DepthImageRawData.Length * sizeof(byte));
                _DepthImageTexture.LoadRawTextureData(_DepthImageRawData);
                _DepthImageTexture.Apply();

                _ColorImageData = frame.ColorImageData;
                _ColorImageTexture.LoadImage(_ColorImageData);
                _ColorImageTexture.Apply();
            }
        }
Exemplo n.º 2
0
        void Start()
        {
            _KinectSensor = _AzureKinectManager.Sensor;
            if (_KinectSensor != null)
            {
                int depthImageSize = _KinectSensor.DepthImageWidth * _KinectSensor.DepthImageHeight;
                _DepthRawData     = new byte[depthImageSize * sizeof(ushort)];
                _EncodedDepthData = new byte[depthImageSize];
                _DecodedDepthData = new short[depthImageSize];
                _Diff             = new short[depthImageSize];

                _DepthImageTexture        = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.R16, false);
                _DecodedDepthImageTexture = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.R16, false);
                _DiffImageTexture         = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.R16, false);
                _ColorImageTexture        = new Texture2D(_KinectSensor.ColorImageWidth, _KinectSensor.ColorImageHeight, TextureFormat.BGRA32, false);

                MeshRenderer depthMeshRenderer = _DepthImageObject.GetComponent <MeshRenderer>();
                depthMeshRenderer.sharedMaterial = new Material(_DepthVisualizer);
                depthMeshRenderer.sharedMaterial.SetTexture("_DepthTex", _DepthImageTexture);

                MeshRenderer decodedDepthMeshRenderer = _DecodedDepthImageObject.GetComponent <MeshRenderer>();
                decodedDepthMeshRenderer.sharedMaterial = new Material(_DepthVisualizer);
                decodedDepthMeshRenderer.sharedMaterial.SetTexture("_DepthTex", _DecodedDepthImageTexture);

                MeshRenderer diffMeshRenderer = _DiffImageObject.GetComponent <MeshRenderer>();
                diffMeshRenderer.sharedMaterial = new Material(_DiffVisualizer);
                diffMeshRenderer.sharedMaterial.SetTexture("_DepthTex", _DiffImageTexture);

                MeshRenderer colorMeshRenderer = _ColorImageObject.GetComponent <MeshRenderer>();
                colorMeshRenderer.sharedMaterial = new Material(_UnlitTextureMaterial);
                colorMeshRenderer.sharedMaterial.SetTexture("_MainTex", _ColorImageTexture);

                Debug.Log("ColorResolution: " + _KinectSensor.ColorImageWidth + "x" + _KinectSensor.ColorImageHeight);
                Debug.Log("DepthResolution: " + _KinectSensor.DepthImageWidth + "x" + _KinectSensor.DepthImageHeight);

                _TrvlEncoder = new TemporalRVLEncoder(depthImageSize, 10, 2);
                _TrvlDecoder = new TemporalRVLDecoder(depthImageSize);
            }
        }
        public void Initialize()
        {
            _KinectSensor = _AzureKinectManager.Sensor;
            if (_KinectSensor != null)
            {
                Debug.Log("ColorResolution: " + _KinectSensor.ColorImageWidth + "x" + _KinectSensor.ColorImageHeight);
                Debug.Log("DepthResolution: " + _KinectSensor.DepthImageWidth + "x" + _KinectSensor.DepthImageHeight);

                _DepthImageSize        = _KinectSensor.DepthImageWidth * _KinectSensor.DepthImageHeight;
                _DepthRawData          = new byte[_DepthImageSize * sizeof(short)];
                _Diff                  = new short[_DepthImageSize];
                _EncodedColorImageData = new byte[_DepthImageSize];

                _DepthImageTexture        = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.R16, false);
                _DecodedDepthImageTexture = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.R16, false);
                _DiffImageTexture         = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.R16, false);
                _ColorImageTexture        = new Texture2D(_KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight, TextureFormat.BGRA32, false);

                _TrvlEncoder = new TemporalRVLEncoder(_DepthImageSize, 10, 2);
                _TrvlDecoder = new TemporalRVLDecoder(_DepthImageSize);

                CameraCalibration deviceDepthCameraCalibration = _KinectSensor.DeviceCalibration.DepthCameraCalibration;
                CameraCalibration deviceColorCameraCalibration = _KinectSensor.DeviceCalibration.ColorCameraCalibration;

                _Calibration = new K4A.Calibration();
                _Calibration.DepthCameraCalibration = CreateCalibrationCamera(deviceDepthCameraCalibration, _KinectSensor.DepthImageWidth, _KinectSensor.DepthImageHeight);
                _Calibration.ColorCameraCalibration = CreateCalibrationCamera(deviceColorCameraCalibration, _KinectSensor.ColorImageWidth, _KinectSensor.ColorImageHeight);

                _CalibrationType = K4A.CalibrationType.Depth; // Color to depth

                _Initialized = true;
            }
            else
            {
                Debug.LogError("KinectSensor is null!");
            }
        }