public override bool GetstureDetected(KinectPlayer p) { //PlayerJoints startJoints; //PlayerJoints nowJoints; //Get2Joints(p.PlayerJoints, out startJoints, out nowJoints); //if (nowJoints != null && startJoints != null) //{ // JointData startHandLeft = startJoints.HandLeft; // JointData nowHandLeft = nowJoints.HandLeft; // JointData nowElbowLeft = nowJoints.ElbowLeft; // if (startHandLeft.TrackingState == JointTrackingState.Tracked && // nowHandLeft.TrackingState == JointTrackingState.Tracked && // nowElbowLeft.TrackingState == JointTrackingState.Tracked && // nowHandLeft.Z > base.PlayerZDistance && // p.Z > base.PlayerZDistance && // nowHandLeft.Y - nowElbowLeft.Y > -0.1f && // Math.Abs(nowHandLeft.X - startHandLeft.X) > base.GestureGateDistance) // { // base.GestureDistance = nowHandLeft.X - startHandLeft.X; // p.PlayerJoints.Clear(); // return true; // } //} //return false; return base.GetstureDetected(p); }
public override bool GetstureDetected(KinectPlayer p) { //PlayerJoints startJoints; //PlayerJoints nowJoints; //Get2Joints(p.PlayerJoints, out startJoints, out nowJoints); //if (nowJoints != null && startJoints != null) //{ // JointData startHandRight = startJoints.HandRight; // JointData startElbowRight = startJoints.ElbowRight; // JointData nowHandRight = nowJoints.HandRight; // JointData nowElbowRight = nowJoints.ElbowRight; // //right hand up // if (startHandRight.TrackingState == JointTrackingState.Tracked && // startElbowRight.TrackingState == JointTrackingState.Tracked && // nowHandRight.TrackingState == JointTrackingState.Tracked && // nowElbowRight.TrackingState == JointTrackingState.Tracked && // startHandRight.Y < startElbowRight.Y && // nowHandRight.Y > nowElbowRight.Y && // p.Z > base.PlayerZDistance && // nowHandRight.Z > base.PlayerZDistance) // { // base.GestureDistance = 0f; // p.PlayerJoints.Clear(); // return true; // } //} //return false; return base.GetstureDetected(p); }
/// <summary> /// todo:只判断了首尾的状态。要中间也是保持状态 /// </summary> /// <param name="p"></param> /// <returns></returns> public override bool GetstureDetected(KinectPlayer p) { PlayerJoints startJoints; PlayerJoints nowJoints; Get2Joints(p.PlayerJoints, out startJoints, out nowJoints); if (nowJoints != null && startJoints != null) { if (IsFly(startJoints) && IsFly(nowJoints) && nowJoints.TimeStamp.Subtract(startJoints.TimeStamp).TotalMilliseconds> base.MinTimeDuration) { p.PlayerJoints.Clear(); return true; } } return false; }
private bool IsFlying(KinectPlayer p) { PlayerJoints nowJoints = p.PlayerJoints.LastOrDefault(); if (nowJoints != null) { if ( nowJoints.ShoulderLeft.TrackingState == JointTrackingState.Tracked && nowJoints.ShoulderRight.TrackingState == JointTrackingState.Tracked && nowJoints.ElbowLeft.TrackingState == JointTrackingState.Tracked && nowJoints.ElbowRight.TrackingState == JointTrackingState.Tracked && nowJoints.ElbowLeft.Z > base.PlayerZDistance && nowJoints.ElbowRight.Z > base.PlayerZDistance && Math.Abs(nowJoints.ShoulderLeft.Y - nowJoints.ElbowLeft.Y) < 0.15 && Math.Abs(nowJoints.ShoulderRight.Y - nowJoints.ElbowRight.Y) < 0.15 && p.IsAlive) { return true; }; } return false; }
private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); //start by wyf foreach (Skeleton sskeleton in this.skeletonData)//6个人 { if (SkeletonTrackingState.Tracked == sskeleton.TrackingState) { if (sskeleton.Joints.Count > 0) { KinectPlayer pplayer; if (this.players.ContainsKey(sskeleton.TrackingId)) { pplayer = this.players[sskeleton.TrackingId]; } else { pplayer = new KinectPlayer(sskeleton); this.players.Add(sskeleton.TrackingId, pplayer); } pplayer.AddSketon(sskeleton); } } } foreach (var item in players) { KinectPlayer p = item.Value; if (!p.IsAlive) { continue; } ////right hand move if (handRSweepDetector.GetstureDetected(p)) { this.RaiseEvent(new KinectGestureEventArgs() { GestureType = KinectGestureType.RightHandsMove, ActionStep = Convert.ToInt16(Math.Ceiling(handRSweepDetector.GestureDistance / handRSweepDetector.GestureGateDistance)), Distance = handRSweepDetector.GestureDistance }); break; } ////////left hand move if (handLSweepDetector.GetstureDetected(p)) { this.RaiseEvent(new KinectGestureEventArgs() { GestureType = KinectGestureType.LeftHandsMove, ActionStep = -Convert.ToInt16(Math.Ceiling(handLSweepDetector.GestureDistance / handLSweepDetector.GestureGateDistance)), Distance = handLSweepDetector.GestureGateDistance }); break; } } } } }
void Update() { if (BodySourceManager == null) { return; } _bodyManager = BodySourceManager.GetComponent <BodySourceManager>(); if (_bodyManager == null) { return; } Kinect.Body[] data = _bodyManager.GetData(); if (data == null) { return; } List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); break; } } List <ulong> knownIds = new List <ulong>(Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(Bodies[trackingId]); Bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { if (!Bodies.ContainsKey(body.TrackingId)) { GameObject newBody = new GameObject(); KinectPlayer newPlayer = Instantiate(Resources.Load("BlockPlayer") as GameObject, new Vector3(0, 0, 0), Quaternion.identity).GetComponent <KinectPlayer>(); newPlayer.Kinect = this; if (players.Count == 0) { newPlayer.makeMainPlayer(true); } Bodies[body.TrackingId] = newPlayer.CreateBodyObject(body, newBody); newPlayer.WarpToLocation(new Vector3(0, 1.5f, 0)); players.Add(newPlayer); _bodyThread = new Thread(new ThreadStart(RefreshBody)); _bodyThread.Start(); } foreach (KinectPlayer player in players) { try { if (player.IsTracked()) { player.gameObject.SetActive(true); player.UpdateBodyObject(); player.AdjustBodyParts(); } else { player.gameObject.SetActive(false); } } catch (Exception e) { Debug.LogError("Error getting body"); Debug.LogError(e); } } break; } } }
/// <summary> /// 是否识别动作 /// </summary> /// <param name="PlayerJoints"></param> /// <returns></returns> public virtual bool GetstureDetected( KinectPlayer p) { PlayerJoints startJoints; PlayerJoints nowJoints; Get2Joints(p.PlayerJoints, out startJoints, out nowJoints); if (nowJoints != null && startJoints != null) { switch (Orentation) { case GestureOrentation.Left: return IsGesture(p, startJoints.HandLeft, nowJoints.HandLeft) || IsGesture(p, startJoints.WristLeft, nowJoints.WristLeft); case GestureOrentation.Right: return IsGesture(p, startJoints.HandRight, nowJoints.HandRight) || IsGesture(p, startJoints.WristRight, nowJoints.WristRight);; } } return false; }
protected bool IsGesture(KinectPlayer p, JointData startJoint, JointData nowJoint) { if (startJoint.TrackingState == JointTrackingState.Tracked && nowJoint.TrackingState == JointTrackingState.Tracked && startJoint.Z > this.PlayerZDistance && nowJoint.Z > this.PlayerZDistance && p.Z > this.PlayerZDistance ) { this.GestureDistance = MovedDistance(startJoint, nowJoint); if (nowJoint.X < startJoint.X) { this.GestureDistance *= -1; } if (Math.Abs(this.GestureDistance) > GestureGateDistance) { p.PlayerJoints.Clear(); return true; } } return false; }
public void init(KinectPlayer player, KinectCamera camera) { this.player = player; this.kinect_view = camera; _onBounds = new HashSet <Collider>(); }