Beispiel #1
0
        protected virtual void OnKinectEventTriggered(KinectEventArgs e)
        {
            EventHandler <KinectEventArgs> handler = KinectEventTriggered;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #2
0
        //Method for linking an specific tracked body with the assigned tracking ID at the same frame
        //In case the saved matching ID is different from the current tracking ID, the method tries to get device control back
        private Body FindBodyWithTrackingId(BodyFrame bodyFrame, ulong trackingId)
        {
            Body result = null;

            Body[] bodies = new Body[bodyFrame.BodyCount];
            bodyFrame.GetAndRefreshBodyData(bodies);

            foreach (var body in bodies)
            {
                if (body.IsTracked)
                {
                    if (body.TrackingId == trackingId)
                    {
                        if (getControlBack == 0)
                        {
                            result = body;
                            break;
                        }
                        else
                        {
                            if (timingFrames < 331) //The getting connection back procedure listens to the getting back control gesture for 10 seconds
                            {
                                if (body.HandRightState == HandState.Closed)
                                {
                                    if (flag < 301)
                                    {
                                        if (flag < 300)
                                        {
                                            Console.WriteLine("{0:D}", flag + 1);
                                        }
                                        flag++;      //In case it detects the getting control back gesture increases the recognition counter until gets back device control or loses it
                                    }
                                    if (flag == 300) //In case it achieves the required detection time, it fires the device control method again an restart the involved properties
                                    {
                                        Console.WriteLine("Control returned");
                                        matchingId     = 0;
                                        flag           = 0;
                                        getControlBack = 0;
                                        timingFrames   = 0;
                                        break;
                                    }
                                }
                                timingFrames++;
                            }
                            if (timingFrames >= 331) //Otherwise, it fires the device security state method
                            {
                                Console.WriteLine("Time Elapsed, device returning to security state");
                                matchingId     = 0;
                                flag           = 0;
                                getControlBack = 0;
                                timingFrames   = 0;
                                KinectEventArgs args = new KinectEventArgs();
                                args.KinectEvent = KinectEvent.UserControlLost;
                                OnKinectEventTriggered(args);
                                break;
                            }
                        }
                    }
                }
            }
            return(result);
        }