ADD : Test Console Posture HandUpRight working in console

exo2
lobroda 10 months ago
parent 02c35bda79
commit 3d22413fd5

@ -132,6 +132,10 @@
<Project>{e527438a-dfa2-4ec6-9891-d4956152b093}</Project>
<Name>KinectConnection</Name>
</ProjectReference>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2bc300e4-d3c1-4e17-a011-380edb793182}</Project>
<Name>KinectUtils</Name>
</ProjectReference>
</ItemGroup>
<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')" />

@ -33,9 +33,9 @@
<Ellipse Width="30"
Height="30"
Fill="{Binding KinectManager.Status, Converter={StaticResource KinectStatusToColorConverter}}"
Fill="{Binding GestureManager.KinectManager.Status, Converter={StaticResource KinectStatusToColorConverter}}"
Grid.Column="1"/>
<TextBlock Text="{Binding KinectManager.StatusText}"
<TextBlock Text="{Binding GestureManager.KinectManager.StatusText}"
VerticalAlignment="Center"
FontWeight="Bold"
Grid.Column="3"/>
@ -56,43 +56,10 @@
<ColumnDefinition Width="*"/>
</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"
Width="100"
Height="30"
Grid.Column="7"
Grid.Column="5"
Command="{Binding BodyCommand}">
<Button.Resources>
<Style TargetType="Border">
@ -100,17 +67,6 @@
</Style>
</Button.Resources>
</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.Row="4">
@ -118,15 +74,9 @@
HorizontalAlignment="Center"
Height="400"
Width="400">
<Image Source="{Binding KinectStream.Source}"
<Image Source="{Binding BodyImageStream.Source}"
Opacity="50"/>
</Viewbox>
<Viewbox Grid.Row="1"
HorizontalAlignment="Center"
Height="400"
Width="400">
<Image Source="{Binding KinectStream2.Source}"/>
</Viewbox>
</Grid>
</Grid>
</Window>

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

@ -259,10 +259,6 @@ namespace KinectConnection
// dessiner les joints
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>
/// Méthode appelée pour le dessin d'un os
/// </summary>

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

@ -1,4 +1,5 @@
using Microsoft.Kinect;
using KinectUtils;
using Microsoft.Kinect;
using MyGestureBank;
using System;
using System.Collections.Generic;
@ -11,51 +12,63 @@ namespace PostureTester
{
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)
{
// Create a body
Body[] body = new Body[1];
// Create a posture
PostureHandUpRight postureHandUpRight = new PostureHandUpRight();
PostureHandUpLeft postureHandUpLeft = new PostureHandUpLeft();
// Make the body do the posture
bones.Add(new Tuple<JointType, JointType>(JointType.Head, JointType.Neck));
bones.Add(new Tuple<JointType, JointType>(JointType.Neck, JointType.SpineShoulder));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineMid, JointType.SpineBase));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineBase, JointType.HipRight));
bones.Add(new Tuple<JointType, JointType>(JointType.SpineBase, JointType.HipLeft));
// 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));
bones.Add(new Tuple<JointType, JointType>(JointType.WristRight, JointType.ThumbRight));
// Bras gauche
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));
kinectSensor = KinectSensor.GetDefault();
postureHandUpRight.GestureRecognized += PostureHandUpRight_GestureRecognized;
if (kinectSensor != null)
{
kinectSensor.Open();
// Utilisation du bloc using pour bodyFrameReader
using (var bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader())
{
if (bodyFrameReader != null)
{
// Abonnement à l'événement FrameArrived
bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
Console.WriteLine("Lecture des données du corps en cours... Appuyez sur une touche pour quitter.");
Console.ReadKey();
}
}
}
if (kinectSensor != null)
{
kinectSensor.Close();
kinectSensor = null;
}
}
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