fixes and improvements

begin_project_view
nico-dev 9 months ago
parent ba0db4525e
commit 703a1cfb35

@ -12,11 +12,26 @@ namespace KinectUtils
/// </summary>
public abstract class Posture : BaseGesture
{
private bool postureWasRecognized = false;
/// <summary>
/// Tests the posture.
/// </summary>
/// <param name="body">The body</param>
/// <returns></returns>
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();
PostureHandDownLeft postureHandDownLeft = new PostureHandDownLeft();
PostureHandDownRight postureHandDownRight = new PostureHandDownRight();
PostureTwoHandsDown postureTwoHandsDown = new PostureTwoHandsDown();
PostureTwoHandsUp postureTwoHandsUp = new PostureTwoHandsUp();
//PostureTwoHandsDown postureTwoHandsDown = new PostureTwoHandsDown();
//PostureTwoHandsUp postureTwoHandsUp = new PostureTwoHandsUp();
// Gesture
SoccerShootGesture soccerShootGesture = new SoccerShootGesture();
BaseGesture[] gestures = new BaseGesture[7];
BaseGesture[] gestures = new BaseGesture[5];
gestures[0] = postureHandUpLeft;
gestures[1] = postureHandUpRight;
gestures[2] = postureHandDownLeft;
gestures[3] = postureHandDownRight;
gestures[4] = postureTwoHandsDown;
gestures[5] = postureTwoHandsUp;
gestures[6] = soccerShootGesture;
//gestures[4] = postureTwoHandsDown;
//gestures[5] = postureTwoHandsUp;
gestures[4] = soccerShootGesture;
return gestures;
}

@ -19,21 +19,6 @@ namespace MyGestureBank
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>
/// The test posture method.
/// </summary>
@ -43,7 +28,14 @@ namespace MyGestureBank
protected override bool TestPosture(Body body)
{
// 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";
}
/// <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>
/// The test posture method.
/// </summary>
@ -43,7 +28,11 @@ namespace MyGestureBank
protected override bool TestPosture(Body body)
{
// 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";
}
/// <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>
/// The test posture method.
/// </summary>
@ -44,7 +29,8 @@ namespace MyGestureBank
{
// Check if the left hand is above the left shoulder
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";
}
/// <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>
/// Tests the posture.
/// </summary>
@ -44,7 +30,8 @@ namespace MyGestureBank
protected override bool TestPosture(Body body)
{
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";
}
/// <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>
/// The test posture method.
/// </summary>

@ -19,21 +19,6 @@ namespace MyGestureBank
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>
/// The test posture method.
/// </summary>

@ -207,7 +207,7 @@ namespace PenaltyMaster3000.Helpers
break;
case "HandDownLeft":
QuestionPointTopRightVisibility = Visibility.Visible;
QuestionPointDownLeftVisibility = Visibility.Visible;
break;
default: return;
@ -246,22 +246,18 @@ namespace PenaltyMaster3000.Helpers
switch (shotPosition)
{
case "HandUpRight":
QuestionPointTopRightVisibility = Visibility.Hidden;
BallTopRightVisibility = Visibility.Visible;
break;
case "HandUpLeft":
QuestionPointTopLeftVisibility = Visibility.Hidden;
BallTopLeftVisibility = Visibility.Visible;
break;
case "HandDownRight":
QuestionPointDownRightVisibility = Visibility.Hidden;
BallDownRightVisibility = Visibility.Visible;
break;
case "HandDownLeft":
QuestionPointTopRightVisibility = Visibility.Hidden;
BallTopRightVisibility = Visibility.Visible;
break;
@ -295,7 +291,7 @@ namespace PenaltyMaster3000.Helpers
break;
case "HandDownLeft":
GoalTopRightVisibility = Visibility.Visible;
GoalDownLeftVisibility = Visibility.Visible;
break;
default: return;
@ -331,5 +327,15 @@ namespace PenaltyMaster3000.Helpers
GoalDownLeftVisibility = 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);
// Let the player choose a angle to shoot
await DisplayActionText("Shooter's turn. Get ready !", 3);
await DisplayActionText("Choose an angle to shoot.", 5);
await DisplayActionText("Shooter's turn. Get ready !", 2);
await DisplayActionText("Choose an angle to shoot.", 2);
// Read a gesture for 5 seconds
// Save the shot on the ShotHolder attribute
@ -247,12 +247,13 @@ namespace PenaltyMaster3000.ViewModel
// IsShootCompleted = false;
// Call the save method
Save();
VsMgr.HideQuestionPoint();
}
private async void Save()
{
await DisplayActionText("GoalKeeper's turn. Get ready !", 3);
await DisplayActionText("Choose an angle to defend.", 5);
await DisplayActionText("GoalKeeper's turn. Get ready !", 2);
await DisplayActionText("Choose an angle to defend.", 2);
DefenseHolder = await ReadAGesture(2);
@ -262,6 +263,7 @@ namespace PenaltyMaster3000.ViewModel
// IsSaveCompleted = false;
Result();
VsMgr.HideQuestionPoint();
}
private async void Result()
@ -393,7 +395,7 @@ namespace PenaltyMaster3000.ViewModel
// load all
GestureManager.AddGestures(this.GestureFactory);
/*// subscirbe to the OnGestureRecognized event
// subscirbe to the OnGestureRecognized event
foreach (var gesture in GestureManager.KnownGestures)
{
gesture.GestureRecognized += (sender, args) =>
@ -403,27 +405,25 @@ namespace PenaltyMaster3000.ViewModel
{
// [TODO?] Display gesture on screen
gestureRead = args.GestureName;
*/
gestureRead = "HandUpRight"; //TEST [TO REPLACE BY gestureRead = args.GestureName;]
VsMgr.SetQuestionPoint(gestureRead);
/*
}
};
}
// Read frames for ReadTimeSeconds
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
GestureManager.StopAcquiringFrame(GestureManager.KinectManager);
foreach (var gesture in GestureManager.KnownGestures)
{
gesture.GestureRecognized = null;
}*/
}
// return gestureRead;
return "HandUpRight";
return gestureRead;
}
}
}

@ -23,17 +23,17 @@ namespace PostureTester
SoccerShootGesture soccerShootGesture = new SoccerShootGesture();
BaseGesture[] gestures = new BaseGesture[1];
/*gestures[0] = postureHandUpLeft;
gestures[1] = postureHandUpRight;
gestures[2] = postureHandDownLeft;
gestures[3] = postureHandDownRight;
gestures[4] = postureTwoHandsDown;
gestures[5] = postureTwoHandsUp;*/
IGestureFactory factory = new PenaltyMasterGestureFactory();
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);

Loading…
Cancel
Save