ADD : Test Console Posture HandUpRight working in console

exo2
lobroda 1 year ago
parent 02c35bda79
commit 3d22413fd5

@ -132,6 +132,10 @@
<Project>{e527438a-dfa2-4ec6-9891-d4956152b093}</Project> <Project>{e527438a-dfa2-4ec6-9891-d4956152b093}</Project>
<Name>KinectConnection</Name> <Name>KinectConnection</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2bc300e4-d3c1-4e17-a011-380edb793182}</Project>
<Name>KinectUtils</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\CommunityToolkit.Mvvm.8.2.2\build\netstandard2.0\CommunityToolkit.Mvvm.targets" Condition="Exists('..\packages\CommunityToolkit.Mvvm.8.2.2\build\netstandard2.0\CommunityToolkit.Mvvm.targets')" /> <Import Project="..\packages\CommunityToolkit.Mvvm.8.2.2\build\netstandard2.0\CommunityToolkit.Mvvm.targets" Condition="Exists('..\packages\CommunityToolkit.Mvvm.8.2.2\build\netstandard2.0\CommunityToolkit.Mvvm.targets')" />

@ -33,9 +33,9 @@
<Ellipse Width="30" <Ellipse Width="30"
Height="30" Height="30"
Fill="{Binding KinectManager.Status, Converter={StaticResource KinectStatusToColorConverter}}" Fill="{Binding GestureManager.KinectManager.Status, Converter={StaticResource KinectStatusToColorConverter}}"
Grid.Column="1"/> Grid.Column="1"/>
<TextBlock Text="{Binding KinectManager.StatusText}" <TextBlock Text="{Binding GestureManager.KinectManager.StatusText}"
VerticalAlignment="Center" VerticalAlignment="Center"
FontWeight="Bold" FontWeight="Bold"
Grid.Column="3"/> Grid.Column="3"/>
@ -56,43 +56,10 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Content="Color"
Width="100"
Height="30"
Grid.Column="1"
Command="{Binding ColorCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Button.Resources>
</Button>
<Button Content="Depth"
Width="100"
Height="30"
Grid.Column="3"
Command="{Binding DepthCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Button.Resources>
</Button>
<Button Content="Infrared"
Width="100"
Height="30"
Grid.Column="5"
Command="{Binding IRCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Button.Resources>
</Button>
<Button Content="Body" <Button Content="Body"
Width="100" Width="100"
Height="30" Height="30"
Grid.Column="7" Grid.Column="5"
Command="{Binding BodyCommand}"> Command="{Binding BodyCommand}">
<Button.Resources> <Button.Resources>
<Style TargetType="Border"> <Style TargetType="Border">
@ -100,17 +67,6 @@
</Style> </Style>
</Button.Resources> </Button.Resources>
</Button> </Button>
<Button Content="Body and color"
Width="100"
Height="30"
Grid.Column="9"
Command="{Binding BodyColorCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Button.Resources>
</Button>
</Grid> </Grid>
<Grid Grid.Row="4"> <Grid Grid.Row="4">
@ -118,15 +74,9 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
Height="400" Height="400"
Width="400"> Width="400">
<Image Source="{Binding KinectStream.Source}" <Image Source="{Binding BodyImageStream.Source}"
Opacity="50"/> Opacity="50"/>
</Viewbox> </Viewbox>
<Viewbox Grid.Row="1"
HorizontalAlignment="Center"
Height="400"
Width="400">
<Image Source="{Binding KinectStream2.Source}"/>
</Viewbox>
</Grid> </Grid>
</Grid> </Grid>
</Window> </Window>

@ -11,7 +11,8 @@ namespace KinectSensorStreams.ViewModel
{ {
public class MainWindowVM : ObservableObject public class MainWindowVM : ObservableObject
{ {
private KinectStream kinectStream; private BodyImageStream bodyImageStream;
private GestureManager gestureManager;
#region Properties #region Properties
@ -20,33 +21,24 @@ namespace KinectSensorStreams.ViewModel
/// </summary> /// </summary>
public ICommand StartCommand { get; set; } public ICommand StartCommand { get; set; }
public ICommand ColorCommand { get; set; }
public ICommand BodyCommand { get; set; } public ICommand BodyCommand { get; set; }
public ICommand IRCommand { get; set; }
public ICommand DepthCommand { get; set; }
public ICommand BodyColorCommand { get; set; }
/// <summary>
/// The Kinect streams factory.
/// </summary>
public KinectStreamsFactory KinectStreamsFactory { get; set; }
/// <summary> /// <summary>
/// The Kinect stream property. /// The Kinect stream property.
/// </summary> /// </summary>
public KinectStream KinectStream public BodyImageStream BodyImageStream
{ {
get { return kinectStream; } get { return bodyImageStream; }
set { SetProperty(ref kinectStream, value); } set { SetProperty(ref bodyImageStream, value); }
} }
/// <summary> /// <summary>
/// The Secondary Kinect stream property. /// The Gesture Manager property.
/// </summary> /// </summary>
public KinectStream KinectStream2 public GestureManager GestureManager
{ {
get { return kinectStream; } get { return gestureManager; }
set { SetProperty(ref kinectStream, value); } set { SetProperty(ref gestureManager, value); }
} }
#endregion #endregion
@ -61,16 +53,8 @@ namespace KinectSensorStreams.ViewModel
// eventuellement a enlever : // eventuellement a enlever :
GestureManager = new GestureManager(); GestureManager = new GestureManager();
// factory
KinectStreamsFactory = new KinectStreamsFactory(new KinectManager());
StartCommand = new RelayCommand(Start); StartCommand = new RelayCommand(Start);
// [Question] : StartCommand ici peut être mieux que BeginInit() dans MainWindow.xaml.cs ?
ColorCommand = new RelayCommand(Color);
BodyCommand = new RelayCommand(Body); BodyCommand = new RelayCommand(Body);
IRCommand = new RelayCommand(IR);
DepthCommand = new RelayCommand(Depth);
BodyColorCommand = new RelayCommand(BodyColor);
} }
#endregion #endregion
@ -83,84 +67,17 @@ namespace KinectSensorStreams.ViewModel
private void Start() private void Start()
{ {
GestureManager.KinectManager.StartSensor(); GestureManager.KinectManager.StartSensor();
// Start the kinect sensor
//KinectStream.KinectManager.StartSensor();
// Start the color stream reader
//KinectStream.Start();
}
private void Color()
{
if(KinectStream != null)
{
KinectStream.Stop();
}
if (KinectStream2 != null)
{
KinectStream2.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.Color];
KinectStream.Start();
} }
private void Body() private void Body()
{ {
if (KinectStream != null) if (BodyImageStream != null)
{
KinectStream.Stop();
}
if (KinectStream2 != null)
{
KinectStream2.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.Body];
KinectStream.Start();
GestureManager.GestureRecognized += GestureManager.KnownGestures.FirstOrDefault().TestGesture(BodyImageStream.);
}
private void IR()
{
if (KinectStream != null)
{
KinectStream.Stop();
}
if (KinectStream2 != null)
{
KinectStream2.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.IR];
KinectStream.Start();
}
private void Depth()
{
if (KinectStream != null)
{
KinectStream.Stop();
}
if (KinectStream2 != null)
{
KinectStream2.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.Depth];
KinectStream.Start();
}
private void BodyColor()
{
if (KinectStream != null)
{
KinectStream.Stop();
}
if (KinectStream2 != null)
{ {
KinectStream2.Stop(); BodyImageStream.Stop();
} }
KinectStream = KinectStreamsFactory[KinectStreams.Color]; BodyImageStream = new BodyImageStream();
KinectStream.Start(); BodyImageStream.Start();
KinectStream2 = KinectStreamsFactory[KinectStreams.Body]; //GestureManager.GestureRecognized += GestureManager.KnownGestures.FirstOrDefault().TestGesture();
KinectStream2.Start();
} }
#endregion #endregion

@ -259,10 +259,6 @@ namespace KinectConnection
// dessiner les joints // dessiner les joints
this.DrawBody(joints, jointPoints, dc, drawPen); this.DrawBody(joints, jointPoints, dc, drawPen);
// dessiner les mains
this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
} }
} }
@ -306,27 +302,6 @@ namespace KinectConnection
} }
} }
/// <summary>
/// Méthode appelée pour le dessin d'une main
/// </summary>
private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext)
{
switch (handState)
{
case HandState.Closed:
drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize);
break;
case HandState.Open:
drawingContext.DrawEllipse(this.handOpenBrush, null, handPosition, HandSize, HandSize);
break;
case HandState.Lasso:
drawingContext.DrawEllipse(this.handLassoBrush, null, handPosition, HandSize, HandSize);
break;
}
}
/// <summary> /// <summary>
/// Méthode appelée pour le dessin d'un os /// Méthode appelée pour le dessin d'un os
/// </summary> /// </summary>

@ -54,6 +54,10 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2BC300E4-D3C1-4E17-A011-380EDB793182}</Project>
<Name>KinectUtils</Name>
</ProjectReference>
<ProjectReference Include="..\MyGestureBank\MyGestureBank.csproj"> <ProjectReference Include="..\MyGestureBank\MyGestureBank.csproj">
<Project>{d70b7357-6ff8-4f35-a283-8db4217c0c85}</Project> <Project>{d70b7357-6ff8-4f35-a283-8db4217c0c85}</Project>
<Name>MyGestureBank</Name> <Name>MyGestureBank</Name>

@ -1,4 +1,5 @@
using Microsoft.Kinect; using KinectUtils;
using Microsoft.Kinect;
using MyGestureBank; using MyGestureBank;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -11,51 +12,63 @@ namespace PostureTester
{ {
public class Program public class Program
{ {
private static List<Tuple<JointType, JointType>> bones = new List<Tuple<JointType, JointType>>(); private static KinectSensor kinectSensor;
private static PostureHandUpRight postureHandUpRight = new PostureHandUpRight();
static void Main(string[] args) static void Main(string[] args)
{ {
// Create a body kinectSensor = KinectSensor.GetDefault();
Body[] body = new Body[1]; postureHandUpRight.GestureRecognized += PostureHandUpRight_GestureRecognized;
// Create a posture if (kinectSensor != null)
PostureHandUpRight postureHandUpRight = new PostureHandUpRight(); {
PostureHandUpLeft postureHandUpLeft = new PostureHandUpLeft(); kinectSensor.Open();
// Make the body do the posture // Utilisation du bloc using pour bodyFrameReader
bones.Add(new Tuple<JointType, JointType>(JointType.Head, JointType.Neck)); using (var bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader())
bones.Add(new Tuple<JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); {
bones.Add(new Tuple<JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); if (bodyFrameReader != null)
bones.Add(new Tuple<JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); {
bones.Add(new Tuple<JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); // Abonnement à l'événement FrameArrived
bones.Add(new Tuple<JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
bones.Add(new Tuple<JointType, JointType>(JointType.SpineBase, JointType.HipRight));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); Console.WriteLine("Lecture des données du corps en cours... Appuyez sur une touche pour quitter.");
Console.ReadKey();
// Bras droit }
bones.Add(new Tuple<JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); }
bones.Add(new Tuple<JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); }
bones.Add(new Tuple<JointType, JointType>(JointType.WristRight, JointType.HandRight));
bones.Add(new Tuple<JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); if (kinectSensor != null)
bones.Add(new Tuple<JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); {
kinectSensor.Close();
// Bras gauche kinectSensor = null;
bones.Add(new Tuple<JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); }
bones.Add(new Tuple<JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); }
bones.Add(new Tuple<JointType, JointType>(JointType.WristLeft, JointType.HandLeft));
bones.Add(new Tuple<JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft));
bones.Add(new Tuple<JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft));
// Jambe droite
bones.Add(new Tuple<JointType, JointType>(JointType.HipRight, JointType.KneeRight));
bones.Add(new Tuple<JointType, JointType>(JointType.KneeRight, JointType.AnkleRight));
bones.Add(new Tuple<JointType, JointType>(JointType.AnkleRight, JointType.FootRight));
// Jambe gauche
bones.Add(new Tuple<JointType, JointType>(JointType.HipLeft, JointType.KneeLeft));
bones.Add(new Tuple<JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft));
bones.Add(new Tuple<JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft));
private static void BodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
Body[] bodies = new Body[bodyFrame.BodyCount];
bodyFrame.GetAndRefreshBodyData(bodies);
foreach (Body body in bodies)
{
if (body.IsTracked)
{
postureHandUpRight.TestGesture(body);
}
}
}
}
}
private static void PostureHandUpRight_GestureRecognized(object sender, GestureRecognizedEventArgs e)
{
Console.WriteLine("Posture Hand Up Right reconnue !");
} }
} }
} }

Loading…
Cancel
Save