public KinectManager(FrameSourceTypes frameSourceTypes) { _FrameSourceTypes = frameSourceTypes; _KinectSensor = KinectSensor.GetDefault(); _KinectSensor.IsAvailableChanged += Kinect_IsAvailableChanged; if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Color)) { _ColorFrameDescription = _KinectSensor.ColorFrameSource.CreateFrameDescription(ImageFormat); } if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Depth)) { _DepthFrameDescription = _KinectSensor.DepthFrameSource.FrameDescription; } if (_FrameSourceTypes.HasFlag(FrameSourceTypes.BodyIndex)) { _BodyIndexFrameDescription = _KinectSensor.BodyIndexFrameSource.FrameDescription; } _MultiSourceFrameReader = _KinectSensor.OpenMultiSourceFrameReader(_FrameSourceTypes); _MultiSourceFrameReader.MultiSourceFrameArrived += FrameReader_MultiSourceFrameArrived; InitializeArrays(_KinectSensor.ColorFrameSource.CreateFrameDescription(ImageFormat), _KinectSensor.DepthFrameSource.FrameDescription, _KinectSensor.BodyIndexFrameSource.FrameDescription, _KinectSensor.BodyFrameSource.BodyCount); }
private void InitializeArrays(FrameDescription colorFrameDescription, FrameDescription depthFrameDescription, FrameDescription bodyIndexDescription, int bodyCount) { if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Color)) { ColorPixels = new byte[colorFrameDescription.Width * colorFrameDescription.Height * colorFrameDescription.BytesPerPixel]; } if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Depth)) { DepthPixels = new ushort[depthFrameDescription.Width * depthFrameDescription.Height]; } if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Body)) { Bodies = new Body[bodyCount]; } if (_FrameSourceTypes.HasFlag(FrameSourceTypes.BodyIndex)) { BodyIndexPixels = new byte[bodyIndexDescription.Width * bodyIndexDescription.Height * bodyIndexDescription.BytesPerPixel]; } }