コード例 #1
0
        void IGestureRecognizer.UpdateJointData(Dictionary<Microsoft.Kinect.JointType, Point3D> jointData)
        {
            if (_recoginized)
                return;

            Point3D rightHand = jointData[JointType.HandRight];
            //Debug.WriteLine("z = " + rightHand.Z);
            Point3D hip = jointData[JointType.HipCenter];

            if (!_gestureStart)
            {
                // if the guesture has not started, and we found the right hand
                // is about the height of the right shoulder, and it's Z is also
                // close to the right shoulder, we will say the gesture starts.
                //double zDiff = lastRightHandPos != null ? lastRightHandPos.Z - rightHand.Z : 0;
                double yDiff = lastRightHandPos != null ? lastRightHandPos.Y - rightHand.Y : 0;
                //Debug.WriteLine("zDiff = " + zDiff);
                if (Math.Abs(hip.Y - rightHand.Y) < 0.1)
                {
                    //Debug.WriteLine("\n*** START ***");
                    _gestureStart = true;
                    startRightHandPos = rightHand;
                    totalDis = 0.0;
                }
            }
            else
            {
                totalDis += Math.Abs(startRightHandPos.Y - rightHand.Y);

                // the gesture has started, we need to track the hand position
                // to see if the guesture has completed.

                if (startRightHandPos.Y > rightHand.Y)
                {
                    //Debug.WriteLine("=== ABORT!");
                    _gestureStart = false;

                    totalDis = 0.0;
                    return;
                }

                if (totalDis > 0.5)
                {
                    _recoginized = true;
                    //Debug.WriteLine("\n!!!! RECOGNIZED!!! !!!");
                    //totalDis = 0.0;
                }
            }
            lastRightHandPos = rightHand;
        }
コード例 #2
0
 public double Dist(Point3D p)
 {
     return Math.Sqrt(Math.Pow(_x - p.X, 2) +
                      Math.Pow(_y - p.Y, 2) +
                      Math.Pow(_z - p.Z, 2));
 }
コード例 #3
0
 public static double Dist(Point3D p1, Point3D p2)
 {
     return Math.Sqrt(Math.Pow(p1.X - p2.X, 2) +
                      Math.Pow(p1.Y - p2.Y, 2) +
                      Math.Pow(p1.Z - p2.Z, 2));
 }
コード例 #4
0
        // Normalize all joint data by setting shoulder center to be origin
        // and shoulder width to be 1.0.
        private Dictionary<JointType, Point3D> NormalizeJoints(Skeleton sk)
        {
            Dictionary<JointType, Point3D> normalizedJointData = new Dictionary<JointType, Point3D>();

            // Make all joints' position relative to the shoulder center
            SkeletonPoint shouldCenter = sk.Joints[JointType.ShoulderCenter].Position;
            foreach (JointType jointType in Enum.GetValues(typeof(JointType)).Cast<JointType>())
            {
                Point3D newPoint = new Point3D();
                normalizedJointData.Add(jointType, newPoint);
                newPoint.X = sk.Joints[jointType].Position.X - shouldCenter.X;
                newPoint.Y = sk.Joints[jointType].Position.Y - shouldCenter.Y;
                newPoint.Z = sk.Joints[jointType].Position.Z - shouldCenter.Z;
            }

            // Normalize the distance between each point and the shoulder center
            double shouldWidth = Point3D.Dist(sk.Joints[JointType.ShoulderLeft].Position,
                                              sk.Joints[JointType.ShoulderRight].Position);
            foreach (JointType jointType in Enum.GetValues(typeof(JointType)).Cast<JointType>())
            {
                Point3D p = normalizedJointData[jointType];
                p.X /= shouldWidth;
                p.Y /= shouldWidth;
                p.Z /= shouldWidth;
            }

            return normalizedJointData;
        }