fixes and improvements

begin_project_view
nico-dev 1 year ago
parent ba0db4525e
commit 703a1cfb35

@ -12,11 +12,26 @@ namespace KinectUtils
/// </summary> /// </summary>
public abstract class Posture : BaseGesture public abstract class Posture : BaseGesture
{ {
private bool postureWasRecognized = false;
/// <summary> /// <summary>
/// Tests the posture. /// Tests the posture.
/// </summary> /// </summary>
/// <param name="body">The body</param> /// <param name="body">The body</param>
/// <returns></returns> /// <returns></returns>
protected abstract bool TestPosture(Body body); protected abstract bool TestPosture(Body body);
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
postureWasRecognized = TestPosture(body);
if (postureWasRecognized)
{
OnGestureRecognized();
}
}
} }
} }

@ -24,20 +24,20 @@ namespace KinectUtils
PostureHandUpLeft postureHandUpLeft = new PostureHandUpLeft(); PostureHandUpLeft postureHandUpLeft = new PostureHandUpLeft();
PostureHandDownLeft postureHandDownLeft = new PostureHandDownLeft(); PostureHandDownLeft postureHandDownLeft = new PostureHandDownLeft();
PostureHandDownRight postureHandDownRight = new PostureHandDownRight(); PostureHandDownRight postureHandDownRight = new PostureHandDownRight();
PostureTwoHandsDown postureTwoHandsDown = new PostureTwoHandsDown(); //PostureTwoHandsDown postureTwoHandsDown = new PostureTwoHandsDown();
PostureTwoHandsUp postureTwoHandsUp = new PostureTwoHandsUp(); //PostureTwoHandsUp postureTwoHandsUp = new PostureTwoHandsUp();
// Gesture // Gesture
SoccerShootGesture soccerShootGesture = new SoccerShootGesture(); SoccerShootGesture soccerShootGesture = new SoccerShootGesture();
BaseGesture[] gestures = new BaseGesture[7]; BaseGesture[] gestures = new BaseGesture[5];
gestures[0] = postureHandUpLeft; gestures[0] = postureHandUpLeft;
gestures[1] = postureHandUpRight; gestures[1] = postureHandUpRight;
gestures[2] = postureHandDownLeft; gestures[2] = postureHandDownLeft;
gestures[3] = postureHandDownRight; gestures[3] = postureHandDownRight;
gestures[4] = postureTwoHandsDown; //gestures[4] = postureTwoHandsDown;
gestures[5] = postureTwoHandsUp; //gestures[5] = postureTwoHandsUp;
gestures[6] = soccerShootGesture; gestures[4] = soccerShootGesture;
return gestures; return gestures;
} }

@ -19,21 +19,6 @@ namespace MyGestureBank
GestureName = "HandDownLeft"; GestureName = "HandDownLeft";
} }
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand down left");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary> /// <summary>
/// The test posture method. /// The test posture method.
/// </summary> /// </summary>
@ -43,7 +28,14 @@ namespace MyGestureBank
protected override bool TestPosture(Body body) protected override bool TestPosture(Body body)
{ {
// Check if the left hand is below the left hip // Check if the left hand is below the left hip
return body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.HipLeft].Position.Y;
bool handLeft = body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.HipLeft].Position.Y;
var result = handLeft &&
body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.HipRight].Position.Y &&
body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y;
return result;
} }
} }
} }

@ -19,21 +19,6 @@ namespace MyGestureBank
GestureName = "HandDownRight"; GestureName = "HandDownRight";
} }
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand down right");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary> /// <summary>
/// The test posture method. /// The test posture method.
/// </summary> /// </summary>
@ -43,7 +28,11 @@ namespace MyGestureBank
protected override bool TestPosture(Body body) protected override bool TestPosture(Body body)
{ {
// Check if right hand is below the right hip // Check if right hand is below the right hip
return body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.HipRight].Position.Y; var result = body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.HipRight].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.HipLeft].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y;
return result;
} }
} }
} }

@ -19,21 +19,6 @@ namespace MyGestureBank
GestureName = "HandUpLeft"; GestureName = "HandUpLeft";
} }
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand up left");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary> /// <summary>
/// The test posture method. /// The test posture method.
/// </summary> /// </summary>
@ -44,7 +29,8 @@ namespace MyGestureBank
{ {
// Check if the left hand is above the left shoulder // Check if the left hand is above the left shoulder
return body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y && return body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y; body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.HipRight].Position.Y;
} }
} }
} }

@ -22,20 +22,6 @@ namespace MyGestureBank
GestureName = "HandUpRight"; GestureName = "HandUpRight";
} }
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body"></param>
public override void TestGesture(Body body)
{
if(TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand up right");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary> /// <summary>
/// Tests the posture. /// Tests the posture.
/// </summary> /// </summary>
@ -44,7 +30,8 @@ namespace MyGestureBank
protected override bool TestPosture(Body body) protected override bool TestPosture(Body body)
{ {
return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y && return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y; body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.HipLeft].Position.Y;
} }
} }
} }

@ -19,20 +19,6 @@ namespace MyGestureBank
GestureName = "HandsMid"; GestureName = "HandsMid";
} }
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, both hands middle");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary> /// <summary>
/// The test posture method. /// The test posture method.
/// </summary> /// </summary>

@ -19,21 +19,6 @@ namespace MyGestureBank
GestureName = "HandsUp"; GestureName = "HandsUp";
} }
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, two hands up");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary> /// <summary>
/// The test posture method. /// The test posture method.
/// </summary> /// </summary>

@ -207,7 +207,7 @@ namespace PenaltyMaster3000.Helpers
break; break;
case "HandDownLeft": case "HandDownLeft":
QuestionPointTopRightVisibility = Visibility.Visible; QuestionPointDownLeftVisibility = Visibility.Visible;
break; break;
default: return; default: return;
@ -246,22 +246,18 @@ namespace PenaltyMaster3000.Helpers
switch (shotPosition) switch (shotPosition)
{ {
case "HandUpRight": case "HandUpRight":
QuestionPointTopRightVisibility = Visibility.Hidden;
BallTopRightVisibility = Visibility.Visible; BallTopRightVisibility = Visibility.Visible;
break; break;
case "HandUpLeft": case "HandUpLeft":
QuestionPointTopLeftVisibility = Visibility.Hidden;
BallTopLeftVisibility = Visibility.Visible; BallTopLeftVisibility = Visibility.Visible;
break; break;
case "HandDownRight": case "HandDownRight":
QuestionPointDownRightVisibility = Visibility.Hidden;
BallDownRightVisibility = Visibility.Visible; BallDownRightVisibility = Visibility.Visible;
break; break;
case "HandDownLeft": case "HandDownLeft":
QuestionPointTopRightVisibility = Visibility.Hidden;
BallTopRightVisibility = Visibility.Visible; BallTopRightVisibility = Visibility.Visible;
break; break;
@ -295,7 +291,7 @@ namespace PenaltyMaster3000.Helpers
break; break;
case "HandDownLeft": case "HandDownLeft":
GoalTopRightVisibility = Visibility.Visible; GoalDownLeftVisibility = Visibility.Visible;
break; break;
default: return; default: return;
@ -331,5 +327,15 @@ namespace PenaltyMaster3000.Helpers
GoalDownLeftVisibility = Visibility.Hidden; GoalDownLeftVisibility = Visibility.Hidden;
QuestionPointDownLeftVisibility = Visibility.Hidden; QuestionPointDownLeftVisibility = Visibility.Hidden;
} }
public void HideQuestionPoint()
{
QuestionPointTopRightVisibility = Visibility.Hidden;
QuestionPointTopMiddleVisibility = Visibility.Hidden;
QuestionPointTopLeftVisibility= Visibility.Hidden;
QuestionPointDownRightVisibility= Visibility.Hidden;
QuestionPointDownMiddleVisibility= Visibility.Hidden;
QuestionPointDownLeftVisibility= Visibility.Hidden;
}
} }
} }

@ -237,8 +237,8 @@ namespace PenaltyMaster3000.ViewModel
//int randomIndex = random.Next(goalVisibilities.Count); //int randomIndex = random.Next(goalVisibilities.Count);
// Let the player choose a angle to shoot // Let the player choose a angle to shoot
await DisplayActionText("Shooter's turn. Get ready !", 3); await DisplayActionText("Shooter's turn. Get ready !", 2);
await DisplayActionText("Choose an angle to shoot.", 5); await DisplayActionText("Choose an angle to shoot.", 2);
// Read a gesture for 5 seconds // Read a gesture for 5 seconds
// Save the shot on the ShotHolder attribute // Save the shot on the ShotHolder attribute
@ -247,12 +247,13 @@ namespace PenaltyMaster3000.ViewModel
// IsShootCompleted = false; // IsShootCompleted = false;
// Call the save method // Call the save method
Save(); Save();
VsMgr.HideQuestionPoint();
} }
private async void Save() private async void Save()
{ {
await DisplayActionText("GoalKeeper's turn. Get ready !", 3); await DisplayActionText("GoalKeeper's turn. Get ready !", 2);
await DisplayActionText("Choose an angle to defend.", 5); await DisplayActionText("Choose an angle to defend.", 2);
DefenseHolder = await ReadAGesture(2); DefenseHolder = await ReadAGesture(2);
@ -262,6 +263,7 @@ namespace PenaltyMaster3000.ViewModel
// IsSaveCompleted = false; // IsSaveCompleted = false;
Result(); Result();
VsMgr.HideQuestionPoint();
} }
private async void Result() private async void Result()
@ -393,7 +395,7 @@ namespace PenaltyMaster3000.ViewModel
// load all // load all
GestureManager.AddGestures(this.GestureFactory); GestureManager.AddGestures(this.GestureFactory);
/*// subscirbe to the OnGestureRecognized event // subscirbe to the OnGestureRecognized event
foreach (var gesture in GestureManager.KnownGestures) foreach (var gesture in GestureManager.KnownGestures)
{ {
gesture.GestureRecognized += (sender, args) => gesture.GestureRecognized += (sender, args) =>
@ -403,27 +405,25 @@ namespace PenaltyMaster3000.ViewModel
{ {
// [TODO?] Display gesture on screen // [TODO?] Display gesture on screen
gestureRead = args.GestureName; gestureRead = args.GestureName;
*/
gestureRead = "HandUpRight"; //TEST [TO REPLACE BY gestureRead = args.GestureName;]
VsMgr.SetQuestionPoint(gestureRead); VsMgr.SetQuestionPoint(gestureRead);
/*
} }
}; };
} }
// Read frames for ReadTimeSeconds // Read frames for ReadTimeSeconds
GestureManager.StartAcquiringFrames(GestureManager.KinectManager); GestureManager.StartAcquiringFrames(GestureManager.KinectManager);
await Task.Delay(ReadTimeInSeconds*1000); await Task.Delay(ReadTimeInSeconds*5000);
// Stop reading and unsub from the GestureRecognized event to prevent memory leaks // Stop reading and unsub from the GestureRecognized event to prevent memory leaks
GestureManager.StopAcquiringFrame(GestureManager.KinectManager); GestureManager.StopAcquiringFrame(GestureManager.KinectManager);
foreach (var gesture in GestureManager.KnownGestures) foreach (var gesture in GestureManager.KnownGestures)
{ {
gesture.GestureRecognized = null; gesture.GestureRecognized = null;
}*/ }
// return gestureRead; // return gestureRead;
return "HandUpRight"; return gestureRead;
} }
} }
} }

@ -23,17 +23,17 @@ namespace PostureTester
SoccerShootGesture soccerShootGesture = new SoccerShootGesture(); SoccerShootGesture soccerShootGesture = new SoccerShootGesture();
BaseGesture[] gestures = new BaseGesture[1]; IGestureFactory factory = new PenaltyMasterGestureFactory();
/*gestures[0] = postureHandUpLeft;
gestures[1] = postureHandUpRight;
gestures[2] = postureHandDownLeft;
gestures[3] = postureHandDownRight;
gestures[4] = postureTwoHandsDown;
gestures[5] = postureTwoHandsUp;*/
gestures[0] = soccerShootGesture; GestureManager.AddGestures(factory);
GestureManager.AddGestures(gestures); foreach (var gesture in GestureManager.KnownGestures)
{
gesture.GestureRecognized += (sender, arg) =>
{
Console.WriteLine(arg.GestureName);
};
}
GestureManager.StartAcquiringFrames(GestureManager.KinectManager); GestureManager.StartAcquiringFrames(GestureManager.KinectManager);

Loading…
Cancel
Save