Beispiel #1
0
        /// <summary>
        /// Constructs a body adapter from a serialized version
        /// </summary>
        /// <param name="body"></param>
        public KinectBody(KGP.Serialization.Body.KinectBodyInternal body)
        {
            body.Validate(); //This will check preconditions to make sure we have a valid construct

            this.clippedEdges        = body.ClippedEdges;
            this.handLeftConfidence  = body.HandLeftConfidence;
            this.handLeftState       = body.HandLeftState;
            this.handRightConfidence = body.HandRightConfidence;
            this.handRightState      = body.HandRightState;
            this.isRestricted        = body.IsRestricted;
            this.isTracked           = body.IsTracked;

            Dictionary <JointType, JointOrientation> orientations = new Dictionary <JointType, JointOrientation>();
            Dictionary <JointType, Joint>            jointsDic    = new Dictionary <JointType, Joint>();

            for (int i = 0; i < body.Joints.Length; i++)
            {
                var joint = body.Joints[i];
                orientations.Add(joint.JointType, body.JointOrientations[i]);
                jointsDic.Add(joint.JointType, joint);
            }

            this.joints            = jointsDic;
            this.jointOrientations = orientations;

            this.lean = body.Lean;
            this.leanTrackingState = body.LeanTrackingState;
            this.trackingId        = body.TrackingId;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomBody"/> class.
        /// </summary>
        public CustomBody()
        {
            _clippedEdges = FrameEdges.None;

            _handLeftConfidence = TrackingConfidence.Low;
            _handLeftState = HandState.Unknown;
            _handRightConfidence = TrackingConfidence.Low;
            _handRightState = HandState.Unknown;
            _isDisposed = false;
            _isRestricted = false;
            _isTracked = false;

            _joints = new Dictionary<JointType, IJoint>();
            _jointOrientations = new Dictionary<JointType, IJointOrientation>();
            foreach (var jointType in CustomJointType.AllJoints)
            {
                _joints.Add(jointType, new CustomJoint(jointType));
                _jointOrientations.Add(jointType, new CustomJointOrientation(jointType));
            }

            _lean = new PointF();

            _leanTrackingState = TrackingState.NotTracked;
            _trackingId = ulong.MaxValue;
            _hasMappedDepthPositions = false;
            _hasMappedColorPositions = false;
        }
Beispiel #3
0
        public OscMessage BuildHandMessage(Body body, string key, HandState state, TrackingConfidence confidence)
        {
            var address = String.Format("/bodies/{0}/hands/{1}", body.TrackingId, key);

            //System.Diagnostics.Debug.WriteLine(address);
            return(new OscMessage(address, state.ToString(), confidence.ToString()));
        }
Beispiel #4
0
	private void GetHandState(OVRPlugin.Step step)
	{
		if (OVRPlugin.GetHandState(step, (OVRPlugin.Hand)HandType, ref _handState))
		{
			IsTracked = (_handState.Status & OVRPlugin.HandStatus.HandTracked) != 0;
			IsSystemGestureInProgress = (_handState.Status & OVRPlugin.HandStatus.SystemGestureInProgress) != 0;
			IsPointerPoseValid = (_handState.Status & OVRPlugin.HandStatus.InputStateValid) != 0;
			PointerPose.localPosition = _handState.PointerPose.Position.FromFlippedZVector3f();
			PointerPose.localRotation = _handState.PointerPose.Orientation.FromFlippedZQuatf();
			HandScale = _handState.HandScale;
			HandConfidence = (TrackingConfidence)_handState.HandConfidence;

			IsDataValid = true;
			IsDataHighConfidence = IsTracked && HandConfidence == TrackingConfidence.High;
		}
		else
		{
			IsTracked = false;
			IsSystemGestureInProgress = false;
			IsPointerPoseValid = false;
			PointerPose.localPosition = Vector3.zero;
			PointerPose.localRotation = Quaternion.identity;
			HandScale = 1.0f;
			HandConfidence = TrackingConfidence.Low;

			IsDataValid = false;
			IsDataHighConfidence = false;
		}
	}
Beispiel #5
0
        public BodyData(BinaryReader reader, byte kinectId)
        {
            this.kinectId         = kinectId;
            trackingId            = 0;
            position              = Vector3.zero;
            trackingState         = 0;
            spineMidPosition      = Vector3.zero;
            spineMidState         = 0;
            spineShoulderPosition = Vector3.zero;
            spineShoulderState    = 0;

            headPosition = Vector3.zero;
            headState    = 0;

            handLeftState         = HandState.NotTracked;
            handLeftConfidence    = TrackingConfidence.Low;
            handLeftTrackingState = TrackingState.NotTracked;
            handLeftPosition      = Vector3.zero;

            handRightState         = HandState.NotTracked;
            handRightConfidence    = TrackingConfidence.Low;
            handRightTrackingState = TrackingState.NotTracked;
            handRightPosition      = Vector3.zero;
            valid = true;

            Deserialize(reader, kinectId);
        }
Beispiel #6
0
    void DrawHandGizmo(Vector3 position, HandState handState, TrackingConfidence confidence, TrackingState trackingState)
    {
        Color trackingColor = confidence == TrackingConfidence.High ? Color.green : Color.yellow;

        switch (handState)
        {
        case HandState.Unknown:
            Gizmos.color = trackingColor;
            Gizmos.DrawWireSphere(position, 0.15f);
            break;

        case HandState.Closed:
            Gizmos.color = trackingColor;
            Gizmos.DrawWireCube(position, Vector3.one * 0.3f);
            break;

        case HandState.Open:
            Gizmos.color = trackingColor;
            Gizmos.DrawWireSphere(position, 0.3f);
            break;

        case HandState.Lasso:
            Gizmos.color = Color.blue;
            Gizmos.DrawWireCube(position + new Vector3(0, 0.3f, 0), new Vector3(0.3f, 0.6f, 0.3f));
            break;

        case HandState.NotTracked:
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(position, 0.3f);
            break;
        }
    }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomBody"/> class.
        /// </summary>
        public CustomBody()
        {
            _clippedEdges = FrameEdges.None;

            _handLeftConfidence  = TrackingConfidence.Low;
            _handLeftState       = HandState.Unknown;
            _handRightConfidence = TrackingConfidence.Low;
            _handRightState      = HandState.Unknown;
            _isDisposed          = false;
            _isRestricted        = false;
            _isTracked           = false;

            _joints            = new Dictionary <JointType, IJoint>();
            _jointOrientations = new Dictionary <JointType, IJointOrientation>();
            foreach (var jointType in JointTypeEx.AllJoints)
            {
                _joints.Add(jointType, new CustomJoint(jointType));
                _jointOrientations.Add(jointType, new CustomJointOrientation(jointType));
            }

#if NETFX_CORE
            _lean = new Point();
#else
            _lean = new PointF();
#endif
            _leanTrackingState       = TrackingState.NotTracked;
            _trackingId              = ulong.MaxValue;
            _hasMappedDepthPositions = false;
            _hasMappedColorPositions = false;
        }
        public void Update(TrackingConfidence leftConfidence, HandState leftHand, TrackingConfidence rightConfidence, HandState rightHand)
        {
            if ( leftConfidence == TrackingConfidence.High && leftHand == HandState.Closed )
            {
                if (!this.HasLeftHandWeapon)
                {
                    this.LeftHandWeaponIndex = this.selectRandomWeapon();
                    this.HasLeftHandWeapon = true;
                }
            }
            else
            {
                this.HasLeftHandWeapon = false;
                this.LeftHandWeaponIndex = -1;
            }

            if (rightConfidence == TrackingConfidence.High && rightHand == HandState.Closed)
            {
                if (!this.HasRightHandWeapon)
                {
                    this.RightHandWeaponIndex = this.selectRandomWeapon();
                    this.HasRightHandWeapon = true;
                }
            }
            else
            {
                this.HasRightHandWeapon = false;
                this.RightHandWeaponIndex = -1;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Constructs a body adapter from a serialized version
        /// </summary>
        /// <param name="body"></param>
        public KinectBody(KGP.Serialization.Body.KinectBodyInternal body)
        {
            body.Validate(); //This will check preconditions to make sure we have a valid construct

            this.clippedEdges = body.ClippedEdges;
            this.handLeftConfidence = body.HandLeftConfidence;
            this.handLeftState = body.HandLeftState;
            this.handRightConfidence = body.HandRightConfidence;
            this.handRightState = body.HandRightState;
            this.isRestricted = body.IsRestricted;
            this.isTracked = body.IsTracked;

            Dictionary<JointType, JointOrientation> orientations = new Dictionary<JointType, JointOrientation>();
            Dictionary<JointType, Joint> jointsDic = new Dictionary<JointType,Joint>();
            for (int i = 0; i < body.Joints.Length;i++)
            {
                var joint = body.Joints[i];
                orientations.Add(joint.JointType, body.JointOrientations[i]);
                jointsDic.Add(joint.JointType, joint);

            }

            this.joints = jointsDic;
            this.jointOrientations =orientations;

            this.lean = body.Lean;
            this.leanTrackingState = body.LeanTrackingState;
            this.trackingId = body.TrackingId;
        }
Beispiel #10
0
        private string GetTrackingConfidence(TrackingConfidence confidence)
        {
            switch (confidence)
            {
            case TrackingConfidence.High: return("high");
            }

            return("low");
        }
        public Data(double xPos, double yPos, MouseControlState state, double xHand, double yHand, HandState handState, TrackingConfidence trackingConfidence, TrackingState trackingState)
        {
            XHand          = xHand;
            YHand          = yHand;
            HandState      = handState;
            HandConfidence = trackingConfidence;
            TrackingState  = trackingState;

            XPos  = xPos;
            YPos  = yPos;
            State = state;
        }
Beispiel #12
0
 double TrackingConfidenceToValue(TrackingConfidence c)
 {
     if (c == TrackingConfidence.High)
     {
         return(1);
     }
     if (c == TrackingConfidence.Low)
     {
         return(0);
     }
     return(0.5);
 }
Beispiel #13
0
        /// <summary>
        /// Updates hand state ellipses depending on tracking state and it's confidence.
        /// </summary>
        /// <param name="ellipse">ellipse representing hand state</param>
        /// <param name="handState">open, closed, or lasso</param>
        /// <param name="trackingConfidence">confidence of hand state</param>
        /// <param name="point">location of hand joint</param>
        private void UpdateHand(Ellipse ellipse, HandState handState, TrackingConfidence trackingConfidence, Point point)
        {
            ellipse.Fill = new SolidColorBrush(this.HandStateToColor(handState));

            // draw handstate ellipse based on tracking confidence
            ellipse.Width      = ellipse.Height = (trackingConfidence == TrackingConfidence.Low) ? LowConfidenceHandSize : HighConfidenceHandSize;
            ellipse.Visibility = Windows.UI.Xaml.Visibility.Visible;

            // don't draw handstate if hand joints are not tracked
            if (!double.IsInfinity(point.X) && !double.IsInfinity(point.Y))
            {
                Canvas.SetLeft(ellipse, point.X - (ellipse.Width / 2));
                Canvas.SetTop(ellipse, point.Y - (ellipse.Width / 2));
            }
        }
Beispiel #14
0
 /// <summary>
 /// Constructs a body adapter from a kinect sdk body
 /// </summary>
 /// <param name="body">Body from Kinect SDK</param>
 public KinectBody(Microsoft.Kinect.Body body)
 {
     this.clippedEdges = body.ClippedEdges;
     this.handLeftConfidence = body.HandLeftConfidence;
     this.handLeftState = body.HandLeftState;
     this.handRightConfidence = body.HandRightConfidence;
     this.handRightState = body.HandRightState;
     this.isRestricted = body.IsRestricted;
     this.isTracked = body.IsTracked;
     this.jointOrientations = body.JointOrientations;
     this.joints = body.Joints;
     this.lean = body.Lean;
     this.leanTrackingState = body.LeanTrackingState;
     this.trackingId = body.TrackingId;
 }
Beispiel #15
0
 /// <summary>
 /// Constructs a body adapter from a kinect sdk body
 /// </summary>
 /// <param name="body">Body from Kinect SDK</param>
 public KinectBody(Microsoft.Kinect.Body body)
 {
     this.clippedEdges        = body.ClippedEdges;
     this.handLeftConfidence  = body.HandLeftConfidence;
     this.handLeftState       = body.HandLeftState;
     this.handRightConfidence = body.HandRightConfidence;
     this.handRightState      = body.HandRightState;
     this.isRestricted        = body.IsRestricted;
     this.isTracked           = body.IsTracked;
     this.jointOrientations   = body.JointOrientations;
     this.joints            = body.Joints;
     this.lean              = body.Lean;
     this.leanTrackingState = body.LeanTrackingState;
     this.trackingId        = body.TrackingId;
 }
Beispiel #16
0
 public static KinectBodyInternal BodyWithRightHandState(ulong id, TrackingConfidence confidence, HandState state)
 {
     var result = new KinectBodyInternal()
     {
         ClippedEdges = FrameEdges.None,
         HandLeftConfidence = TrackingConfidence.High,
         HandLeftState = HandState.NotTracked,
         HandRightConfidence = confidence,
         HandRightState = state,
         IsRestricted = false,
         IsTracked = true,
         JointOrientations = new JointOrientation[Microsoft.Kinect.Body.JointCount],
         Joints = FakeJoints.ValidRandomJoints(),
         LeanTrackingState = TrackingState.NotTracked,
         TrackingId = id
     };
     return result;
 }
Beispiel #17
0
    private void GetHandState(OVRPlugin.Step step)
    {
        if (OVRPlugin.GetHandState(step, (OVRPlugin.Hand)HandType, ref _handState))
        {
            IsTracked = (_handState.Status & OVRPlugin.HandStatus.HandTracked) != 0;
            IsSystemGestureInProgress = (_handState.Status & OVRPlugin.HandStatus.SystemGestureInProgress) != 0;
            IsPointerPoseValid        = (_handState.Status & OVRPlugin.HandStatus.InputStateValid) != 0;
            PointerPose.localPosition = _handState.PointerPose.Position.FromFlippedZVector3f();
            PointerPose.localRotation = _handState.PointerPose.Orientation.FromFlippedZQuatf();
            HandScale      = _handState.HandScale;
            HandConfidence = (TrackingConfidence)_handState.HandConfidence;

            _isInitialized = true;
        }
        else
        {
            _isInitialized = false;
        }
    }
Beispiel #18
0
        public static KinectBodyInternal BodyWithLeftHandState(ulong id, TrackingConfidence confidence, HandState state)
        {
            var result = new KinectBodyInternal()
            {
                ClippedEdges        = FrameEdges.None,
                HandLeftConfidence  = confidence,
                HandLeftState       = state,
                HandRightConfidence = TrackingConfidence.High,
                HandRightState      = HandState.NotTracked,
                IsRestricted        = false,
                IsTracked           = true,
                JointOrientations   = new JointOrientation[Microsoft.Kinect.Body.JointCount],
                Joints            = FakeJoints.ValidRandomJoints(),
                LeanTrackingState = TrackingState.NotTracked,
                TrackingId        = id
            };

            return(result);
        }
Beispiel #19
0
        public void Deserialize(BinaryReader reader, byte kinectId)
        {
            this.kinectId = kinectId;
            trackingId    = reader.ReadUInt64(); //WTF
            ReadJointData(reader, ref trackingState, ref position);
            ReadJointData(reader, ref spineMidState, ref spineMidPosition);
            ReadJointData(reader, ref spineShoulderState, ref spineShoulderPosition);

            ReadJointData(reader, ref headState, ref headPosition);

            handLeftState      = (HandState)reader.ReadByte();
            handLeftConfidence = (TrackingConfidence)reader.ReadByte();
            ReadJointData(reader, ref handLeftTrackingState, ref handLeftPosition);

            handRightState      = (HandState)reader.ReadByte();
            handRightConfidence = (TrackingConfidence)reader.ReadByte();
            ReadJointData(reader, ref handRightTrackingState, ref handRightPosition);
            modifiedByMatrix = false;
            valid            = true;
        }
Beispiel #20
0
 public Person(string ID, Point3D location, string gesture, trackingStates trackState,Joint leftHand, Joint rightHand, HandState leftHandState, HandState rightHandState, TrackingConfidence leftHandConfidence, TrackingConfidence rightHandConfidence)
 {
     this.ID = ID;
     this.location = location;
     this.gesture = gesture;
     this.trackingState = (int)trackState;
     this.leftHandLocation = null;
     this.rightHandLocation = null;
     if (leftHand.TrackingState == TrackingState.Tracked) {
         this.leftHandLocation = new Point3D((double)leftHand.Position.X, (double)leftHand.Position.Y, (double)leftHand.Position.Z);
         this.leftHandState = leftHandState.ToString();
         this.leftHandConfidence = leftHandConfidence.ToString();
         this.rightHandConfidence = rightHandConfidence.ToString();
     }
     if (rightHand.TrackingState == TrackingState.Tracked)
     {
         this.rightHandLocation = new Point3D((double)rightHand.Position.X, (double)rightHand.Position.Y, (double)rightHand.Position.Z);
         this.rightHandState = rightHandState.ToString();
     }
     
 }
Beispiel #21
0
        private void DrawHandState(Joint joint,
                                   TrackingConfidence trackingConfidence, HandState handState)
        {
            // 手の追跡信頼性が高い
            if (trackingConfidence != TrackingConfidence.High)
            {
                return;
            }

            // 手が開いている(パー)
            if (handState == HandState.Open)
            {
                DrawEllipse(joint, 40, new Color()
                {
                    R = 255,
                    G = 255,
                    A = 128
                });
            }
            // チョキのような感じ
            else if (handState == HandState.Lasso)
            {
                DrawEllipse(joint, 40, new Color()
                {
                    R = 255,
                    B = 255,
                    A = 128
                });
            }
            // 手が閉じている(グー)
            else if (handState == HandState.Closed)
            {
                DrawEllipse(joint, 40, new Color()
                {
                    G = 255,
                    B = 255,
                    A = 128
                });
            }
        }
Beispiel #22
0
    private void GetHandState(OVRPlugin.Step step)
    {
        if (OVRPlugin.GetHandState(step, (OVRPlugin.Hand)HandType, ref _handState))
        {
            IsTracked = (_handState.Status & OVRPlugin.HandStatus.HandTracked) != 0;
            IsSystemGestureInProgress = (_handState.Status & OVRPlugin.HandStatus.SystemGestureInProgress) != 0;
            IsPointerPoseValid        = (_handState.Status & OVRPlugin.HandStatus.InputStateValid) != 0;
            PointerPose.localPosition = _handState.PointerPose.Position.FromFlippedZVector3f();
            PointerPose.localRotation = _handState.PointerPose.Orientation.FromFlippedZQuatf();
            HandScale      = _handState.HandScale;
            HandConfidence = (TrackingConfidence)_handState.HandConfidence;

            _isInitialized = true;
        }
        else
        {
#if UNITY_EDITOR
            //in editor don't change _isInitialized - this could cause feeders adding data at invalid moment (depending on call order) - which will result in no hands being visible
            return;
#endif
            _isInitialized = false;
        }
    }
Beispiel #23
0
 internal Body(
     Joint[] jointData,
     Guid entityId,
     bool isTracked,
     HandState leftHandState,
     TrackingConfidence leftHandConfidence,
     HandState rightHandState,
     TrackingConfidence rightHandConfidence,
     Vector2 lean,
     TrackingState leanState,
     FrameEdges clippedEdges)
 {
     Joints            = new EnumDictionary <Joint>(jointData);
     IsTracked         = isTracked;
     EntityId          = entityId;
     HandStateLeft     = leftHandState;
     ConfidenceLeft    = leftHandConfidence;
     HandStateRight    = rightHandState;
     ConfidenceRight   = rightHandConfidence;
     Lean              = lean;
     LeanTrackingState = leanState;
     ClippedEdges      = clippedEdges;
 }
Beispiel #24
0
        void Update()
        {
            updateHandTracking();

            if (IsHandTracking)
            {
                LeftHandConfidence  = LeftHand.GetFingerConfidence(HandFinger.Index);
                RightHandConfidence = RightHand.GetFingerConfidence(HandFinger.Index);

                if (leftSkele != null && leftSkele.Bones != null)
                {
                    leftIndexBone = leftSkele.Bones.FirstOrDefault(x => x.Id == OVRSkeleton.BoneId.Hand_IndexTip);
                    if (leftIndexBone != null)
                    {
                        LeftIndexPosition = leftIndexBone.Transform.position;
                    }
                }

                IsLeftIndexPinching    = LeftHand.GetFingerIsPinching(HandFinger.Index) && LeftHandConfidence == TrackingConfidence.High;
                LeftIndexPinchStrength = LeftHand.GetFingerPinchStrength(HandFinger.Index);

                if (rightSkele && rightSkele.Bones != null)
                {
                    rightIndexBone = rightSkele.Bones.FirstOrDefault(x => x.Id == OVRSkeleton.BoneId.Hand_IndexTip);
                    if (rightIndexBone != null)
                    {
                        RightIndexPosition = rightIndexBone.Transform.position;
                    }
                }

                IsRightIndexPinching    = RightHand.GetFingerIsPinching(HandFinger.Index) && RightHandConfidence == TrackingConfidence.High;
                RightIndexPinchStrength = RightHand.GetFingerPinchStrength(HandFinger.Index);
            }

            updateGrabbers();
        }
 public OscMessage BuildHandMessage(Body body, string key, HandState state, TrackingConfidence confidence)
 {
     var address = String.Format("/bodies/{0}/hands/{1}", body.TrackingId, key);
     //System.Diagnostics.Debug.WriteLine(address);
     return new OscMessage(address, state.ToString(), confidence.ToString());
 }
        private void UpdateHand(FrameworkElement thumbsUp, HandState handState, TrackingConfidence trackingConfidence, Point point)
        {
            thumbsUp.Visibility = (handState == HandState.Lasso) ? Visibility.Visible : Visibility.Collapsed;

            if (!Double.IsInfinity(point.X) && !Double.IsInfinity(point.Y))
            {
                Canvas.SetLeft(thumbsUp, point.X - thumbsUp.Width / 2);
                Canvas.SetTop(thumbsUp, point.Y - thumbsUp.Height / 2);
            }
        }
        /// <summary>
        /// Updates hand state ellipses depending on tracking state and it's confidence.
        /// </summary>
        /// <param name="ellipse">ellipse representing handstate</param>
        /// <param name="handState">open, closed, or lasso</param>
        /// <param name="trackingConfidence">confidence of handstate</param>
        /// <param name="point">location of handjoint</param>
        private void UpdateHand(Ellipse ellipse, HandState handState, TrackingConfidence trackingConfidence, Point point)
        {
            ellipse.Fill = new SolidColorBrush(this.HandStateToColor(handState));

            // draw handstate ellipse based on tracking confidence
            ellipse.Width = ellipse.Height = (trackingConfidence == TrackingConfidence.Low) ? LowConfidenceHandSize : HighConfidenceHandSize;

            ellipse.Visibility = Windows.UI.Xaml.Visibility.Visible;

            // don't draw handstate if hand joints are not tracked
            if (!Double.IsInfinity(point.X) && !Double.IsInfinity(point.Y))
            {
                Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
                Canvas.SetTop(ellipse, point.Y - ellipse.Width / 2);
            }
        }
Beispiel #28
0
 void ProcessHandStateInformation(int joint, Joint j, JointOrientation jo, HandState state, TrackingConfidence confidence, double time, int pointScale, UdpWriter osc, StreamWriter fileWriter)
 {
     SendHandStateMessage(joint,
                          j.Position.X, j.Position.Y, j.Position.Z,
                          JointToConfidenceValue(j),
                          HandStateToValue(state),
                          TrackingConfidenceToValue(confidence), time,
                          pointScale, osc, fileWriter);
 }
Beispiel #29
0
 public static KinectBody BodyWithRightHandState(ulong id, TrackingConfidence confidence, HandState state)
 {
     return new KinectBody(FakeInternalBodies.BodyWithRightHandState(id, confidence, state));
 }
Beispiel #30
0
 private KinectBase.TrackingConfidence convertTrackingConfidence(TrackingConfidence confidence)
 {
     //The enums are numbered the same, so we can do a straight cast
     return (KinectBase.TrackingConfidence)confidence;
 }
Beispiel #31
0
 private KinectBase.TrackingConfidence convertTrackingConfidence(TrackingConfidence confidence)
 {
     //The enums are numbered the same, so we can do a straight cast
     return((KinectBase.TrackingConfidence)confidence);
 }
Beispiel #32
0
        // Saves the joint state to a .csv file
        private Boolean WriteJoint(Body body)
        {
            CameraSpacePoint rightWristPosition = body.Joints[JointType.WristRight].Position;
            CameraSpacePoint spineBasePosition  = body.Joints[JointType.SpineBase].Position;
            CameraSpacePoint rightHandPosition  = body.Joints[JointType.HandRight].Position;
            CameraSpacePoint rightThumbPosition = body.Joints[JointType.ThumbRight].Position;

            // Save the elbow as well in case we want it in the future
            CameraSpacePoint rightElbowPosition = body.Joints[JointType.ElbowRight].Position;

            // The change the coordinate frame with respect to Baxter according to the rotation matrix
            Single xW = spineBasePosition.Z - rightWristPosition.Z;
            Single yW = spineBasePosition.X - rightWristPosition.X;
            Single zW = rightWristPosition.Y - spineBasePosition.Y;

            Single xH = spineBasePosition.Z - rightHandPosition.Z;
            Single yH = spineBasePosition.X - rightHandPosition.X;
            Single zH = rightHandPosition.Y - spineBasePosition.Y;

            Single xT = spineBasePosition.Z - rightThumbPosition.Z;
            Single yT = spineBasePosition.X - rightThumbPosition.X;
            Single zT = rightThumbPosition.Y - spineBasePosition.Y;

            Single xE = spineBasePosition.Z - rightElbowPosition.Z;
            Single yE = spineBasePosition.X - rightElbowPosition.X;
            Single zE = rightElbowPosition.Y - spineBasePosition.Y;


            DateTime finalTime = DateTime.Now;

            Double ElapsedTime = (finalTime - this.initialTime).TotalSeconds;

            String name        = "NEW_ROTZ";
            String filePathAll = @"C:\Users\Usuario\Documents\Universidad\Master\TFM\Kinect\BodyBasics-WPF\Data\" + this.dateString +
                                 "-" + name + ".csv";
            String filePathHigh = @"C:\Users\Usuario\Documents\Universidad\Master\TFM\Kinect\BodyBasics-WPF\Data\HighConf\" + this.dateString +
                                  "-" + name + ".csv";

            String line = ElapsedTime.ToString(CultureInfo.InvariantCulture) + "," +
                          xW.ToString(CultureInfo.InvariantCulture) + "," + yW.ToString(CultureInfo.InvariantCulture)
                          + "," + zW.ToString(CultureInfo.InvariantCulture) + "," +
                          xH.ToString(CultureInfo.InvariantCulture) + "," + yH.ToString(CultureInfo.InvariantCulture)
                          + "," + zH.ToString(CultureInfo.InvariantCulture) + "," +
                          xT.ToString(CultureInfo.InvariantCulture) + "," + yT.ToString(CultureInfo.InvariantCulture)
                          + "," + zT.ToString(CultureInfo.InvariantCulture) + "," +
                          xT.ToString(CultureInfo.InvariantCulture) + "," + yT.ToString(CultureInfo.InvariantCulture)
                          + "," + zT.ToString(CultureInfo.InvariantCulture);

            TrackingConfidence conf = body.HandRightConfidence;

            switch (body.HandRightState)
            {
            /*
             * case HandState.Closed:
             *  Console.WriteLine("Closed");
             *  return false; */
            case HandState.NotTracked:
            //Do nothing
            default:
                //Console.WriteLine("DEFAULT");

                // Use coordinates only if confidence is high
                if (conf.Equals(TrackingConfidence.High))
                {
                    using (StreamWriter file = new StreamWriter(filePathHigh, true))
                    {
                        file.WriteLine(line);
                    }
                }

                using (StreamWriter file = new StreamWriter(filePathAll, true))
                {
                    file.WriteLine(line);
                }

                return(true);
            }
        }
Beispiel #33
0
 public static void AddConfidence(FlatBufferBuilder builder, TrackingConfidence confidence)
 {
     builder.AddInt(0, (int)confidence, 0);
 }
Beispiel #34
0
   public static Offset<Hand> CreateHand(FlatBufferBuilder builder,
 TrackingConfidence confidence = TrackingConfidence.Low,
 HandState state = HandState.Unknown)
   {
       builder.StartObject(2);
       Hand.AddState(builder, state);
       Hand.AddConfidence(builder, confidence);
       return Hand.EndHand(builder);
   }
Beispiel #35
0
 public static KinectBody BodyWithLeftHandState(ulong id, TrackingConfidence confidence, HandState state)
 {
     return(new KinectBody(FakeInternalBodies.BodyWithLeftHandState(id, confidence, state)));
 }
Beispiel #36
0
 /// <summary>
 /// update elipse tangan
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="handState"></param>
 /// <param name="trackingConfidence"></param>
 /// <param name="point"></param>
 private void UpdateHand(Ellipse ellipse, HandState handState, TrackingConfidence trackingConfidence, Point point)
 {
 }
Beispiel #37
0
        private void DrawHandState( Joint joint,
            TrackingConfidence trackingConfidence, HandState handState )
        {
            // 手の追跡信頼性が高い
            if ( trackingConfidence != TrackingConfidence.High ) {
                return;
            }

            // 手が開いている(パー)
            if ( handState == HandState.Open ) {
                DrawEllipse( joint, 40, new SolidColorBrush( new Color()
                {
                    R = 255,
                    G = 255,
                    A = 128
                } ) );
            }
            // チョキのような感じ
            else if ( handState == HandState.Lasso ) {
                DrawEllipse( joint, 40, new SolidColorBrush( new Color()
                {
                    R = 255,
                    B = 255,
                    A = 128
                } ) );
            }
            // 手が閉じている(グー)
            else if ( handState == HandState.Closed ) {
                DrawEllipse( joint, 40, new SolidColorBrush( new Color()
                {
                    G = 255,
                    B = 255,
                    A = 128
                } ) );
            }
        }
Beispiel #38
0
 OscElement ProcessHandStateInformation(int joint, Joint j, JointOrientation jo, HandState state, TrackingConfidence confidence, double time, int pointScale)
 {
     return(SendHandStateMessage(joint,
                                 j.Position.X, j.Position.Y, j.Position.Z,
                                 JointToConfidenceValue(j),
                                 HandStateToValue(state),
                                 TrackingConfidenceToValue(confidence), time,
                                 pointScale));
 }
Beispiel #39
0
 private HandUpdate Create(Joint hand, Joint head, HandState state, bool isLeft, TrackingConfidence confidence, int bodyId)
 {
     return(new HandUpdate
     {
         X = hand.Position.X,
         Y = hand.Position.Y,
         Z = hand.Position.Z,
         DX = hand.Position.X - head.Position.X,
         DY = hand.Position.Y - head.Position.Y,
         DZ = hand.Position.Z - head.Position.Z,
         IsLeft = isLeft,
         Gesture = GetHandTrackingState(state),
         Confidence = GetTrackingConfidence(confidence),
         BodyId = bodyId
     });
 }