Exemplo n.º 1
0
    public void CloseSensor(KinectInterop.SensorData sensorData)
    {
        UnityEngine.WSA.Application.InvokeOnUIThread(() =>
        {
            if (_kinectSensor != null)
            {
                _kinectSensor?.CloseAsync();
                Debug.Log("UWP-K2 sensor closed");
            }
        }, true);

        if (_depthPlaneCoordsBuf != null)
        {
            _depthPlaneCoordsBuf.Release();
            _depthPlaneCoordsBuf = null;
        }

        if (_depthDepthValuesBuf != null)
        {
            _depthDepthValuesBuf.Release();
            _depthDepthValuesBuf = null;
        }

        if (_colorPlaneCoordsBuf != null)
        {
            _colorPlaneCoordsBuf.Release();
            _colorPlaneCoordsBuf = null;
        }

        if (_colorSpaceCoordsBuf != null)
        {
            _colorSpaceCoordsBuf.Release();
            _colorSpaceCoordsBuf = null;
        }

        if (_colorDepthCoordsBuf != null)
        {
            _colorDepthCoordsBuf.Release();
            _colorDepthCoordsBuf = null;
        }

        _colorCameraIntrinsics = null;
        _depthCameraIntrinsics = null;
        _coordinateMapper      = null;
        _coordinateMapper2     = null;

        _coordMapperShader = null;
        _lastDepthDataBuf  = null;

        _clearLatestFrames = true;
        FreeMultiSourceFrame(sensorData);
    }
Exemplo n.º 2
0
    private async Task InitializeKinect()
    {
        _kinectSensor = await Sensor.GetDefaultAsync();

        if (_kinectSensor != null)
        {
            await _kinectSensor.OpenAsync();

            if ((sensorFlags & KinectInterop.FrameSource.TypeColor) != 0)
            {
                _colorReader = await _kinectSensor.OpenColorFrameReaderAsync(ReaderConfig.HalfRate | ReaderConfig.HalfResolution);

                sensorData.colorImage = new byte[sensorData.colorImageWidth * sensorData.colorImageHeight * 4];

                if (_colorReader != null)
                {
                    _colorReader.FrameArrived += ColorReader_FrameArrived;
                }
            }

            if ((sensorFlags & KinectInterop.FrameSource.TypeDepth) != 0)
            {
                _depthReader = await _kinectSensor.OpenDepthFrameReaderAsync();

                sensorData.depthImage = new ushort[sensorData.depthImageWidth * sensorData.depthImageHeight];

                if (_depthReader != null)
                {
                    _depthReader.FrameArrived += DepthReader_FrameArrived;
                }
            }

            if ((sensorFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
            {
                _bodyIndexReader = await _kinectSensor.OpenBodyIndexFrameReaderAsync();

                sensorData.bodyIndexImage = new byte[sensorData.depthImageWidth * sensorData.depthImageHeight];

                if (_bodyIndexReader != null)
                {
                    _bodyIndexReader.FrameArrived += BodyIndexReader_FrameArrived;
                }
            }

            if ((sensorFlags & KinectInterop.FrameSource.TypeBody) != 0)
            {
                _bodyReader = await _kinectSensor.OpenBodyFrameReaderAsync();

                if (_bodyReader != null)
                {
                    _bodyReader.FrameArrived += BodyReader_FrameArrived;
                }
            }

            // get the coordinate mapper
            _coordinateMapper  = _kinectSensor.GetCoordinateMapper();
            _coordinateMapper2 = new CoordinateMapper2();

            Debug.Log("UWP-K2 sensor opened");
        }
        else
        {
            Debug.Log("UWP-K2 sensor not found");
        }
    }