Exemplo n.º 1
0
    public void UpdateMaskedColorTexture(MaskedColorFrame maskedColorFrame)
    {
        if (maskedColorFrame == null)
        {
            return;
        }
        // 拷贝抠图流数据
        if (_maskedColorFrameData == null || _maskedColorFrameData.Length != maskedColorFrame.ByteLength)
        {
            _maskedColorFrameData = new byte[maskedColorFrame.ByteLength];
        }
        maskedColorFrame.CopyData(ref _maskedColorFrameData);

        // 抠图纹理
        if (_maskedColorTexture == null)
        {
            _maskedColorTexture = new Texture2D(maskedColorFrame.Width, maskedColorFrame.Height, TextureFormat.RGBA32, false);
        }
        else if (_maskedColorTexture.width != maskedColorFrame.Width || _maskedColorTexture.height != maskedColorFrame.Height)
        {
            _maskedColorTexture.Resize(maskedColorFrame.Width, maskedColorFrame.Height, TextureFormat.RGBA32, false);
        }

        if (_maskedColorFrameData != null && _maskedColorFrameData.Length > 0)
        {
            _maskedColorTexture.LoadRawTextureData(_maskedColorFrameData);
            _maskedColorTexture.Apply(false);
        }
    }
Exemplo n.º 2
0
    private void CheckMaskedColorReader()
    {
        // Assumes AstraUnityContext.Instance.IsUpdateAsyncComplete is already true

        ReaderFrame frame;

        if (_readerMaskedColor.TryOpenFrame(0, out frame))
        {
            using (frame)
            {
                MaskedColorFrame maskedColorFrame = frame.GetFrame <MaskedColorFrame>();

                if (maskedColorFrame != null)
                {
                    if (_lastMaskedColorFrameIndex != maskedColorFrame.FrameIndex)
                    {
                        _lastMaskedColorFrameIndex = maskedColorFrame.FrameIndex;

                        UpdateMaskedColorTexture(maskedColorFrame);
                        OnMaskedColorFrame.Invoke(maskedColorFrame);
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    private void FrameReady(object sender, FrameReadyEventArgs e)
    {
        frameReadyTime.Start();

        //Debug.Log("FrameReady " + _frameCount);
        DepthFrame depthFrame = e.Frame.GetFrame <DepthFrame>();

        if (depthFrame != null)
        {
            if (_lastDepthFrameIndex != depthFrame.FrameIndex)
            {
                _lastDepthFrameIndex = depthFrame.FrameIndex;

                NewDepthFrameEvent.Invoke(depthFrame);
            }
        }

        ColorFrame colorFrame = e.Frame.GetFrame <ColorFrame>();

        if (colorFrame != null)
        {
            if (_lastColorFrameIndex != colorFrame.FrameIndex)
            {
                _lastColorFrameIndex = colorFrame.FrameIndex;

                NewColorFrameEvent.Invoke(colorFrame);
            }
        }

        BodyFrame bodyFrame = e.Frame.GetFrame <BodyFrame>();

        if (bodyFrame != null)
        {
            if (_lastBodyFrameIndex != bodyFrame.FrameIndex)
            {
                _lastBodyFrameIndex = bodyFrame.FrameIndex;

                NewBodyFrameEvent.Invoke(_bodyStream, bodyFrame);
                NewBodyMaskEvent.Invoke(bodyFrame.BodyMask);
            }
        }

        MaskedColorFrame maskedColorFrame = e.Frame.GetFrame <MaskedColorFrame>();

        if (maskedColorFrame != null)
        {
            if (_lastMaskedColorFrameIndex != maskedColorFrame.FrameIndex)
            {
                _lastMaskedColorFrameIndex = maskedColorFrame.FrameIndex;

                NewMaskedColorFrameEvent.Invoke(maskedColorFrame);
            }
        }

        ColorizedBodyFrame colorizedBodyFrame = e.Frame.GetFrame <ColorizedBodyFrame>();

        if (colorizedBodyFrame != null)
        {
            if (_lastColorizedBodyFrameIndex != colorizedBodyFrame.FrameIndex)
            {
                _lastColorizedBodyFrameIndex = colorizedBodyFrame.FrameIndex;

                NewColorizedBodyFrameEvent.Invoke(colorizedBodyFrame);
            }
        }

        _frameCount++;
        _frameReadyDirty = true;
        frameReadyTime.Stop();
    }