Пример #1
0
        /**
         * Listener function, recieves the frames from the kinect sensor, and identifies the type of frame returned
         * @method _reader_MultiSourceFrameArrived
         * @param {Object} sender
         * @param {MultiSourceFrameArrivedEventArgs} e
         * @private
         */
        private static void _reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            // Get a reference to the multi-frame
            MultiSourceFrame reference = e.FrameReference.AcquireFrame();

            // if returned frame is a colourframe, return the colour frame blob
            using (ColorFrame frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == Mode.Color)
                    {
                        // serialize the data
                        var blob = frame.Serialize();

                        foreach (var socket in _clients)
                        {
                            socket.Send(blob);
                        }
                    }
                }
            }

            // if returned frame is a depthframe, return the depth frame blob
            using (DepthFrame frame = reference.DepthFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (_mode == Mode.Depth)
                    {
                        // serialize the data
                        var blob = frame.Serialize();

                        foreach (var socket in _clients)
                        {
                            socket.Send(blob);
                        }
                    }
                }
            }

            // If returned frame is a skeletal/body frame,populate the bodies in the frame to a list and return the result through the socket
            using (BodyFrame frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    frame.GetAndRefreshBodyData(_skeletons);

                    // fetch the bodies monitored in the frame
                    var users = _skeletons.Where(s => s.IsTracked == true).ToList();

                    if (users.Count > 0)
                    {
                        // reialize the data to be returneed
                        string json = users.Serialize(_coordinateMapper, _mode);

                        foreach (var socket in _clients)
                        {
                            socket.Send(json);
                        }
                    }
                }
            }
        }