Ejemplo n.º 1
0
        public KinectReplay(Stream stream)
        {
            this.stream = stream;
            reader      = new BinaryReader(stream);

            synchronizationContext = SynchronizationContext.Current;

            KinectRecordOptions options = (KinectRecordOptions)reader.ReadInt32();

            if ((options & KinectRecordOptions.Color) != 0)
            {
                colorReplay = new ReplaySystem <ReplayColorImageFrame>();
            }
            if ((options & KinectRecordOptions.Depth) != 0)
            {
                depthReplay = new ReplaySystem <ReplayDepthImageFrame>();
            }
            if ((options & KinectRecordOptions.Skeletons) != 0)
            {
                skeletonReplay = new ReplaySystem <ReplaySkeletonFrame>();
            }

            while (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                KinectRecordOptions header = (KinectRecordOptions)reader.ReadInt32();
                switch (header)
                {
                case KinectRecordOptions.Color:
                    colorReplay.AddFrame(reader);
                    break;

                case KinectRecordOptions.Depth:
                    depthReplay.AddFrame(reader);
                    break;

                case KinectRecordOptions.Skeletons:
                    skeletonReplay.AddFrame(reader);
                    break;
                }
            }
        }
        /// <summary>
        /// Creates a replayer from stream data. Disposes the stream after reading all the data.
        /// </summary>
        /// <param name="stream"></param>
        public KinectAllFramesReplay(Stream stream)
        {
            synchronizationContext = SynchronizationContext.Current;

            reader = new BinaryReader(stream);

            kinectParams = ReadCoordinateMapperParams(reader);
            ColorNominalFocalLengthInPixels = reader.ReadSingle();
            DepthNominalFocalLengthInPixels = reader.ReadSingle();

            var options = (KinectRecordOptions)reader.ReadInt32();

            if (!IsValidOptions(options))
            {
                throw new Exception(String.Format("Not all streams are recorded. Record option = {0}",
                                                  options));
            }

            // Reads all the frames.
            while (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                allFramesReplay.AddFrame(reader);
            }
        }