Exemplo n.º 1
0
        ///<summary>
        /// Receive three skeleton point (3D position of a joint).
        /// Compute two vector, return the angle between them.
        /// If something is wrong return 0
        ///</summary>
        public static float getAngle(SkeletonPoint a, SkeletonPoint b, SkeletonPoint c, bool sign)
        {
            Vecto3Float[] vector = new Vecto3Float[2];
            //vector[0] = new Vecto3Float(b.X - c.X, b.Y - c.Y, b.Z - c.Z);
            vector[0] = new Vecto3Float(c.X - b.X, c.Y - b.Y, c.Z - b.Z);
            vector[1] = new Vecto3Float(a.X - b.X, a.Y - b.Y, a.Z - b.Z);

            float v0_magnitude = vector[0].magnitude();
            float v1_magnitude = vector[1].magnitude();
            if (v0_magnitude != 0.0 && v1_magnitude != 0.0)
            {
                vector[0].normalize();
                vector[1].normalize();

                float sign_f = sign ? -1f : 1f;
                double x = (double)vector[0].cross(vector[1]).magnitude();
                double y = (double)vector[0].dot(vector[1]);

                float theta = (float)Math.Atan2(sign_f * x, sign_f * y);

                return theta;// -theta;
            }
            else
            {
                return 0.0f;
            }
        }
        public static Vector3D TransPortVector(SkeletonPoint skel) //單點做世界座標轉換
        {
            Vector3D realPoint = new Vector3D(skel.X, skel.Y, skel.Z);
            realPoint = TransPortVector(realPoint);

            return realPoint;
        }   
        /// <summary>
        /// Deserialize a skeleton
        /// </summary>
        /// <param name="reader">Binary reader</param>
        /// <returns>Deserialized skeleton</returns>
        private kinect.Skeleton DeserializeSkeleton(BinaryReader reader)
        {
            kinect.Skeleton skeleton = new kinect.Skeleton();

            skeleton.ClippedEdges = (kinect.FrameEdges)reader.ReadInt32();

            kinect.SkeletonPoint point = new kinect.SkeletonPoint();
            point.X           = reader.ReadSingle();
            point.Y           = reader.ReadSingle();
            point.Z           = reader.ReadSingle();
            skeleton.Position = point;

            skeleton.TrackingId    = reader.ReadInt32();
            skeleton.TrackingState = (kinect.SkeletonTrackingState)reader.ReadInt32();

            int jointsCount = reader.ReadInt32();

            for (int index = 0; index < jointsCount; index++)
            {
                kinect.JointType jointType = (kinect.JointType)reader.ReadInt32();
                kinect.Joint     joint     = skeleton.Joints[jointType];

                joint.TrackingState = (kinect.JointTrackingState)reader.ReadInt32();

                point.X        = reader.ReadSingle();
                point.Y        = reader.ReadSingle();
                point.Z        = reader.ReadSingle();
                joint.Position = point;

                skeleton.Joints[joint.JointType] = joint;
            }

            return(skeleton);
        }
Exemplo n.º 4
0
        public static float DistanceXYBetweenPoints(SkeletonPoint point1, SkeletonPoint point2)
        {
            double d1 = point1.X - point2.X;
            double d2 = point1.Y - point2.Y;

            return (float)Math.Sqrt(d1 * d1 + d2 * d2);
        }
Exemplo n.º 5
0
 public Plane(SkeletonPoint p1, SkeletonPoint p2, SkeletonPoint p3)
 {
     a = (p2.Y - p1.Y) * (p3.Z - p1.Z) - (p3.Y - p1.Y) * (p2.Z - p1.Z);
     b = (p2.Z - p1.Z) * (p3.X - p1.X) - (p3.Z - p1.Z) * (p2.X - p1.X);
     c = (p2.X - p1.X) * (p3.Y - p1.Y) - (p3.X - p1.X) * (p2.Y - p1.Y);
     d = -(a * p1.X + b * p1.Y + c * p1.Z);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Maps a SkeletonPoint to lie within our render space and converts to Point
 /// </summary>
 /// <param name="sensor">Sensor to proyect point</param>
 /// <param name="skelpoint">point to map</param>
 /// <returns>mapped point</returns>
 public Point SkeletonPointToScreen(KinectSensor sensor, SkeletonPoint skelpoint)
 {
     // Convert point to depth space.
     // We are not using depth directly, but we do want the points in our 640x480 output resolution.
     DepthImagePoint depthPoint = sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);
     return new Point(depthPoint.X, depthPoint.Y);
 }
        public void AssignAnglesToSkeleton(Skeleton skeleton)
        {
            Hashtable angles = getAllAngles();

            foreach (JointType key in angles.Keys)
            {
                List<double> anglesInDouble = (List<double>)angles[key];

                SkeletonPoint point = new SkeletonPoint();

                if (!double.IsNaN(anglesInDouble[0]))
                {
                    point.X = (int)anglesInDouble[0];
                }
                if (!double.IsNaN(anglesInDouble[1]))
                {
                    point.Y = (int)anglesInDouble[1];
                }
                if (!double.IsNaN(anglesInDouble[2]))
                {
                    point.Z = (int)anglesInDouble[2];
                }

                var joint = skeleton.Joints[key];
                joint.Position = point;
                skeleton.Joints[key] = joint;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Calculates the angle of two rays that do not necessarily share a point
        /// </summary>
        /// <param name="ray1_1">first vector on first ray</param>
        /// <param name="ray1_2">second vector on first ray</param>
        /// <param name="ray2_1">first vector on second ray</param>
        /// <param name="ray2_2">second vector on second ray</param>
        /// <returns>angle in radians</returns>
        public static double AngleTo(this NUIVector ray1_1, NUIVector ray1_2, NUIVector ray2_1, NUIVector ray2_2)
        {
            NUIVector diff1 = ray1_2.Minus(ray1_1);
            NUIVector diff2 = ray2_2.Minus(ray2_1);

            return Math.Acos(diff1.DotProduct(diff2) / diff1.Length() / diff2.Length());
        }
Exemplo n.º 9
0
 public static bool comparePoint(SkeletonPoint a, SkeletonPoint b, float dif)
 {
     if (compareValue(a.X, b.X, dif) && compareValue(a.Y, b.Y, dif) && compareValue(a.Z, b.Z, dif))
         return true;
     else
         return false;
 }
Exemplo n.º 10
0
        public bool Detect(SkeletonPoint shoulderCenter, SkeletonPoint rightHandPoint, bool rightHandTracked,
                           SkeletonPoint leftHandPoint, bool leftHandTracked)
        {
            var rightHandInFront = rightHandTracked && (shoulderCenter.Z - rightHandPoint.Z >= MinZDistanceFromBody);
            var leftHandInFront = leftHandTracked && (shoulderCenter.Z - leftHandPoint.Z >= MinZDistanceFromBody);

            // Just one hand at minimal distance from Shoulder Center
            if (rightHandInFront ^ leftHandInFront)
            {
                SkeletonPoint handPoint;
                if (rightHandInFront)
                {
                    handPoint = rightHandPoint;
                    PanningHand = Hand.Right;
                }
                else
                {
                    handPoint = leftHandPoint;
                    PanningHand = Hand.Left;
                }

                if (!IsPanning)
                {
                    StartPan(handPoint);
                }

                RunPanning(handPoint);
            }
            else
            {
                StopZooming();
            }

            return IsPanning;
        }
Exemplo n.º 11
0
 public static SkeletonPoint vecMult(float coEffish, SkeletonPoint vec)
 {
     vec.X *= coEffish;
     vec.Y *= coEffish;
     vec.Z *= coEffish;
     return vec;
 }
Exemplo n.º 12
0
 public static SkeletonPoint vecSubt(SkeletonPoint a, SkeletonPoint b)
 {
     a.X -= b.X;
     a.Y -= b.Y;
     a.Z -= b.Z;
     return a;
 }
Exemplo n.º 13
0
 public static SkeletonPoint vecAdd(SkeletonPoint a, SkeletonPoint b)
 {
     a.X += b.X;
     a.Y += b.Y;
     a.Z += b.Z;
     return a;
 }
        public void Update(SkeletonPoint position, int updateId, long timestamp)
        {
            // Movement magnitude gets scaled by this amount in order to get the current activity metric
            const double DeltaScalingFactor = 10.0;

            // Controls how quickly new values of the metric displace old values. 1.0 means that new values
            // for metric immediately replace old values, while smaller decay amounts mean that old metric
            // values influence the metric for a longer amount of time (i.e.: decay more slowly).
            const double ActivityDecay = 0.1;

            var delta = new SkeletonPoint
            {
                X = position.X - this.LastPosition.X,
                Y = position.Y - this.LastPosition.Y,
                Z = position.Z - this.LastPosition.Z
            };

            double deltaLengthSquared = (delta.X * delta.X) + (delta.Y * delta.Y) + (delta.Z * delta.Z);
            double newMetric = DeltaScalingFactor * Math.Sqrt(deltaLengthSquared);

            this.ActivityLevel = ((1.0 - ActivityDecay) * this.ActivityLevel) + (ActivityDecay * newMetric);

            bool newIsActive = this.ActivityLevel >= ActivityMetricThreshold;

            if (newIsActive != this.IsActive)
            {
                this.IsActive = newIsActive;
                this.StateTransitionTimestamp = timestamp;
            }

            this.LastPosition = position;
            this.LastUpdateId = updateId;
        }
Exemplo n.º 15
0
 public static SkeletonPoint averagePoint(SkeletonPoint p1, int avgFactor)
 {
     p1.X = p1.X  / avgFactor;
     p1.Y = p1.Y  / avgFactor;
     p1.Z = p1.Z  / avgFactor;
     return p1;
 }
Exemplo n.º 16
0
        // add isGhost!
        public Person(SkeletonWrapper skeletonData, Color c, bool isGhost)
        {
            hashCode = HASH_CODE;
            HASH_CODE += 1;

            this.skeletonData = skeletonData;
            this.isGhost = isGhost;

            // Retrieve hand data.
            Joint rightHand = skeletonData.getRightHandJoint();
            Joint leftHand = skeletonData.getLeftHandJoint();

            // Retrieve torso data.
            if (isGhost == false)
            {
                Joint shoulderCenter = skeletonData.getCenterShoulderJoint();
                Joint spine = skeletonData.getSpineJoint();

                torsoTop = shoulderCenter.Position;
                torsoBottom = spine.Position;
            }

            leftHandPosition = leftHand.Position;
            rightHandPosition = rightHand.Position;

            this.color = c;

            canSpawnBoids = true;

            this.rightHand = new Hand(rightHand);
            this.leftHand = new Hand(leftHand);
        }
Exemplo n.º 17
0
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame == null)
                    return;

                var skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                skeletonFrame.CopySkeletonDataTo(skeletons);
                foreach (Skeleton skeletonData in skeletons)
                {
                    if (skeletonData.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Microsoft.Kinect.SkeletonPoint rightHandVec = skeletonData.Joints[JointType.HandRight].Position;
                        var depthPoint = _kinectSensor.MapSkeletonPointToDepth(rightHandVec, DepthImageFormat.Resolution640x480Fps30);

                        Size size = new Size(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);
                        Point OriginalPoint = new Point(depthPoint.X * size.Width / 640, depthPoint.Y * size.Height / 480);
                        Point effectivePoint = EffectivePoint(OriginalPoint, size, 1.6, 1.5);
                        //HandTop = depthPoint.Y * SystemParameters.PrimaryScreenHeight / 480;
                        //HandLeft = depthPoint.X * SystemParameters.PrimaryScreenWidth / 640;
                        HandTop = effectivePoint.Y / size.Height * 65535;
                        HandLeft = effectivePoint.X / size.Width * 65535;
                        mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, (int)HandLeft, (int)HandTop, 0, 0);//移动到需要点击的位置

                    }
                }
            }
        }
Exemplo n.º 18
0
        public virtual void Add(SkeletonPoint position, KinectSensor sensor)
        {
            GesturePoint entity = new GesturePoint { Position = Vector.ToVector(position), Time = DateTime.Now };
            GestureEntities.Add(entity);
            if (GestureCanvas != null)
            {
                entity.DisplayEllipse = new Ellipse
                {
                    Width = 4,
                    Height = 4,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment = VerticalAlignment.Top,
                    StrokeThickness = 2.0,
                    Stroke = new SolidColorBrush(DisplayColor),
                    StrokeLineJoin = PenLineJoin.Round
                };

                Point point = Tools.Convert(sensor, position);
                float x = (float)(point.X * GestureCanvas.ActualWidth);
                float y = (float)(point.Y * GestureCanvas.ActualHeight);
                Canvas.SetLeft(entity.DisplayEllipse, x - entity.DisplayEllipse.Width / 2);
                Canvas.SetTop(entity.DisplayEllipse, y - entity.DisplayEllipse.Height / 2);
                GestureCanvas.Children.Add(entity.DisplayEllipse);
            }
            if (GestureEntities.Count > WindowSize)
            {
                GesturePoint entryToRemove = GestureEntities[0];
                if (GestureCanvas != null)
                {
                    GestureCanvas.Children.Remove(entryToRemove.DisplayEllipse);
                }
                GestureEntities.Remove(entryToRemove);
            }
            LookForGesture();
        }
        public bool Detect(SkeletonPoint shoulderCenter, SkeletonPoint rightHandPoint, bool rightHandTracked,
                           SkeletonPoint leftHandPoint, bool leftHandTracked)
        {
            if (rightHandTracked == false || leftHandTracked == false)
            {
                StopZooming();
            }
                // Both hands at minimal distance from Shoulder Center
            else if (shoulderCenter.Z - rightHandPoint.Z >= MinZDistanceFromBody &&
                     shoulderCenter.Z - leftHandPoint.Z >= MinZDistanceFromBody)
            {
                if (!IsZooming)
                {
                    StartZoom(rightHandPoint, leftHandPoint);
                }

                RunZooming(rightHandPoint, leftHandPoint);
            }
            else
            {
                StopZooming();
            }

            return IsZooming;
        }
Exemplo n.º 20
0
        protected void DoPan(SkeletonPoint handPoint)
        {
            var mapExtentDeltaX = (_startExtent.XMax - _startExtent.XMin);
            var mapExtentDeltaY = (_startExtent.YMax - _startExtent.YMin);

            var relativeDeltaDistance = _startHandPoint.DistanceVectorFrom(handPoint, _map.ActualWidth, _map.ActualHeight);
            var deltaX = relativeDeltaDistance.X * mapExtentDeltaX;
            var deltaY = relativeDeltaDistance.Y * mapExtentDeltaY;

            var nextExtent = new Envelope
                                 {
                                     XMin = _startExtent.XMin + deltaX,
                                     XMax = _startExtent.XMax + deltaX,
                                     YMin = _startExtent.YMin - deltaY,
                                     YMax = _startExtent.YMax - deltaY
                                 };

            _map.Extent = nextExtent;

            if (KinectPanning != null)
            {
                var handCoordinate = handPoint.ToEsriWebMercatorMapPoint(_map);
                KinectPanning(handCoordinate.ToMapCoord());
            }
        }
 /// <summary>
 /// Initializes a new Gesture Status.
 /// </summary>
 public GestureStatus()
 {
     this.isMakingAFast = false;
     this.startPoint = new SkeletonPoint();
     this.endPoint = new SkeletonPoint();
     this.headPoint = new SkeletonPoint();
 }
Exemplo n.º 22
0
        public void Test90DegreeAngle()
        {
            Joint vertex = new Joint();
            Joint[] otherJoints = new Joint[2];

            SkeletonPoint sp = new SkeletonPoint();
            sp.X = 0.0F;
            sp.Y = 0.0F;
            sp.Z = 0.0F;
            vertex.Position = sp;

            Joint joint1 = new Joint();
            SkeletonPoint point = new SkeletonPoint();
            point.X = 0.0F;
            point.Y = 1.0F;
            point.Z = 0.0F;
            joint1.Position = point;

            Joint joint2 = new Joint();
            SkeletonPoint point2 = new SkeletonPoint();
            point2.X = 1.0F;
            point2.Y = 0.0F;
            point2.Z = 0.0F;
            joint2.Position = point2;

            otherJoints[0] = joint1;
            otherJoints[1] = joint2;

            Assert.AreEqual(90, JointAnalyzer.findAngle(vertex,otherJoints), "Angle should be 90 degrees");
        }
Exemplo n.º 23
0
 public UserActivityRecord(SkeletonPoint position, int updateId, long timestamp)
 {
     this.ActivityLevel = 0.0;
     this.LastPosition = position;
     this.LastUpdateId = updateId;
     this.IsActive = false;
     this.StateTransitionTimestamp = timestamp;
 }
Exemplo n.º 24
0
 /// <summary>
 /// creates an plane in front of the Kinect sensor with vector data
 /// </summary>
 /// <param name="ru">vector of the right upper corner</param>
 /// <param name="lu">vector of the left upper corner</param>
 /// <param name="rd">vector of the right lower corner</param>
 /// <param name="ld">vector of the left lower corner</param>
 public Plane(SkeletonPoint ru, SkeletonPoint lu, SkeletonPoint rd, SkeletonPoint ld)
 {
     right_up = ru;
     left_up = lu;
     right_down = rd;
     left_down = ld;
     coll = false;
 }
Exemplo n.º 25
0
 protected override void DoMapClick(SkeletonPoint handPoint)
 {
     Location mapPoint = handPoint.ToTelerikMapLocation(_map);
     if (KinectMapClick != null)
     {
         KinectMapClick(mapPoint.ToMapCoord());
     }
 }
Exemplo n.º 26
0
 public static SkeletonPoint AddPoints(SkeletonPoint refPoint1, SkeletonPoint refPoint2)
 {
     SkeletonPoint res = new SkeletonPoint();
     res.X = refPoint1.X + refPoint2.X;
     res.Y = refPoint1.Y + refPoint2.Y;
     res.Z = refPoint1.Z + refPoint2.Z;
     return res;
 }
Exemplo n.º 27
0
 public static Point CalculateMiddlePoint(SkeletonPoint point1, SkeletonPoint point2)
 {
     return new Point(
         GetMiddleValue(point1.X, point2.X),
         GetMiddleValue(point1.Y, point2.Y),
         GetMiddleValue(point1.Z, point2.Z)
     );
 }
Exemplo n.º 28
0
        public static double DistanceBetweenPoints(SkeletonPoint refPoint1, SkeletonPoint refPoint2)
        {
            double dx = Math.Abs(refPoint2.X - refPoint1.X);
            double dy = Math.Abs(refPoint2.Y - refPoint1.Y);
            double dz = Math.Abs(refPoint2.Z - refPoint1.Z);

            return Math.Sqrt(dx * dx + dy * dy + dz * dz);
        }
Exemplo n.º 29
0
 public override bool isMove(Dictionary<JointType, Joint> dict)
 {
     handPosition = dict[JointType.HandRight].Position;
     shoulderPosition = dict[JointType.ShoulderRight].Position;
     leftHandPosition = dict[JointType.HandLeft].Position;
     leftShoulderPosition = dict[JointType.ShoulderLeft].Position;
     return true;
 }
Exemplo n.º 30
0
 public static void findJoint(SkeletonPoint v,out float xd, out float yd)
 {
     ColorImagePoint temp = myK.MapSkeletonPointToColor(v, ColorImageFormat.RgbResolution640x480Fps30);
     xd = temp.X;
     yd = temp.Y;
     //xd = Math.Max(2, Math.Min(xd * 640, 637));
     //yd = Math.Max(2, Math.Min(yd * 480, 477));
 }
Exemplo n.º 31
0
 protected override void DoMapClick(SkeletonPoint handPoint)
 {
     var mapPoint = handPoint.ToEsriWebMercatorMapPoint(_map);
     if (KinectMapClick != null)
     {
         KinectMapClick(mapPoint.ToMapCoord());
     }
 }
 public SkeletonPoint ConvertPoint(SkeletonPoint point)
 {
     SkeletonPoint pt = new SkeletonPoint();
     pt.X = ScalePoint(point.X, bottomCenterPoint.X) + (float)ActiveRectangle.Width / 2 + (float)ActiveRectangle.X;
     pt.Y = (float)ActiveRectangle.Height - ScalePoint(point.Y, bottomCenterPoint.Y) + (float)ActiveRectangle.Y;
     pt.Z = ScalePoint(point.Z, bottomCenterPoint.Z);
     return pt;
 }
Exemplo n.º 33
0
        private float XYToDegrees(Microsoft.Kinect.SkeletonPoint p, Microsoft.Kinect.SkeletonPoint origin)
        {
            double deltaX = origin.X - p.X;
            double deltaY = (origin.Y - p.Y);

            double radAngle    = Math.Atan2(deltaY, deltaX);
            double degreeAngle = radAngle * 180.0 / Math.PI;

            return((float)(180.0 - degreeAngle));
        }
Exemplo n.º 34
0
        //This method is used to position the ellipses on the canvas
        //according to correct movements of the tracked joints.

        //IMPORTANT NOTE: Code for vector scaling was imported from the Coding4Fun Kinect Toolkit
        //available here: http://c4fkinect.codeplex.com/
        //I only used this part to avoid adding an extra reference.
        private void SetEllipsePosition(Ellipse ellipse, Joint joint)
        {
            Microsoft.Kinect.SkeletonPoint vector = new Microsoft.Kinect.SkeletonPoint();
            vector.X = ScaleVector(640, joint.Position.X);
            vector.Y = ScaleVector(480, -joint.Position.Y);
            vector.Z = joint.Position.Z;

            Joint updatedJoint = new Joint();

            updatedJoint = joint;
            updatedJoint.TrackingState = JointTrackingState.Tracked;
            updatedJoint.Position      = vector;

            Canvas.SetLeft(ellipse, updatedJoint.Position.X);
            Canvas.SetTop(ellipse, updatedJoint.Position.Y);
        }
        //This method is used to position the ellipses on the canvas
        //according to correct movements of the tracked joints.

        //IMPORTANT NOTE: Code for vector scaling was imported from the Coding4Fun Kinect Toolkit
        //available here: http://c4fkinect.codeplex.com/
        //I only used this part to avoid adding an extra reference.
        private void SetEllipsePosition(Ellipse ellipse, Joint joint, Joint joint2)
        {
            float xl, xr, bx, by, yl;

            Microsoft.Kinect.SkeletonPoint vector = new Microsoft.Kinect.SkeletonPoint();
            vector.X = ScaleVector(650, joint.Position.X);
            vector.Y = ScaleVector(580, -joint.Position.Y);
            vector.Z = joint.Position.Z;

            xl = vector.X;
            yl = vector.Y;

            Joint updatedJoint = new Joint();

            updatedJoint = joint;
            updatedJoint.TrackingState = JointTrackingState.Tracked;
            updatedJoint.Position      = vector;

            vector.X = ScaleVector(650, joint2.Position.X);
            vector.Y = ScaleVector(580, -joint.Position.Y);
            vector.Z = joint.Position.Z;

            xr = vector.X;

            Joint updatedJoint2 = new Joint();

            updatedJoint2 = joint2;
            updatedJoint2.TrackingState = JointTrackingState.Tracked;
            updatedJoint2.Position      = vector;

            by = yl - (xr - xl) / 2;
            if (xr > xl)
            {
                leftHand.Height = (xr - xl);
                bx = xl + 50;
            }
            else
            {
                leftHand.Height = (-xr + xl);
                bx = xl + 50;
            }
            leftHand.Width = leftHand.Height;


            Canvas.SetLeft(ellipse, bx);
            Canvas.SetTop(ellipse, by);
        }
Exemplo n.º 36
0
        /// <summary>
        /// Helper method to swap two joints in the skeleton when mirroring the avatar.
        /// </summary>
        /// <param name="skeleton">The skeleton to mirror.</param>
        /// <param name="left">The left joint type.</param>
        /// <param name="right">The right joint type.</param>
        private static void SwapJoints(Skeleton skeleton, JointType left, JointType right)
        {
            Joint jL = skeleton.Joints[left];
            Joint jR = skeleton.Joints[right];

            Microsoft.Kinect.SkeletonPoint tempPos = jL.Position;
            jL.Position = jR.Position;
            jR.Position = tempPos;

            JointTrackingState tempTs = jL.TrackingState;

            jL.TrackingState = jR.TrackingState;
            jR.TrackingState = tempTs;

            skeleton.Joints[left]  = jL;
            skeleton.Joints[right] = jR;
        }
Exemplo n.º 37
0
        public Joint SetPosition(Joint joint)
        {
            Microsoft.Kinect.SkeletonPoint vector = new Microsoft.Kinect.SkeletonPoint();
            vector.X = ScaleVector(640, joint.Position.X);
            vector.Y = ScaleVector(480, -joint.Position.Y);


            Joint updatedJoint = new Joint();

            updatedJoint = joint;
            updatedJoint.TrackingState = JointTrackingState.Tracked;
            updatedJoint.Position      = vector;
            return(updatedJoint);

            //Canvas.SetLeft(ellipse, updatedJoint.Position.X);
            //Canvas.SetTop(ellipse, updatedJoint.Position.Y);
        }
Exemplo n.º 38
0
        /// <summary>
        /// Maps a SkeletonPoint to lie within our render space and converts to Point
        /// </summary>
        /// <param name="skelpoint">point to map</param>
        /// <returns>mapped point</returns>
        public Point SkeletonPointToScreen(float x, float y, float z)
        {
            // Convert point to depth space.
            // We are not using depth directly, but we do want the points in our 640x480 output resolution.
            Microsoft.Kinect.SkeletonPoint skelPoint = new Microsoft.Kinect.SkeletonPoint()
            {
                X = x,
                Y = y,
                Z = z
            };
            ColorImagePoint point = _kinectSensor.CoordinateMapper.MapSkeletonPointToColorPoint(skelPoint, ColorImageFormat.RgbResolution640x480Fps30);

            return(new Point(point.X, point.Y));
            //ColorImagePoint depthPoint = _kinectSensor.CoordinateMapper.MapSkeletonPointToColorPoint(skelPoint, ColorImageFormat.RgbResolution640x480Fps30);
            //ColorImagePoint point = _kinectSensor.CoordinateMapper.MapDepthPointToColorPoint(DepthImageFormat.Resolution640x480Fps30, depthPoint, ColorImageFormat.InfraredResolution640x480Fps30);
            //return new Point(point.X, point.Y);
        }
Exemplo n.º 39
0
        //設定圖案位置
        private void SetEllipsePosition(Ellipse ellipse, Joint joint, bool isHighlighted)
        {
            //將3D 座標轉換成螢幕上大小,如640*320 的 2D 座標值
            Microsoft.Kinect.SkeletonPoint vector = new Microsoft.Kinect.SkeletonPoint();
            vector.X = ScaleVector(640, joint.Position.X);
            vector.Y = ScaleVector(480, -joint.Position.Y);
            vector.Z = joint.Position.Z; // Z值原封不動

            Joint updatedJoint = new Joint();

            updatedJoint = joint;
            updatedJoint.TrackingState = JointTrackingState.Tracked;
            updatedJoint.Position      = vector;

            //得到 2D座標值(X、Y)後,將值設定為圖案顯示的位置
            Canvas.SetLeft(ellipse, updatedJoint.Position.X);
            Canvas.SetTop(ellipse, updatedJoint.Position.Y);
        }
Exemplo n.º 40
0
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame == null)
                {
                    return;
                }

                var skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                skeletonFrame.CopySkeletonDataTo(skeletons);
                foreach (Skeleton skeletonData in skeletons)
                {
                    if (skeletonData.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Microsoft.Kinect.SkeletonPoint rightHandVec = skeletonData.Joints[JointType.HandRight].Position;
                        var depthPoint = _kinectSensor.MapSkeletonPointToDepth(rightHandVec, DepthImageFormat.Resolution640x480Fps30);
                        HandTop  = depthPoint.Y * this.MainStage.ActualHeight / 480;
                        HandLeft = depthPoint.X * this.MainStage.ActualWidth / 640;
                    }
                }
            }
        }
Exemplo n.º 41
0
 public DepthImagePoint MapFromSkeletonPoint(SkeletonPoint skeletonPoint);
 //
 // Summary:
 //     This method compares two skeleton point objects.
 //
 // Parameters:
 //   skeletonPoint:
 //     The SkeletonPoint to compare.
 //
 // Returns:
 //     It returns true if they are equal and false otherwise.
 public bool Equals(SkeletonPoint skeletonPoint);
Exemplo n.º 43
0
 private Vector3D ToVector(Microsoft.Kinect.SkeletonPoint Point)
 {
     return(new Vector3D(Point.X, Point.Y, Point.Z));
 }
Exemplo n.º 44
0
 //
 // Summary:
 //     Tests whether the SkeletonPoint has a known value.
 //
 // Parameters:
 //   skeletonPoint:
 //     The SkeletonPoint to test.
 //
 // Returns:
 //     Returns true if the Skeleton point has a known value, false otherwise.
 public static bool IsKnownPoint(SkeletonPoint skeletonPoint);
Exemplo n.º 45
0
 public ColorImagePoint MapSkeletonPointToColor(SkeletonPoint skeletonPoint, ColorImageFormat colorImageFormat);
Exemplo n.º 46
0
 public DepthImagePoint MapSkeletonPointToDepth(SkeletonPoint skeletonPoint, DepthImageFormat depthImageFormat);
Exemplo n.º 47
0
        //ProcessGestture tracks the  desired limbs and draws its postion on the screen
        private void ProcessGesture(Joint FootLeft)
        {
            Microsoft.Kinect.SkeletonPoint vector = new Microsoft.Kinect.SkeletonPoint();
            // if (cntr == 30) //This slows downs the number of readings,in order to control the mouse flicking
            // {
            // Note that the X & Y represents the vertical plane of the sensor
            // Z represents the depth or the prependicular distance from the sensor plan
            Joint LeftStore = FootLeft;


            vector.X          = FootLeft.Position.X;                                  //Gets the Feet postion  X-axis in meters
            vector.Z          = FootLeft.Position.Z;                                  ///Gets the Feet postion Z-axis in meters (depth: Patient distance from Sensor)
            vector.Y          = FootLeft.Position.Y;                                  //Gets the Feet postion  Y-axis in meters
            FootLeft.Position = vector;
            VX.Text           = Convert.ToString(Math.Round(FootLeft.Position.X, 3)); //Prints it on the patient screen
            VY.Text           = Convert.ToString(Math.Round(FootLeft.Position.Y, 3)); //Prints it on the patient screen
            VZ.Text           = Convert.ToString(Math.Round(FootLeft.Position.Z, 3)); //Prints it on the patient screen
            vector.X          = ScaleX(vector.X);                                     //Sends the postion to the scale function to be able //please check the function comments
            vector.Z          = ScaleZ(vector.Z);                                     // same as before
            vector.Y          = ScaleZ(vector.Y);                                     // same as before
            if (cntr > 0)
            {
                diffX = Math.Abs(vector.X) - Math.Abs(pX);       // Calculates difference between old & new reading
                diffZ = Math.Abs(vector.Z) - Math.Abs(pZ);       // Calculates difference between old & new reading
                if (diffX / pX > xPrcnt)
                {
                    vector.X = pX;                           // Calculates the % of the change, > pre-set % takes the old value
                }
                if (diffZ / pZ > zPrcnt)
                {
                    vector.Z = pZ;                           // Same
                }
                cntr += 1;
            }
            FootLeft.Position = vector;
            CursorX           = Convert.ToInt32(vector.X);//convert the float points 32 bit signed integear
            CursorZ           = Convert.ToInt32(vector.Z);
            CursorY           = -1 * Convert.ToInt32(vector.Y);
            ScreenW.Text      = Convert.ToString(CursorX);
            ScreenH.Text      = Convert.ToString(CursorZ);
            SetCursorPos(CursorX, CursorZ);
            pX = vector.X;      //Store old positions for smotthing
            pZ = vector.Z;      //Store old positions for smotthing
            pY = vector.Y;      //Store old positions for smotthing

            Thread.SpinWait(32);



            //These below controls the circles which indicates the postions of patient if its too noear or far
            if (MatrixMath.FootToFloor(FloorClipPlane, LeftStore) && !LeftFoot.SamePosition(LeftStore))
            {
                Mouseclick(CursorX, CursorZ);
                LeftFoot.setX(LeftStore.Position.X);
                LeftFoot.setZ(LeftStore.Position.Z);
                Debug.WriteLine("MouseClick");
                Debug.WriteLine(MatrixMath.FootToFloorVal(FloorClipPlane, FootLeft));
            }
            if (vector.Z < 265)
            {
                redsignal.Visibility    = Visibility.Visible;
                yellowsignal.Visibility = Visibility.Collapsed;
                greensignal.Visibility  = Visibility.Collapsed;
            }
            if (vector.Z > 265 & vector.Z < 435)
            {
                redsignal.Visibility    = Visibility.Collapsed;
                yellowsignal.Visibility = Visibility.Visible;
                greensignal.Visibility  = Visibility.Collapsed;
            }
            if (vector.Z > 435)
            {
                redsignal.Visibility    = Visibility.Collapsed;
                yellowsignal.Visibility = Visibility.Collapsed;
                greensignal.Visibility  = Visibility.Visible;
            }
            // cntr = 0;
            //  }
            //    cntr += 1;
        }