improvements

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

@ -29,7 +29,7 @@ namespace MyGestureBank
{
// Check if right hand is below the right hip
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.SpineBase].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y;
return result;

@ -30,7 +30,7 @@ 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.HipRight].Position.Y;
body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.SpineBase].Position.Y;
}
}
}

@ -9,6 +9,9 @@ using System.Threading.Tasks;
namespace MyGestureBank
{
/// <summary>
/// The soccer shoot gesture.
/// </summary>
public class SoccerShootGesture : Gesture
{
private CameraSpacePoint lastLeftFootPosition;
@ -20,17 +23,24 @@ namespace MyGestureBank
MaxNbOfFrames = 30;
}
/// <summary>
/// Tests if the gesture is recognized.
/// </summary>
/// <param name="body"></param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, shooting motion");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary>
/// Tests the end conditions of the gesture.
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
protected override bool TestEndConditions(Body body)
{
float threshold = 0.05f;
@ -39,25 +49,42 @@ namespace MyGestureBank
return areFeetClose;
}
/// <summary>
/// Tests the intial conditions of the gesture.
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
protected override bool TestInitialConditions(Body body)
{
// Position of the feet + hips and head
CameraSpacePoint currentLeftFootPosition = body.Joints[JointType.FootLeft].Position;
CameraSpacePoint currentRightFootPosition = body.Joints[JointType.FootRight].Position;
CameraSpacePoint currentHipPosition = body.Joints[JointType.SpineBase].Position;
CameraSpacePoint currentHeadPosition = body.Joints[JointType.Head].Position;
// X and Y that should be respected
bool isWithinDistanceX = Math.Abs(currentLeftFootPosition.X - currentRightFootPosition.X) < Math.Abs(currentHipPosition.Y - currentHeadPosition.Y);
bool isWithinRangeY = IsFootBetweenHeadAndSpinBase(body.Joints[JointType.FootRight].Position, body.Joints[JointType.Head].Position, body.Joints[JointType.SpineBase].Position);
return isWithinDistanceX && isWithinRangeY;
}
/// <summary>
/// Test the posture
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
protected override bool TestPosture(Body body)
{
bool isWithinRangeY = IsFootBetweenHeadAndSpinBase(body.Joints[JointType.FootRight].Position, body.Joints[JointType.Head].Position, body.Joints[JointType.SpineBase].Position);
return isWithinRangeY;
}
/// <summary>
/// Tests the running gesture
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
protected override bool TestRunningGesture(Body body)
{
CameraSpacePoint currentLeftFootPosition = body.Joints[JointType.FootLeft].Position;

@ -195,18 +195,22 @@ namespace PenaltyMaster3000.Helpers
switch (gesturePosition)
{
case "HandUpRight":
HideQuestionPoint();
QuestionPointTopRightVisibility = Visibility.Visible;
break;
case "HandUpLeft":
HideQuestionPoint();
QuestionPointTopLeftVisibility = Visibility.Visible;
break;
case "HandDownRight":
HideQuestionPoint();
QuestionPointDownRightVisibility = Visibility.Visible;
break;
case "HandDownLeft":
HideQuestionPoint();
QuestionPointDownLeftVisibility = Visibility.Visible;
break;
@ -258,7 +262,7 @@ namespace PenaltyMaster3000.Helpers
break;
case "HandDownLeft":
BallTopRightVisibility = Visibility.Visible;
BallDownLeftVisibility = Visibility.Visible;
break;
default: return;

@ -27,21 +27,21 @@
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Visibility="{Binding VsMgr.GoalTopRightVisibility}"/>
Visibility="{Binding VsMgr.GoalTopLeftVisibility}"/>
<Image Source="/Images/football_ball.png"
Width="50"
Height="50"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Visibility="{Binding VsMgr.BallTopRightVisibility}"/>
Visibility="{Binding VsMgr.BallTopLeftVisibility}"/>
<Image Source="/Images/white_question_point.png"
Width="40"
Height="40"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="0"
Visibility="{Binding VsMgr.QuestionPointTopRightVisibility}"/>
Visibility="{Binding VsMgr.QuestionPointTopLeftVisibility}"/>
<Image Source="/Images/goalkeeper_top_middle.png"
Grid.Row="0"
@ -67,42 +67,42 @@
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="2"
Visibility="{Binding VsMgr.GoalTopLeftVisibility}"/>
Visibility="{Binding VsMgr.GoalTopRightVisibility}"/>
<Image Source="/Images/football_ball.png"
Width="50"
Height="50"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="2"
Visibility="{Binding VsMgr.BallTopLeftVisibility}"/>
Visibility="{Binding VsMgr.BallTopRightVisibility}"/>
<Image Source="/Images/white_question_point.png"
Width="40"
Height="40"
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="2"
Visibility="{Binding VsMgr.QuestionPointTopLeftVisibility}"/>
Visibility="{Binding VsMgr.QuestionPointTopRightVisibility}"/>
<Image Source="/Images/goalkeeper_down_right.png"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="0"
Visibility="{Binding VsMgr.GoalDownRightVisibility}"/>
Visibility="{Binding VsMgr.GoalDownLeftVisibility}"/>
<Image Source="/Images/football_ball.png"
Width="50"
Height="50"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="0"
Visibility="{Binding VsMgr.BallDownRightVisibility}"/>
Visibility="{Binding VsMgr.BallDownLeftVisibility}"/>
<Image Source="/Images/white_question_point.png"
Width="40"
Height="40"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="0"
Visibility="{Binding VsMgr.QuestionPointDownRightVisibility}"/>
Visibility="{Binding VsMgr.QuestionPointDownLeftVisibility}"/>
<Image Source="{Binding CurrentImageSource}"
Grid.Row="1"
@ -133,21 +133,21 @@
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="2"
Visibility="{Binding VsMgr.GoalDownLeftVisibility}"/>
Visibility="{Binding VsMgr.GoalDownRightVisibility}"/>
<Image Source="/Images/football_ball.png"
Width="50"
Height="50"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="2"
Visibility="{Binding VsMgr.BallDownLeftVisibility}"/>
Visibility="{Binding VsMgr.BallDownRightVisibility}"/>
<Image Source="/Images/white_question_point.png"
Width="40"
Height="40"
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="2"
Visibility="{Binding VsMgr.QuestionPointDownLeftVisibility}"/>
Visibility="{Binding VsMgr.QuestionPointDownRightVisibility}"/>
</Grid>
<Image Source="/Images/football_ball.png"

@ -242,12 +242,12 @@ namespace PenaltyMaster3000.ViewModel
// Read a gesture for 5 seconds
// Save the shot on the ShotHolder attribute
ShotHolder = await ReadAGesture(2);
ShotHolder = await ReadAPosture();
// IsShootCompleted = false;
// Call the save method
Save();
VsMgr.HideQuestionPoint();
await DisplayActionText("SHOOT!", 2);
await ReadShootingGesture();
Save();
}
private async void Save()
@ -255,7 +255,7 @@ namespace PenaltyMaster3000.ViewModel
await DisplayActionText("GoalKeeper's turn. Get ready !", 2);
await DisplayActionText("Choose an angle to defend.", 2);
DefenseHolder = await ReadAGesture(2);
DefenseHolder = await ReadAPosture();
// Arrêter le timer du déplacement automatique du Goal
goalTimer.Stop();
@ -388,8 +388,9 @@ namespace PenaltyMaster3000.ViewModel
/*
* Use the gesture manager to read a gesture
*/
private async Task<string> ReadAGesture(int ReadTimeInSeconds)
private Task<string> ReadAPosture()
{
var tcs = new TaskCompletionSource<string>();
string gestureRead = "";
// load all
@ -403,27 +404,72 @@ namespace PenaltyMaster3000.ViewModel
// If new gesture read, replace th gesture name
if(gestureRead != args.GestureName)
{
// [TODO?] Display gesture on screen
// save the recognized gesture
gestureRead = args.GestureName;
// display where
VsMgr.SetQuestionPoint(gestureRead);
if (!tcs.Task.IsCompleted)
{
tcs.SetResult(args.GestureName);
}
}
};
}
// Read frames for ReadTimeSeconds
GestureManager.StartAcquiringFrames(GestureManager.KinectManager);
await Task.Delay(ReadTimeInSeconds*5000);
// Stop reading and unsub from the GestureRecognized event to prevent memory leaks
GestureManager.StopAcquiringFrame(GestureManager.KinectManager);
return tcs.Task.ContinueWith(t =>
{
// 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 t.Result;
});
}
private Task<bool> ReadShootingGesture()
{
var tcs = new TaskCompletionSource<bool>();
// load all
GestureManager.AddGestures(this.GestureFactory);
// subscribe to the OnGestureRecognized event
foreach (var gesture in GestureManager.KnownGestures)
{
gesture.GestureRecognized = null;
var soccerShootGesture = gesture as SoccerShootGesture;
if (soccerShootGesture != null)
{
soccerShootGesture.GestureRecognized += (sender, args) =>
{
if (!tcs.Task.IsCompleted)
{
tcs.SetResult(true);
}
};
}
}
// return gestureRead;
return gestureRead;
// Read frames for ReadTimeInSeconds
GestureManager.StartAcquiringFrames(GestureManager.KinectManager);
return tcs.Task.ContinueWith(t =>
{
// 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 t.Result;
});
}
}
}

Loading…
Cancel
Save