Shooting gesture added

exo2
nico-dev 1 year ago
parent ec2bff1e45
commit 036a1f5d50

@ -0,0 +1,29 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KinectUtils
{
public abstract class Gesture : BaseGesture
{
public bool IsTesting;
protected int MinNbOfFrames;
protected int MaxNbOfFrames;
private int mCurrentFrameCount;
protected abstract bool TestInitialConditions(Body body);
protected abstract bool TestPosture(Body body);
protected abstract bool TestRunningGesture(Body body);
protected abstract bool TestEndConditions(Body body);
}
}

@ -45,6 +45,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="BaseGesture.cs" /> <Compile Include="BaseGesture.cs" />
<Compile Include="Gesture.cs" />
<Compile Include="GestureManager.cs" /> <Compile Include="GestureManager.cs" />
<Compile Include="GestureRecognizedEventArgs.cs" /> <Compile Include="GestureRecognizedEventArgs.cs" />
<Compile Include="IGestureFactory.cs" /> <Compile Include="IGestureFactory.cs" />

@ -51,6 +51,7 @@
<Compile Include="PostureTwoHandsUp.cs" /> <Compile Include="PostureTwoHandsUp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PostureTwoHandsDown.cs" /> <Compile Include="PostureTwoHandsDown.cs" />
<Compile Include="SoccerShootGesture .cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />

@ -0,0 +1,84 @@
using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MyGestureBank
{
public class SoccerShootGesture : Gesture
{
private CameraSpacePoint lastLeftFootPosition;
private CameraSpacePoint lastRightFootPosition;
public SoccerShootGesture()
{
MinNbOfFrames = 10;
MaxNbOfFrames = 30;
}
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, shooting motion");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
protected override bool TestEndConditions(Body body)
{
float threshold = 0.05f;
bool areFeetClose = Math.Abs(body.Joints[JointType.FootLeft].Position.X - body.Joints[JointType.FootRight].Position.X) < threshold;
return areFeetClose;
}
protected override bool TestInitialConditions(Body body)
{
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;
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;
}
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;
}
protected override bool TestRunningGesture(Body body)
{
CameraSpacePoint currentLeftFootPosition = body.Joints[JointType.FootLeft].Position;
CameraSpacePoint currentRightFootPosition = body.Joints[JointType.FootRight].Position;
bool areFeetCloserThanLastFrame =
Math.Abs(currentLeftFootPosition.X) <= lastLeftFootPosition.X + 0.1f &&
Math.Abs(currentRightFootPosition.X) <= lastRightFootPosition.X + 0.1f;
lastLeftFootPosition = currentLeftFootPosition;
lastRightFootPosition = currentRightFootPosition;
return areFeetCloserThanLastFrame;
}
private bool IsFootBetweenHeadAndSpinBase(CameraSpacePoint footPosition, CameraSpacePoint headPosition, CameraSpacePoint hipPosition)
{
float maxY = headPosition.Y;
float minY = hipPosition.Y;
return footPosition.Y < maxY && footPosition.Y > minY;
}
}
}

@ -14,21 +14,24 @@ namespace PostureTester
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
PostureHandUpRight postureHandUpRight = new PostureHandUpRight(); /*PostureHandUpRight postureHandUpRight = new PostureHandUpRight();
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();*/
SoccerShootGesture soccerShootGesture = new SoccerShootGesture();
BaseGesture[] gestures = new BaseGesture[6]; BaseGesture[] gestures = new BaseGesture[1];
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[0] = soccerShootGesture;
GestureManager.AddGestures(gestures); GestureManager.AddGestures(gestures);

Loading…
Cancel
Save