Example #1
0
        private void Initialize()
        {
            if (IsInitialized)
            {
                return;
            }

            //loop through all the Kinects attached to this PC, and start the first that is connected without an error.
            if (KinectSensorDefault == null)
            {
                var msg = new KinectMessage(MessageType.Error,
                                            "Uexpected error. API call to KinectSensorDefault.GetDefault() return null");
                EnqueueKinectMessage(msg);

                throw new Exception(msg.Data);
            }

            // open the reader for the body frames
            //if (MultiSourceFrameReader == null)
            //{
            MultiSourceFrameReader =
                KinectSensorDefault.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Depth |
                                                               FrameSourceTypes.BodyIndex);
            MultiSourceFrameReader.MultiSourceFrameArrived -= MultiSourceFrameReaderOnMultiSourceFrameArrived;
            MultiSourceFrameReader.MultiSourceFrameArrived += MultiSourceFrameReaderOnMultiSourceFrameArrived;
            //}

            IsInitialized = true;
        }
Example #2
0
        protected void SendKinectMessageKeepAlive(object source, ElapsedEventArgs e)
        {
            if (Callback == null)
            {
                return;
            }

            KinectMessage kinectMessage = null;

            var channelState = ((IChannel)Callback).State;

            kinectMessage = new KinectMessage(MessageType.Information, "KeepAlive");
            if (channelState == CommunicationState.Opened)
            {
                try
                {
                    Callback.SendKinectMessage(kinectMessage.CreateBinaryMessage());
                }
                catch (Exception)
                {
                    _keepAliveFaulted      = true;
                    KeepAliveTimer.Enabled = false;
                    Console.WriteLine("Error sending keep-alive message.");
                    return;
                    //throw new FaultException<Exception>(new Exception("Client disconnected or unknown error."));
                }
            }
            else
            {
                _keepAliveFaulted      = true;
                KeepAliveTimer.Enabled = false;
            }
        }
Example #3
0
        protected override void MultiSourceFrameReaderOnMultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            using (var bodyFrame = reference.BodyFrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (_bodies == null)
                    {
                        _bodies = new Body[bodyFrame.BodyCount];
                    }

                    // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                    // As long as those body objects are not disposed and not set to null in the array,
                    // those body objects will be re-used.

                    bodyFrame.GetAndRefreshBodyData(this._bodies);


                    foreach (var body in Enumerable.Where <Body>(_bodies, body => body.IsTracked))
                    {
                        var handPositionMsg = new KinectMessage(string.Empty)
                        {
                            MessageType = MessageType.HandPosition,
                            LeftHand    = GetCoordinatesFromJoint(body.Joints[JointType.HandLeft]),
                            RightHand   = GetCoordinatesFromJoint(body.Joints[JointType.HandRight])
                        };


                        if (handPositionMsg.LeftHand.Item1 != 0 ||
                            handPositionMsg.LeftHand.Item2 != 0 ||
                            handPositionMsg.RightHand.Item1 != 0 ||
                            handPositionMsg.RightHand.Item2 != 0
                            )
                        {
                            EnqueueKinectMessage(handPositionMsg);
                        }
                    }
                }
            }
        }
Example #4
0
 protected void EnqueueKinectMessage(KinectMessage message)
 {
     NextKinectMessage = message;
 }