My program has problems with poor coordination between depth and color images.
The player’s mask is not in the same place as the person (see picture below).
void _AllFreamReady(object sender, AllFramesReadyEventArgs e) { using (ColorImageFrame _colorFrame = e.OpenColorImageFrame()) { if (_colorFrame == null) //jezeli pusta ramka nie rob nic { return; } byte[] _pixels = new byte[_colorFrame.PixelDataLength]; //utworzenie tablicy pixeli dla 1 ramki obrazu o rozmiarach przechwyconej ramki z strumienia _colorFrame.CopyPixelDataTo(_pixels); //kopiujemy pixele do tablicy int _stride = _colorFrame.Width * 4; //Kazdy pixel moze miec 4 wartosci Red Green Blue lub pusty image1.Source = BitmapSource.Create(_colorFrame.Width, _colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, _pixels, _stride); if (_closing) { return; } using (DepthImageFrame _depthFrame = e.OpenDepthImageFrame()) { if (_depthFrame == null) { return; } byte[] _pixelsdepth = _GenerateColoredBytes(_depthFrame,_pixels); int _dstride = _depthFrame.Width * 4; image3.Source = BitmapSource.Create(_depthFrame.Width, _depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, _pixelsdepth, _dstride); } } } private byte[] _GenerateColoredBytes(DepthImageFrame _depthFrame, byte[] _pixels) { short[] _rawDepthData = new short[_depthFrame.PixelDataLength]; _depthFrame.CopyPixelDataTo(_rawDepthData); Byte[] _dpixels = new byte[_depthFrame.Height * _depthFrame.Width * 4]; const int _blueindex = 0; const int _greenindex = 1; const int _redindex = 2; for (int _depthindex = 0, _colorindex = 0; _depthindex < _rawDepthData.Length && _colorindex < _dpixels.Length; _depthindex++, _colorindex += 4) { int _player = _rawDepthData[_depthindex] & DepthImageFrame.PlayerIndexBitmaskWidth; if (_player > 0) { _dpixels[_colorindex + _redindex] = _pixels[_colorindex + _redindex]; _dpixels[_colorindex + _greenindex] = _pixels[_colorindex + _greenindex]; _dpixels[_colorindex + _blueindex] = _pixels[_colorindex + _blueindex]; }; } return _dpixels; }

source share