private void TrackGesture(Skeleton skeleton, ref GestureTracker tracker, long timeStamp) { Joint leftHand = skeleton.Joints[JointType.HandLeft]; Joint rightHand = skeleton.Joints[JointType.HandRight]; if (leftHand.TrackingState != JointTrackingState.NotTracked && rightHand.TrackingState != JointTrackingState.NotTracked) { if (tracker.State == GestureState.InProcess && tracker.TimeStamp + _TIMEOUT <= timeStamp) //响应超时 tracker.UpdateState(GestureState.Failure, timeStamp); else { if (tracker.State == GestureState.InProcess) { if (Math.Abs(leftHand.Position.X - rightHand.Position.X) >= UPPER_THRESHOLD || Math.Abs(leftHand.Position.Y - rightHand.Position.Y) >= UPPER_THRESHOLD) { tracker.UpdateState(GestureState.Success, timeStamp); if (GestureDetected != null) GestureDetected(this, new EventArgs()); } } else { if (Math.Abs(leftHand.Position.Y - rightHand.Position.Y) < LOWER_THRESHOLD && Math.Abs(leftHand.Position.X - rightHand.Position.X) <= LOWER_THRESHOLD) tracker.UpdatePosition(timeStamp); else tracker.Reset(); } } } else tracker.Reset(); }
public void LoadPersistantGesuture(string name, OnGestureSuccessEvent onSuccess, OnGestureFailureEvent onFail = null, bool loops = true, float loopDelay = 0.1f, float minVelMag = 0.25f) { List <Vector3> leftMP, rightMP; //Try loading the gesture, return on failure if (!GestureInput.instance.TryLoadGesture(name, out leftMP, out rightMP)) { return; } //Add new points to the pool if needed int used = PersistantTrackersCount(); int add = leftMP.Count + rightMP.Count; if (used + add > m_PointsPool.Count) { CreateTrackers(used + add - m_PointsPool.Count); } //Align the points m_LastActiveIndex = used; AlignPoints(ref leftMP, out m_PointTrackersLeft, true); AlignPoints(ref rightMP, out m_PointTrackersRight, false); //Associate to the gesture tracker m_TrackedGestures[name] = new GestureTracker(); m_TrackedGestures[name].SetUpGestureTracking(name, m_PointTrackersLeft, m_PointTrackersRight, onSuccess, onFail, loops, loopDelay, minVelMag); }
public GestureAnalyser(GestureTracker gesture_tracker) { m_gestureTracker = gesture_tracker; m_tagActionDict.Add("PathNodeMoveLeft", CharacterAction.SwimLeft); m_tagActionDict.Add("PathNodeMoveRight", CharacterAction.SwimRight); m_tagActionDict.Add("PathNodeMoveUp", CharacterAction.SwimUp); m_tagActionDict.Add("PathNodeMoveDown", CharacterAction.SwimDown); m_tagActionDict.Add("PathNodeRotateLeft", CharacterAction.SwimLeft); // m_tagActionDict.Add("PathNodeRotateLeft" , CharacterAction.RotateLeft); m_tagActionDict.Add("PathNodeRotateRight", CharacterAction.SwimRight); // m_tagActionDict.Add("PathNodeRotateRight" , CharacterAction.RotateRight); m_tagActionDict.Add("PathNodeSeaweed", CharacterAction.Eat); m_tagActionDict.Add("PathNodeSpeedup", CharacterAction.SwimForward); }
private void TrackGesture(Skeleton skeleton, ref GestureTracker tracker, long timeStamp) { Joint hand = skeleton.Joints[JointType.HandLeft]; Joint head = skeleton.Joints[JointType.Head]; if (hand.TrackingState != JointTrackingState.NotTracked && head.TrackingState != JointTrackingState.NotTracked) { if (tracker.State == GestureState.Success) { if (hand.Position.Y < head.Position.Y) tracker.Reset(); } else { if (tracker.State == GestureState.InProcess && tracker.TimeStamp + _TIMEOUT <= timeStamp) { if (Math.Abs(tracker.StartX - hand.Position.X) <= 0.1f && Math.Abs(tracker.StartY - hand.Position.Y) <= 0.1f) { tracker.UpdateState(GestureState.Success, timeStamp); if (GestureDetected != null) GestureDetected(this, new EventArgs()); } else tracker.UpdateState(GestureState.Failure, timeStamp); } else { if (tracker.State == GestureState.InProcess) { if (Math.Abs(tracker.StartX - hand.Position.X) > 0.1f && Math.Abs(tracker.StartY - hand.Position.Y) > 0.1f) tracker.UpdateState(GestureState.Failure, timeStamp); } else { if (hand.Position.Y - head.Position.Y >= ABOVE_THRESHOLD) tracker.UpdatePosition(hand.Position.X, hand.Position.Y, timeStamp); else tracker.Reset(); } } } } else tracker.Reset(); }
private void TrackGesture(Skeleton skeleton, bool isLeft, ref GestureTracker tracker, long timeStamp) { JointType handJointId = (isLeft) ? JointType.HandLeft : JointType.HandRight; JointType elbowJointId = (isLeft) ? JointType.ElbowLeft : JointType.ElbowRight; Joint hand = skeleton.Joints[handJointId]; Joint elbow = skeleton.Joints[elbowJointId]; if (hand.TrackingState != JointTrackingState.NotTracked && elbow.TrackingState != JointTrackingState.NotTracked) { if (tracker.State == GestureState.InProcess && tracker.TimeStamp + WAVE_MOVEMENT_TIMEOUT < timeStamp) { //超时失效 tracker.UpdateState(GestureState.Failure, timeStamp); } else if (hand.Position.Y > elbow.Position.Y+0.15f) { if (hand.Position.X <= elbow.Position.X - WAVE_THRESHOLD) tracker.UpdatePosition(WavePosition.Left, timeStamp); else if (hand.Position.X >= elbow.Position.X + WAVE_THRESHOLD) tracker.UpdatePosition(WavePosition.Right, timeStamp); else tracker.UpdatePosition(WavePosition.Neutral, timeStamp); if (tracker.State != GestureState.Success && tracker.IterationCount == REQUIRED_ITERATIONS) { //手势识别成功 tracker.UpdateState(GestureState.Success, timeStamp); if (GestureDetected != null) GestureDetected(this, new EventArgs()); } } else { if (tracker.State == GestureState.InProcess) tracker.UpdateState(GestureState.Failure, timeStamp); else tracker.Reset(); } } else tracker.Reset(); }
private void InitializeGestureTracker() { try { _tracker = new GestureTracker(); _tracker.OnError += new Action <CamEvent>(_tracker_OnError); _tracker.OnNotify += new Action <CamEvent>(_tracker_OnNotify); _tracker.OnAlert += new Action <PXCMGesture.Alert>(_tracker_OnAlert); _tracker.OnMovement += new Action <Point>(_tracker_OnMovement); _tracker.OnOpenClose += new Action <PXCMGesture.GeoNode.Openness, uint>(_tracker_OnOpenClose); _tracker.OnGesture += new Action <PXCMGesture.Gesture>(_tracker_OnGesture); _tracker.Start(); } catch (Exception exception) { UIHelper.ShowError("GESTURE TRACKER INITIALIZATION ERROR: " + exception.Message); } }
private void TrackGesture(Skeleton skeleton,bool isLeft, ref GestureTracker tracker, long timeStamp) { JointType handJointId = (isLeft) ? JointType.HandLeft : JointType.HandRight; JointType elbowJointId = (isLeft) ? JointType.ElbowLeft : JointType.ElbowRight; Joint hand = skeleton.Joints[handJointId]; Joint elbow = skeleton.Joints[elbowJointId]; if (hand.TrackingState != JointTrackingState.NotTracked && elbow.TrackingState != JointTrackingState.NotTracked) { if (tracker.State == GestureState.InProcess && tracker.TimeStamp + _TIMEOUT <= timeStamp) //响应超时 tracker.UpdateState(GestureState.Failure, timeStamp); else { if (tracker.State == GestureState.InProcess) { if (hand.Position.X - tracker.StartX >= UPPER_THRESHOLD && Math.Abs(hand.Position.Y - tracker.StartY) <= LOWER_THRESHOLD) { tracker.UpdateState(GestureState.Success, timeStamp); if (GestureDetected != null) GestureDetected(this, new EventArgs()); } } else { if (Math.Abs(hand.Position.Y - elbow.Position.Y) <= LOWER_THRESHOLD && Math.Abs(hand.Position.Z - elbow.Position.Z) >= ZINDEX_THRESHOLD) tracker.UpdatePosition(hand.Position.X,hand.Position.Y, timeStamp); else tracker.Reset(); } } } else tracker.Reset(); }
public void MakeCurrentPersistant(string name, bool loops = true, float loopDelay = 0.1f, float velMinMag = 0.25f) { m_TrackedGestures[name] = new GestureTracker(); m_TrackedGestures[name].SetUpGestureTracking(name, m_PointTrackersLeft, m_PointTrackersRight, m_SuccessEvent, m_FailureEvent, loops, loopDelay, velMinMag); }
public void SetOwner(GestureTracker owner) { m_Owner = owner; }