/// <summary> /// Records a <c>ReplayBodyFrame</c>. /// </summary> /// <param name="frame">The frame.</param> public async Task RecordAsync(ReplayBodyFrame frame) { if (_writer.BaseStream == null || _writer.BaseStream.CanWrite == false) return; await Task.Run(() => { try { // Header _writer.Write((int)frame.FrameType); _writer.Write(frame.RelativeTime.TotalMilliseconds); // Data using (var dataStream = new MemoryStream()) { using (var dataWriter = new BinaryWriter(dataStream)) { dataWriter.Write(frame.BodyCount); dataWriter.Write(frame.FloorClipPlane.W); dataWriter.Write(frame.FloorClipPlane.X); dataWriter.Write(frame.FloorClipPlane.Y); dataWriter.Write(frame.FloorClipPlane.Z); int trackedBodyCount = 0; for (var i = 0; i < frame.BodyCount; i++) { if (RecordBody(frame.Bodies[i], dataWriter)) trackedBodyCount++; } // Reset frame data stream dataWriter.Flush(); dataStream.Position = 0; // Write FrameSize _writer.Write(dataStream.Length); // Write actual frame data dataStream.CopyTo(_writer.BaseStream); // Write end of frame marker _writer.Write(ReplayFrame.EndOfFrameMarker); System.Diagnostics.Debug.WriteLine(" (recorded {0} tracked bodies)", trackedBodyCount); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }); }
/// <summary> /// Used in "Manual" mode to record a single <c>BodyFrame</c> if /// the body frame data has already been retrieved from the frame. /// </summary> public void RecordFrame(BodyFrame frame, Body[] bodies) { if (!_isStarted) throw new InvalidOperationException("Cannot record frames unless the KinectRecorder is started."); if (frame != null) { var replayFrame = new ReplayBodyFrame(frame, bodies); if (MapDepthPositions) { replayFrame.MapDepthPositions(); } if (MapColorPositions) { replayFrame.MapColorPositions(); } _recordQueue.Enqueue(replayFrame); System.Diagnostics.Debug.WriteLine("+++ Enqueued Body Frame ({0})", _recordQueue.Count); } else { System.Diagnostics.Debug.WriteLine("!!! FRAME SKIPPED (Body in KinectRecorder)"); } }
private void bodyReplay_FrameArrived(ReplayBodyFrame frame) { if (BodyFrameArrived != null) BodyFrameArrived(this, new ReplayFrameArrivedEventArgs<ReplayBodyFrame> { Frame = frame }); }