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 // Check if right hand is below the right hip
var result = 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.SpineBase].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;
return result; return result;

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

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

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

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

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

Loading…
Cancel
Save