Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            //get ip address of local machine, may not work if virtual machine installed (adds network adapter)
            IPHostEntry host;
            string localIP = "?";
            currentIDAssociation = null;
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily.ToString() == "InterNetwork")
                {
                    localIP = ip.ToString();
                }
            }
            ServerTextBox.Text = localIP;

            //update rule display on UI
            lblCalibrationOrientation.Content = "Change in Orientation: " + translateRule.changeInOrientation;
            lblCalibrationPoint.Content = "dX, dZ: " + translateRule.dX + ", " + translateRule.dZ;
            lblCalibrationTranslation.Content = "xTran, zTran: " + translateRule.xSpace + ", " + translateRule.zSpace;
            lblCalibrationStartingLocation.Content = "Starting Location: " + translateRule.startingLocation.X + ", "
                + translateRule.startingLocation.Y + ", " + translateRule.startingLocation.Z;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the body frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;

            try
            {
                BodyFrame frame = frameReference.AcquireFrame();

                if (frame != null)
                {
                    List<Person> persons = new List<Person>();

                    // BodyFrame is IDisposable
                    using (frame)
                    {
                        // render skeleton 
                        this.framesSinceUpdate++;

                        this.Dispatcher.Invoke(new Action(delegate()
                        {
                            skeletonRenderer2.renderBodyFrame(e,currentIDAssociation);
                        }));

                        frame.GetAndRefreshBodyData(this.bodies);

                        foreach (Body body in this.bodies)
                        {
                            if (body.IsTracked)
                            {
                                float x = body.Joints[JointType.SpineBase].Position.X;
                                float y = body.Joints[JointType.SpineBase].Position.Y;
                                float z = body.Joints[JointType.SpineBase].Position.Z;

                                Joint handLeft = body.Joints[JointType.HandLeft];
                                Joint handRight = body.Joints[JointType.HandRight];
                                //Console.WriteLine("State: " + body.Joints[JointType.HandLeft].TrackingState + " position: " + body.Joints[JointType.HandLeft].Position.X + "," + body.Joints[JointType.HandLeft].Position.Y + "," + body.Joints[JointType.HandLeft].Position.Z);
                                /*
                                double x1 = body.JointOrientations[JointType.SpineBase].Orientation.X;
                                double y1 = body.JointOrientations[JointType.SpineBase].Orientation.Y;
                                double z1 = body.JointOrientations[JointType.SpineBase].Orientation.Z;
                                double w1 = body.JointOrientations[JointType.SpineBase].Orientation.W;
                                // convert face rotation quaternion to Euler angles in degrees
                                double yawD, pitchD, rollD;
                                pitchD = Math.Atan2(2 * ((y1 * z1) + (w1 * x1)), (w1 * w1) - (x1 * x1) - (y1 * y1) + (z1 * z1)) / Math.PI * 180.0;
                                yawD = Math.Asin(2 * ((w1 * y1) - (x1 * z1))) / Math.PI * 180.0;
                                //yawD = Math.Asin(2 * ((x1 * y1) + (w1 * z1))) / Math.PI * 180.0;
                                rollD = Math.Atan2(2 * ((x1 * y1) + (w1 * z1)), (w1 * w1) + (x1 * x1) - (y1 * y1) - (z1 * z1)) / Math.PI * 180.0;
                                // Math convertion from quaternion to euler: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
                                // Found quaternion resource: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#Foreword__rotation_VS_orientation
                                //Console.WriteLine(body.TrackingId + " ori: " + pitchD + " - " + yawD + " - " + rollD);//body.JointOrientations[JointType.SpineBase].Orientation.X + "," + body.JointOrientations[JointType.SpineBase].Orientation.Y + "," + body.JointOrientations[JointType.SpineBase].Orientation.Z + " w: " + body.JointOrientations[JointType.SpineBase].Orientation.W);
                                */
                                
                                
                                //body.JointOrientations
                                /*LightBuzz.Vitruvius.GestureController gestureController; //gesture controller
                                gestureController = new LightBuzz.Vitruvius.GestureController(LightBuzz.Vitruvius.GestureType.All);
                                gestureController.GestureRecognized += GestureController_GestureRecognized;
                                */

                                //double y = skeleton.getHeight() / 2;
                                //Console.WriteLine("X: " + x + "     Y: " + y + "     Z: " + z);

                                //update body gestures
                                gestureController.Update(body);
                                String gesture = null;
                                try 
                                {
                                    if (gestureList.Keys.Contains(body.TrackingId))
                                    {
                                        gesture = gestureList[body.TrackingId];
                                        gestureList.Remove(body.TrackingId);
                                    }
                                }
                                catch(Exception)
                                {
                                    Console.WriteLine("failed to grab gesture from list");
                                }

                                Person person;
                                
                                

                                if (AcceptableNumInferredJoints(body.Joints) && AcceptableNumTrackedJoints(body.Joints)) //deemed accurate enough, send as "tracked"
                                {
                                    person = new Person(body.TrackingId.ToString(), applyTranslateRule(new Point3D(x, y, z), translateRule), gesture, Person.trackingStates.tracked,handLeft,handRight, body.HandLeftState, body.HandRightState, body.HandLeftConfidence, body.HandRightConfidence);
                                }
                                else //not accurate enough, send as "inferred"
                                {
                                    person = new Person(body.TrackingId.ToString(), applyTranslateRule(new Point3D(x, y, z), translateRule), gesture, Person.trackingStates.inferred, handLeft, handRight, body.HandLeftState, body.HandRightState, body.HandLeftConfidence, body.HandRightConfidence);
                                }
                                
                                //Console.WriteLine("X: " + person.location.X + "     Y: " + person.location.Y + "     Z: " + person.location.Z);
                                persons.Add(person);
                                //translateRule.changeInOrientation = translateRule.changeInOrientation * -1;
                            }
                        }// after loop through each skeleton. 
                       
                    }
                    if (socket != null)
                    {
                        if (socket.IsConnected) //add check for isConnected
                        {
                            socket.Emit("personUpdate", persons, null, (callback) => {
                                SODMessage assocations = new SODMessage(callback);
                                currentIDAssociation = assocations;
                                
                            });
                        }
                    }
                    else
                    {
                        Console.WriteLine("Socket not connected.");
                    }
                   

                }
            }
            catch (Exception)
            {
                // ignore if the frame is no longer available
            }
        }