/// <summary> /// Updates the current gesture. /// </summary> /// <param name="skeleton">The skeleton data.</param> public void Update(Skeleton skeleton) { GesturePartResult result = _segments[_currentSegment].Update(skeleton); if (result == GesturePartResult.Succeeded) { if (_currentSegment + 1 < _segments.Length) { _currentSegment++; _frameCount = 0; } else { if (GestureRecognized != null) { GestureRecognized(this, new EventArgs()); Reset(); } } } else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE) { Reset(); } else { _frameCount++; } }
public override void Update(Microsoft.Kinect.Body body) { //check next gesture of the sequence GesturePartResult result = this.CheckGesturePart(body); //if result has been positive if (result == GesturePartResult.Succeded) { //increase counter and check whether the limit has been reached (--> fire event) this.CheckSuccededFlow(body); } //if result has been negative else { //check whether maximal amount of frames has been arrived if (++_frameCounter == MAX_WINDOW_SIZE) { //reset counter this.Reset(); //check this frame again, maybe it might be the start of a new gesture: //DO NOT USE RECURSITION since this might lead into a stack overflow! result = this.CheckGesturePart(body); if (result == GesturePartResult.Succeded) { CheckSuccededFlow(body); // it is not necessary to check the boundaries of the array since we know, that this array has more than 2 fields } } } }
/// <summary> /// Updates the current gesture. /// </summary> /// <param name="skeleton">The skeleton data.</param> public void whatUpdate(Skeleton skeleton) { //if (_currentSegment != 0) //{ GesturePartResult result = _whatsegments[_whatcurrentSegment].whatUpdate(skeleton); //Console.WriteLine("after update"); if (result == GesturePartResult.Succeeded) { if (_whatcurrentSegment + 1 < _whatsegments.Length) { _whatcurrentSegment++; _whatframeCount = 0; } else { if (GestureRecognized != null) { GestureRecognized(this, new EventArgs()); Reset(); } } } else if (result == GesturePartResult.Failed || _whatframeCount == WINDOW_SIZE) { Reset(); } else { _whatframeCount++; } //} }
public GesturePartResult CheckGesture(Skeleton skeleton, GesturePartResult previousResult) { if (skeleton == null) { return GesturePartResult.Fail; } // right hand is raised but not swiping yet if (skeleton.Joints[JointType.HandRight].Position.Y > skeleton.Joints[JointType.ElbowRight].Position.Y) { // right hand is to the right of the elbow if (skeleton.Joints[JointType.HandRight].Position.X > skeleton.Joints[JointType.ElbowRight].Position.X) { framecount = 0; return GesturePartResult.Succeed; } if (previousResult == GesturePartResult.Succeed) { framecount++; if (framecount > 30) { framecount = 0; return GesturePartResult.Fail; } return GesturePartResult.Pausing; } } // hand dropped return GesturePartResult.Fail; }
public void Update(Skeleton skeleton) { //check every segment GesturePartResult result = _segments[_currentSegment].Update(skeleton); //check every segment for success if (result == GesturePartResult.Succeeded) { if (_currentSegment + 1 < _segments.Length) { _currentSegment++; //Go to the next gesture part to check _frameCount = 0; } else { if (GestureRecognizedRight != null) { GestureRecognizedRight(this, new EventArgs()); //Gesture found Reset(); //Start the gesture over } } } else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE) { Reset(); //Start the gesture over } else { _frameCount++; //Count the frames } }
public void Update(Kinect.Body body) { GesturePartResult result = segments[currentSegment].Update(body); if (result == GesturePartResult.Succeeded) { if (currentSegment + 1 < segments.Length) { currentSegment++; frameCount = 0; } else { if (SwipeRightRecognized != null) { SwipeRightRecognized(this, new EventArgs()); Reset(); } } } else if (result == GesturePartResult.Failed || frameCount == windowSize) { Reset(); } else { frameCount++; } }
/// <summary> /// Actualización del gesto. /// </summary> /// <param name="skeleton">Datos del skeleton</param> public void Update(Skeleton skeleton) { GesturePartResult result = _segments[_currentSegment].Update(skeleton); if (result == GesturePartResult.Succeeded) { if (_currentSegment + 1 < _segments.Length) // Detección de segmento. { _currentSegment++; _frameCount = 0; } else { if (GestureRecognized != null) { GestureRecognized(this, new EventArgs()); // Gesto completado. Reset(); } } } else if (result == GesturePartResult.Failed && _frameCount == WINDOW_SIZE) // Gesto fallido y tiempo agotado. { Reset(); } else // Gesto fallido aún con tiempo. { _frameCount++; } }
public override void Update(Body body) { //check next gesture of the sequence GesturePartResult result = this.CheckGesturePart(body); //if result has been positive if (result == GesturePartResult.Succeded) { //increase counter and check whether the limit has been reached (--> fire event) this.CheckSuccededFlow(body); } //if result has been negative else { //reset counter this.Reset(); //now we want to check this body state aggain, but with the first gesture part in the sequence since we have reset the counter //this step is necessary, otherwise the beginning of a possible matching gesture might be lost result = this.CheckGesturePart(body); if (result == GesturePartResult.Succeded) { this.CheckSuccededFlow(body); } } }
public GesturePartResult CheckGesture(Skeleton skeleton, GesturePartResult previousResult) { if (skeleton == null) { return GesturePartResult.Fail; } // should we check for the gesutre yet?? if (startGestureCheck) { //yes // right hand is below right elbow if (skeleton.Joints[JointType.HandRight].Position.Y < skeleton.Joints[JointType.ShoulderRight].Position.Y) { framecount = 0; startGestureCheck = false; return GesturePartResult.Succeed; } // hand is still above head return GesturePartResult.Fail; } else { //no // right hand is above right elbow if (skeleton.Joints[JointType.HandRight].Position.Y > skeleton.Joints[JointType.ShoulderRight].Position.Y) { startGestureCheck = true; } return GesturePartResult.Fail; } }
/// <summary> /// Updates the current gesture. /// </summary> /// <param name="body">The body data.</param> public void Update(Body body) { GesturePartResult gesture_result = _gesture_segments[_current_gesture_segment].Update(body); if (gesture_result == GesturePartResult.Success) { if (_current_gesture_segment + 1 < _gesture_segments.Length) { _current_gesture_segment++; _frame_count = 0; } else { if (GestureRecognized != null) { GestureRecognized(this, new EventArgs()); Reset(); } } } else if (gesture_result == GesturePartResult.Fail || _frame_count == WINDOW_SIZE) { Reset(); } else { _frame_count++; } }
public void Update(KinectSensor sensor, Skeleton skeleton, System.Windows.Point skel2DCenter) { GesturePartResult result = segments[currentSegmentIdx].Update(sensor, skeleton); if (result == GesturePartResult.Succeeded) { if (currentSegmentIdx + 1 < segments.Length) { currentSegmentIdx++; frameCount = 0; } else { if (OnRecognized != null) { OnRecognized(this, new GestureEventArgs(skeleton.TrackingId, skel2DCenter)); Reset(); } } } else if (result == GesturePartResult.Failed || frameCount == WINDOW_SIZE) { Reset(); } else { frameCount++; } }
/// <summary> /// check the state of the gesture compared with the skeleton datas /// </summary> /// <param name="skel">the skeleton datas</param> /// <param name="gesture_context">the gesture context</param> public void updateGesture(Skeleton skel, ContextGesture gesture_context) { //are we in pause ? if (this.paused) { if (this.frameCount >= this.pausedFrameCount) { this.paused = false; } this.frameCount++; } //get the result GesturePartResult result = this.segments[this.currentGesturePart].checkGesture(skel); if (result == GesturePartResult.SUCCESS) { if (this.currentGesturePart + 1 < this.segments.Length) { //search for to next part this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 25; this.paused = true; } else { //gesture had been recognised if (this.GestureRecognised != null) { //use the method GestureDatas e = new GestureDatas(new BodyGestureEvent(name), null, gesture_context); this.GestureRecognised(this, new GestureEventArgs(EventType.BODY, e, Helper.GetTimeStamp())); //reset this.reset(); } } } else if (result == GesturePartResult.FAIL || this.frameCount >= 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 25; this.paused = true; } }
/// <summary> /// Occurs when [gesture recognised]. /// </summary> ///public event EventHandler<GestureEventArgs> GestureRecognised; /// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(SkeletonWrapper skeletonWrapper) { if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } GesturePartResult result = this.gestureParts[this.currentGesturePart].CheckGesture(skeletonWrapper); if (result == GesturePartResult.Suceed) { if (this.currentGesturePart + 1 < this.gestureParts.Length) { this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 10; this.paused = true; } else { //動作結束 //Debug.Log("動作結束"); this.Reset(); /* * if (this.GestureRecognised != null) * { * this.GestureRecognised(this, new GestureEventArgs(this.type, data.TrackingID, data.UserIndex)); * this.Reset(); * } */ } } else if (result == GesturePartResult.Fail || this.frameCount == 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
/// <summary> /// Updates the current gesture. /// </summary> /// <param name="skeleton">The skeleton data.</param> public void Update(Skeleton skeleton) { var currentTime = MainWindow.stopWatch.ElapsedMilliseconds / 1000.0f; GesturePartResult result = _segments[_currentSegment].Update(skeleton); if (result == GesturePartResult.Succeeded) { if (_currentSegment + 1 < _segments.Length) { _currentSegment++; _frameCount = 0; lastGestureTime = currentTime; } else { if (GestureRecognized != null) { if (currentTime - lastSuccessTime > timeBetweenGesture) { GestureRecognized(this, new EventArgs()); lastSuccessTime = currentTime; Reset(); } } } } else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE) { if (_currentSegment > 0) { GesturePartResult prevResult = _segments[_currentSegment - 1].Update(skeleton); if (currentTime - lastGestureTime < 2 && prevResult == GesturePartResult.Succeeded) //we still havent left prev state { //Console.WriteLine("holding gesture"); } else { Reset(); } } else { Reset(); } } else { _frameCount++; } }
/// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(Skeleton data) { if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } // Check if current Skeleton still in gesture GesturePartResult result = this.gestureParts[this.currentGesturePart].CheckGesture(data); if (result == GesturePartResult.Succeed) { if (this.currentGesturePart + 1 < this.gestureParts.Length) // still gesture parts left { Console.Write("+"); this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 10; this.paused = true; } else // All gesture parts are done { Console.Write(" done.\n"); if (this.GestureRecognised != null) { this.GestureRecognised(this, new GestureEventArgs(this.type, data.TrackingId)); this.Reset(); } } } else if (result == GesturePartResult.Fail || this.frameCount == 50) { Console.Write(" fail.\n"); this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else // result == GesturePartResult.Pausing { Console.Write("_"); this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
/// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(BasicAvatarModel data) { if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } GesturePartResult result = this.gestureParts[this.currentGesturePart].CheckGesture(data); if (result == GesturePartResult.Succeed) { // There are still segments of our gesture if (this.currentGesturePart + 1 < this.gestureParts.Length) { // increase the currentGesturePart to check for the next part of the gesture the next time this method is called this.currentGesturePart++; this.frameCount = 0; // reset the frame counter this.pausedFrameCount = 10; // make a short break of 10 frames this.paused = true; } else // Found last segment of the gesture { if (this.GestureRecognizedInGesture != null) // make sure our event is associated with a method { // fire the event // The method to be called is defined in GestureController.cs this.GestureRecognizedInGesture(this, new GestureEventArgs(this.name, data.getTrackingID())); this.Reset(); } } } else if (result == GesturePartResult.Fail || this.frameCount == 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
/// <summary> /// Uses skeleton data from sequential Kinect frames to detect the segments that make up a gesture. /// To be called on each SkeletonFrame from the Kinect. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(Skeleton data) { if (data == null) { // We either lost the skeleton, or were never tracking it to begin with. this.Reset(); return; } GesturePartResult result = this.gestureSegments[this.currentGestureSegment].CheckGesture(data); // If the result is Pausing, the segment can still potentially succeed, // but the joints it is tracking are not in the right position to satisfy it. if (result == GesturePartResult.Pausing) { this.frameCount++; } // The joints on the skeleton satisfy the gesture segment's criteria if (result == GesturePartResult.Succeed) { // If there are more gesture segments to test, we move on to the next one. if (this.currentGestureSegment + 1 < this.gestureSegments.Length) { this.currentGestureSegment++; this.frameCount = 0; } // If this was the last gesture segment in our list, we're done. // We fire off a gesture recognized event and reset to detect future gestures. else { if (this.GestureRecognized != null) { this.GestureRecognized(this, new GestureEventArgs(this.type, data.TrackingId)); this.Reset(); } } } // Failure is when the skeleton's joints move in a way that cancels the gesture, or if we have been waiting for too many frames for it to complete. // TODO: Using the number of frames as our time out condition could be problematic, because the FPS of the kinect is configurable. // It would be best to use some sort of timer instead. This was written with the Kinect configured for 60 FPS. if (result == GesturePartResult.Fail || this.frameCount >= 50) { // We go back to testing the first gesture segment. Reset(); } }
/** * Actualiza el estado del gesto actual. Se permite 1,5 segundos para completar el gesto. */ public void Update(Body skeleton) { GesturePartResult result = _segments[_currentSegment].Update(skeleton); if (result == GesturePartResult.Succeeded) { if (_currentSegment == 0) { instante_1 = DateTime.Now; } if (_currentSegment + 1 < _segments.Length) { _currentSegment++; _frameCount = 0; } else { if (GestureRecognized != null) { GestureRecognized(this, new EventArgs()); Reset(); } } } else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE) { if (skeleton.HandRightState == HandState.Closed) { Reset(); } else if (_currentSegment == 1) { instante_2 = DateTime.Now; TimeSpan intervalo = instante_2.Subtract(instante_1); if (intervalo.TotalMilliseconds > umbral_tiempo) { Reset(); } } else { Reset(); } } else { _frameCount++; } }
public void UpdateGesture(Skeleton data) { //if you reach max pause time unpause if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } result = this.gestureParts[this.currentGesturePart].CheckGesture(data); if (result == GesturePartResult.Succeed) { //if theres another part, reset framecount, and pause for next input if (this.currentGesturePart + 1 < this.gestureParts.Length) { this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 10; this.paused = true; } else { if (this.GestureRecognised != null) { this.GestureRecognised(this, new GestureEventArgs(this.type, data.TrackingId)); this.Reset(); } } } else if(result == GesturePartResult.Fail || this.frameCount== 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
/// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(Body data) { if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } GesturePartResult result = this.gestureParts[this.currentGesturePart].CheckGesture(data); if (result == GesturePartResult.Succeed) { if (this.currentGesturePart + 1 < this.gestureParts.Length) { this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 10; this.paused = true; } else { if (this.GestureRecognized != null) { this.GestureRecognized(this, new GestureEventArgs(this.name, data.TrackingId)); this.Reset(); } } } else if (result == GesturePartResult.Fail || this.frameCount == 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
/// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(Skeleton data, DepthImagePoint head, DepthImagePoint leftHand, DepthImagePoint rightHand) { if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } GesturePartResult result = this.gestureParts[this.currentGesturePart].CheckGesture(data, head, leftHand, rightHand); if (result == GesturePartResult.Succeed) { if (this.currentGesturePart + 1 < this.gestureParts.Length) { this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 10; this.paused = true; } else { if (this.GestureRecognized != null) { this.GestureRecognized(this, new GestureEventArgs(this.name, data.TrackingId)); this.Reset(); } } } else if (result == GesturePartResult.Fail || this.frameCount == 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
/// <summary> /// Updates the current gesture. /// </summary> /// <param name="body">The body data.</param> public void Update(Body body) { if (_isPaused) { if (_frameCount == _pausedFrameCount) { _isPaused = false; } _frameCount++; } GesturePartResult result = Segments[_currentSegment].Update(body); if (result == GesturePartResult.Succeeded) { if (_currentSegment + 1 < Segments.Length) { _currentSegment++; _frameCount = 0; _pausedFrameCount = MAX_PAUSE_COUNT; _isPaused = true; } else { if (GestureRecognized != null) { GestureRecognized(this, new GestureEventArgs(GestureType, body.TrackingId)); Reset(); } } } else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE) { Reset(); } else { _frameCount++; _pausedFrameCount = MAX_PAUSE_COUNT / 2; _isPaused = true; } }
/// <summary> /// Updates the current gesture. /// </summary> /// <param name="skeleton">The skeleton data.</param> public void Update(Skeleton skeleton) { if (_paused) { if (_frameCount == _pausedFrameCount) { _paused = false; } _frameCount++; } GesturePartResult result = _segments[_currentSegment].Update(skeleton); if (result == GesturePartResult.Succeeded) { if (_currentSegment + 1 < _segments.Length) { _currentSegment++; _frameCount = 0; _pausedFrameCount = MAX_PAUSE_COUNT; _paused = true; } else { if (GestureRecognized != null) { GestureRecognized(this, new GestureEventArgs(_name, skeleton.TrackingId)); Reset(); } } } else if (result == GesturePartResult.Failed || _frameCount == WINDOW_SIZE) { Reset(); } else { _frameCount++; _pausedFrameCount = MAX_PAUSE_COUNT / 2; _paused = true; } }
public void Update(Body body) { //Debug.WriteLine(this.name + ":" + partCounter); GesturePartResult result = parts[this.partCounter].CheckGesturePart(body); //Console.WriteLine(result); //if result has been positive if (result == GesturePartResult.Succeded) { //increase counter and check whether gesture is complete if (++partCounter == parts.Length) { partCounter = 0; //fire event if (GestureRecognized != null) { GestureRecognized(this, new EventArgs()); } //reset counter } } //if result has been negative else { //reset counter partCounter = 0; //check this frame again, maybe it might be the start of a new gesture: //DO NOT USE RECURSITION since this might lead into a stack overflow! result = parts[this.partCounter].CheckGesturePart(body); if (result == GesturePartResult.Succeded) { partCounter++; // it is not necessary to check the boundaries of the array since we know, that this array has more than 2 fields } } Debug.WriteLine(this.name + ":" + partCounter); }
/// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(Skeleton data, AllFramesReadyEventArgs e, GestureStatus gestureStatus) { if (!this.ShouldExecut()) { return; } GesturePartResult result = this.gestureParts.CheckGesture(data, e, gestureStatus); if (result == GesturePartResult.Suceed) { if (this.GestureRecognized != null) { // Success & send event this.GestureRecognized(this, new GestureEventArgs(this.type, gestureStatus, data.TrackingId)); // Flush gesture status if a gesture recognized if (this.type != GestureType.HandCloseOrOpen) { gestureStatus.GestureStatusFlush(); } } } }
public void Update(Skeleton skeleton) { //Test if the software recognize a part of the movement on the left side GesturePartResult resultLEFT = _segments[_currentSegment].Update(skeleton, LEFT); //Test if the software recognize a part of the movement on the right side GesturePartResult resultRIGHT = _segments[_currentSegment].Update(skeleton, RIGHT); GesturePartResult result = GesturePartResult.Failed; if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted) { DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Wave your hand"; } //If the user is doing the movement with his left arm if (resultLEFT == GesturePartResult.Succeeded) { //If he wasnt's doing it with his left arm before if (currentWaveSide != LEFT) { //We reset the counters to detect the movement Reset(); currentWaveSide = LEFT; } //We indicate that one of the part of the gesture has been recognized result = GesturePartResult.Succeeded; } //If the user is doing the movement with his right arm if (resultRIGHT == GesturePartResult.Succeeded) { //If he wasnt's doing it with his right arm before if (currentWaveSide != RIGHT) { //We reset the counters to detect the movement Reset(); currentWaveSide = RIGHT; } //We indicate that one of the part of the gesture has been recognized result = GesturePartResult.Succeeded; } if (result == GesturePartResult.Succeeded) { //If the movement as not been recognized entirely if (_currentSegment + 1 < _segments.Length) { //We advance to the next part of the mouvement and reset the number of frame the user had to do this part of the gesture _currentSegment++; _frameCount = 0; _frameGesture++; } else { //If the gesture has been recognized, we throw the event if (GestureRecognized != null) { DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized(this, new EventArgs()); Reset(); } } } //If the user took too much time to do the nextpart of the gesture else if (_frameCount == WINDOW_SIZE) { //We erset the recognition Reset(); } else { //We keep counting the nuber of frame to do the entire movement if (_currentSegment != 0) { _frameGesture++; } _frameCount++; } }
public void Update(Skeleton skeleton) { if (_paused) { if (_frameCount == _pausedFrameCount) { _paused = false; } _frameCount++; } GesturePartResult result = _segments[_currentSegment].Update(skeleton); if (result == GesturePartResult.Success) { if (_currentSegment + 1 < _segments.Length) { _currentSegment++; _frameCount = 0; _pausedFrameCount = MAX_PAUSE_COUNT; _paused = true; } else { if (GestureDetected != null) { var sB = new SkeletonB(skeleton); var height = sB.getHeight(); var fullHeight = sB.getAllHeight(); if (height > 0.40) { if (Gesture.oldGesture.Equals(_name)) { return; } Console.WriteLine("Gesture detected with height: {0}, oldGesture : {1}", height, Gesture.oldGesture); GestureDetected(this, new GestureEventArgs(_name, skeleton.TrackingId)); Gesture.oldGesture = _name; Console.WriteLine(Gesture.oldGesture); } else { Console.WriteLine("ERROR: Gesture detected with height: {0}", height); } Reset(); } else { Console.WriteLine("Unknown gesture"); Gesture.oldGesture = "null"; } } } else if (result == GesturePartResult.Fail || _frameCount == WINDOW_SIZE) { if (_frameCount == WINDOW_SIZE) { Console.WriteLine("frameCount out OU Gesture Failed, seg = {0}, frame = {1}", _currentSegment, _frameCount); Gesture.oldGesture = "null"; } if (_frameCount >= WINDOW_SIZE / 2) { Gesture.oldGesture = "null"; } Reset(); } else { _frameCount++; _pausedFrameCount = MAX_PAUSE_COUNT / 2; _paused = true; } }
private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { Skeleton first = GetFirstSkeleton(e); leftHandUpGestureResult = leftHandUp.CheckGesture(first); rightHandUpGestureResult = rightHandUp.CheckGesture(first); swipeLeftSegment1Result = swipeLeftSeg1.CheckGesture(first, swipeLeftSegment1Result); swipeLeftSegment2Result = swipeLeftSeg2.CheckGesture(first, swipeLeftSegment2Result); swipeRightSegment1Result = swipeRightSeg1.CheckGesture(first); swipeRightSegment2Result = swipeRightSeg2.CheckGesture(first); rightHandForwardGestureResult = rightHandForward.CheckGesture(first); leftHandForwardGestureResult = leftHandForward.CheckGesture(first); swipeDownResult = swipeDown.CheckGesture(first, swipeDownResult); // Check if left hand is up if (leftHandUpGestureResult == GesturePartResult.Succeed) { leftHandUpSpan.Foreground = Brushes.Green; leftHandUpSpan.FontWeight = FontWeights.Bold; } else { leftHandUpSpan.Foreground = Brushes.Red; leftHandUpSpan.FontWeight = FontWeights.Bold; } // Check if right hand is up if (rightHandUpGestureResult == GesturePartResult.Succeed) { rightHandUpSpan.Foreground = Brushes.Green; rightHandUpSpan.FontWeight = FontWeights.Bold; } else { rightHandUpSpan.Foreground = Brushes.Red; rightHandUpSpan.FontWeight = FontWeights.Bold; } // Check if both hands are up if (leftHandUpGestureResult == GesturePartResult.Succeed && rightHandUpGestureResult == GesturePartResult.Succeed) { bothHandUpSpan.Foreground = Brushes.Green; bothHandUpSpan.FontWeight = FontWeights.Bold; } else { bothHandUpSpan.Foreground = Brushes.Red; bothHandUpSpan.FontWeight = FontWeights.Bold; } // Swipe Left Segment if (swipeLeftSegment2Result == GesturePartResult.Pausing) { swipedLeftSpan.Foreground = Brushes.Green; swipedLeftSpan.FontWeight = FontWeights.Bold; } else { swipedLeftSpan.Foreground = Brushes.Red; swipedLeftSpan.FontWeight = FontWeights.Bold; } // Left hand up and swipe if ((swipeLeftSegment2Result == GesturePartResult.Pausing) && (leftHandUpGestureResult == GesturePartResult.Succeed)) { swipedLeftSpan.Foreground = Brushes.Black; swipedLeftSpan.FontWeight = FontWeights.Bold; leftHandUpSpan.Foreground = Brushes.Black; leftHandUpSpan.FontWeight = FontWeights.Bold; } //Swipe down segment if (swipeDownResult == GesturePartResult.Succeed) { swipedRightSpan.Foreground = Brushes.Green; swipedRightSpan.FontWeight = FontWeights.Bold; } else { swipedRightSpan.Foreground = Brushes.Red; swipedRightSpan.FontWeight = FontWeights.Bold; } // Forward gestures if (rightHandForwardGestureResult == GesturePartResult.Succeed) { rightHandForwardSpan.Foreground = Brushes.Green; rightHandForwardSpan.FontWeight = FontWeights.Bold; } else { rightHandForwardSpan.Foreground = Brushes.Red; rightHandForwardSpan.FontWeight = FontWeights.Bold; } if (leftHandForwardGestureResult == GesturePartResult.Succeed) { leftHandForwardSpan.Foreground = Brushes.Green; leftHandForwardSpan.FontWeight = FontWeights.Bold; } else { leftHandForwardSpan.Foreground = Brushes.Red; leftHandForwardSpan.FontWeight = FontWeights.Bold; } }
private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { Skeleton first = GetFirstSkeleton(e); leftHandUpGestureResult = leftHandUp.CheckGesture(first); rightHandUpGestureResult = rightHandUp.CheckGesture(first); swipeLeftSegment2Result = swipeLeftSeg2.CheckGesture(first, swipeLeftSegment2Result); swipeRightSegment2Result = swipeRightSeg2.CheckGesture(first); rightHandForwardGestureResult = rightHandForward.CheckGesture(first); leftHandForwardGestureResult = leftHandForward.CheckGesture(first); swipeDownResult = swipeDown.CheckGesture(first, swipeDownResult); // Check if left hand is up if (leftHandUpGestureResult == GesturePartResult.Succeed) { } else { } // Check if right hand is up if (rightHandUpGestureResult == GesturePartResult.Succeed) { } else { } // Check if both hands are up if (leftHandUpGestureResult == GesturePartResult.Succeed && rightHandUpGestureResult == GesturePartResult.Succeed) { } else { } // Swipe Left Segment if (swipeLeftSegment2Result == GesturePartResult.Pausing) { } else { } // Left hand up and swipe if ((swipeLeftSegment2Result == GesturePartResult.Pausing) && (leftHandUpGestureResult == GesturePartResult.Succeed)) { } //Swipe down segment if (swipeDownResult == GesturePartResult.Succeed) { } else { } // Forward gestures if (rightHandForwardGestureResult == GesturePartResult.Succeed) { } else { } if (leftHandForwardGestureResult == GesturePartResult.Succeed) { } else { } }
public void Update(KinectSensor sensor, Skeleton skeleton, System.Windows.Point skel2DCenter) { var left_foot = skeleton.Joints[JointType.AnkleLeft]; var right_foot = skeleton.Joints[JointType.AnkleRight]; if (left_foot.TrackingState != JointTrackingState.Tracked || right_foot.TrackingState != JointTrackingState.Tracked) { Reset(); return; } // Update filter var left_foot_pos = left_foot.Position; var right_foot_pos = right_foot.Position; float pos_feet_x = (left_foot_pos.X + right_foot_pos.X) / 2.0f; float pos_feet_y = (left_foot_pos.Y + right_foot_pos.Y) / 2.0f; syntheticData.state[0, 0] = pos_feet_x; syntheticData.state[1, 0] = pos_feet_y; // Prediction from Kalman for this timestep. float[] pred = new float[4]; kal.Predict(); kal.StatePre.CopyTo(pred); PointF predictedPositionPoint = new PointF(pred[0], pred[1]); // Update kalman state with a noice induced measurement. Matrix <float> measurement = syntheticData.GetMeasurement(); PointF measurePoint = new PointF(measurement[0, 0], measurement[1, 0]); kal.Correct(measurement.Mat); // Get an adjusted internal state measurement. float[] estimated = new float[4]; kal.StatePost.CopyTo(estimated); PointF estimatedPositionPoint = new PointF(estimated[0], estimated[1]); // syntheticData.GoToNextState(); // Note: This is the data passed into the segment recognizer float[][] kal_results = new float[2][] { pred, estimated }; GesturePartResult result = segments[currentSegmentIdx].Update(sensor, skeleton, kal_results); if (result == GesturePartResult.Succeeded) { if (currentSegmentIdx + 1 < segments.Length) { currentSegmentIdx++; frameCount = 0; } else { if (OnRecognized != null) { OnRecognized(this, new GestureEventArgs(skeleton.TrackingId, skel2DCenter)); Reset(); } } } else if (result == GesturePartResult.Failed || frameCount == WINDOW_SIZE) { Reset(); } else { frameCount++; } }
/// <summary> /// Occurs when [gesture recognised]. /// </summary> ///public event EventHandler<GestureEventArgs> GestureRecognised; /// <summary> /// Updates the gesture. /// </summary> /// <param name="data">The skeleton data.</param> public void UpdateGesture(SkeletonWrapper skeletonWrapper) { if (this.paused) { if (this.frameCount == this.pausedFrameCount) { this.paused = false; } this.frameCount++; } GesturePartResult result = this.gestureParts[this.currentGesturePart].CheckGesture(skeletonWrapper); if (result == GesturePartResult.Suceed) { if (this.currentGesturePart + 1 < this.gestureParts.Length) { this.currentGesturePart++; this.frameCount = 0; this.pausedFrameCount = 10; this.paused = true; } else { //動作結束 //範例 if (this.type == GestureType.LeftSwipe) { isSwipeLeft = true; Debug.Log("揮左成功"); } if (this.type == GestureType.RightSwipe) { isSwipeRight = true; Debug.Log("揮右"); } if (this.type == GestureType.UpSwipe) { isSwipeUp = true; //這裡加入避免揮上下連續判斷的緩衝-->不知如何加 Debug.Log("揮上"); } if (this.type == GestureType.DownSwipe) { isSwipeDown = true; Debug.Log("揮下"); } Debug.Log("動作結束"); this.Reset(); /* * if (this.GestureRecognised != null) * { * this.GestureRecognised(this, new GestureEventArgs(this.type, data.TrackingID, data.UserIndex)); * this.Reset(); * } */ } } else if (result == GesturePartResult.Fail || this.frameCount == 50) { this.currentGesturePart = 0; this.frameCount = 0; this.pausedFrameCount = 5; this.paused = true; } else { this.frameCount++; this.pausedFrameCount = 5; this.paused = true; } }
private void GestureRecognized(object sender, GestureEventArgs e) { if (e.GestureType == GestureType.RightUp) { rightHandUpGestureResult = GesturePartResult.Succeed; //Mouse down } else if (e.GestureType == GestureType.LeftUp) { leftHandUpGestureResult = GesturePartResult.Succeed; //Mouse down } else if (e.GestureType == GestureType.RightSwipe) { swipeRightSegment2Result = GesturePartResult.Succeed; //press correct key spin CCW } else if (e.GestureType == GestureType.LeftSwipe) { swipeLeftSegment2Result = GesturePartResult.Succeed; //press correct key spin clockwise } else if (e.GestureType == GestureType.SwipeDown) { swipeDownResult = GesturePartResult.Succeed; //whatever goes here } }
private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { Skeleton first = GetFirstSkeleton(e); if (first == null) { return; } else { Console.WriteLine("Skeleton retrieval success"); } previousLeftHandUpGestureResult = leftHandUpGestureResult; leftHandUpGestureResult = leftHandUp.CheckGesture(first); rightHandUpGestureResult = rightHandUp.CheckGesture(first); swipeLeftSegment2Result = swipeLeftSeg2.CheckGesture(first, swipeLeftSegment2Result); swipeRightSegment2Result = swipeRightSeg2.CheckGesture(first); rightHandForwardGestureResult = rightHandForward.CheckGesture(first); leftHandForwardGestureResult = leftHandForward.CheckGesture(first); swipeDownResult = swipeDown.CheckGesture(first, swipeDownResult); ControlMouse(first); // Check if left hand is up if (leftHandUpGestureResult == GesturePartResult.Succeed) { if (previousLeftHandUpGestureResult == GesturePartResult.Fail) { Form1.rightClick(); } } else { if (previousLeftHandUpGestureResult == GesturePartResult.Succeed) { Form1.rightMouseUp(); } } // Check if right hand is up if (rightHandUpGestureResult == GesturePartResult.Succeed) { } else { } // Check if both hands are up if (leftHandUpGestureResult == GesturePartResult.Succeed && rightHandUpGestureResult == GesturePartResult.Succeed) { } else { } // Swipe Left Segment if (swipeLeftSegment2Result == GesturePartResult.Pausing) { } else { } // Left hand up and swipe if ((swipeLeftSegment2Result == GesturePartResult.Pausing) && (leftHandUpGestureResult == GesturePartResult.Succeed)) { } //Swipe down segment if (swipeDownResult == GesturePartResult.Succeed) { } else { } // Forward gestures if (rightHandForwardGestureResult == GesturePartResult.Succeed) { } else { } if (leftHandForwardGestureResult == GesturePartResult.Succeed) { if (previousLeftForwardGestureResult == GesturePartResult.Fail) { //Form1.leftClick(); } } else { if (previousLeftHandUpGestureResult == GesturePartResult.Succeed) { //Form1.leftClickUp(); } } }