Frame ApplyFilter(DepthFrame depth, FrameSource frameSource) { using (var p = depth.Profile) { var count = depth.Width * depth.Height; if (depthData == null || depthData.Length != count) { depthData = new ushort[count]; } depth.CopyTo(depthData); for (int i = 0; i < count; i++) { if (depthData[i] > Distance) { depthData[i] = 0; } } var v = frameSource.AllocateVideoFrame <DepthFrame>(p, depth, depth.BitsPerPixel, depth.Width, depth.Height, depth.Stride, Extension.DepthFrame); v.CopyFrom(depthData); return(v); } }
public override Frame Process(Frame frame, FrameSource frameSource, FramesReleaser releaser) { if (!_enabled) { return(frame); } var org = frame as VideoFrame; var stride = org.Width * org.BitsPerPixel / 8; var newFrame = frameSource.AllocateVideoFrame(org.Profile, org, org.BitsPerPixel, org.Width, org.Height, stride, Extension.DepthFrame); if (_pixels == null || org.Profile.UniqueID != _uniqueID) { InitPixels(org); } Marshal.Copy(org.Data, _pixels, 0, _pixels.Length); for (int i = 0; i < _pixels.Length; i++) { _pixels[i] = (short)(_pixels[i] >> _depthResolution); _pixels[i] = (short)(_pixels[i] << _depthResolution); } Marshal.Copy(_pixels, 0, newFrame.Data, _pixels.Length); return(newFrame); }