示例#1
0
        void SensorFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            var        sensor      = (KinectSensor)sender;
            var        sensorIndex = ActiveSensors.IndexOf(sensor);
            Skeleframe frame;

            using (var skeleFrame = e.OpenSkeletonFrame())
            {
                if (skeleFrame == null)
                {
                    return;
                }

                var timeDelta = skeleFrame.Timestamp - _lastTimeStamps[sensorIndex];
                _lastTimeStamps[sensorIndex] = skeleFrame.Timestamp;

                frame = new Skeleframe
                {
                    FloorClipPlane      = skeleFrame.FloorClipPlane,
                    SkeletonFrameNumber = skeleFrame.FrameNumber,
                    TimeStamp           = skeleFrame.Timestamp,
                    TimeDelta           = timeDelta,
                    SensorIndex         = sensorIndex,
                    Skeletons           = new Skeleton[skeleFrame.SkeletonArrayLength],
                    KinectId            = sensor.UniqueKinectId
                };
                skeleFrame.CopySkeletonDataTo(frame.Skeletons);

                lock (_frameQueue)
                {
                    _frameQueue.Enqueue(frame);
                    HasFrames = true;
                }
            }
        }
示例#2
0
        private List <Body> GetBodiesForFrame(Skeleframe frame)
        {
            List <Body> result = new List <Body>();

            if (!_sortedBodies.ContainsKey(frame.SensorIndex))
            {
                _sortedBodies[frame.SensorIndex] = new Dictionary <int, Body>();
            }

            var sx = _sortedBodies[frame.SensorIndex];

            for (var ix = 0; ix < frame.Skeletons.Length; ix++)
            {
                if (frame.Skeletons[ix].TrackingId != 0)
                {
                    var body = GetBodyForSkeleton(sx, frame.Skeletons[ix]);
                    body.SensorIndex = frame.SensorIndex;
                    result.Add(body);
                }
            }

            return(result);
        }