WantToFix(dev): push some crap

pull/17/head
Johan LACHENAL 1 year ago
parent ee37033549
commit c76b1a3f7c

@ -14,40 +14,40 @@ namespace ConsoleApp
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
KinectManager kinectManager = new KinectManager(); // KinectManager kinectManager = new KinectManager();
if (!kinectManager.StartSensor()) // if (kinectManager.StartSensor())
{ // {
Console.WriteLine("Kinect n'est pas connecté ou non reconnu."); // Console.WriteLine("Kinect n'est pas connecté ou non reconnu.");
return; // return;
} // }
// Créez les instances de vos postures // // Créez les instances de vos postures
PostureHandUp handUpPosture = new PostureHandUp(); // PostureHandUp handUpPosture = new PostureHandUp();
PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead(); // PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead();
// Abonnez-vous aux événements de reconnaissance de posture // // Abonnez-vous aux événements de reconnaissance de posture
handUpPosture.GestureRecognized += (sender, e) => // handUpPosture.GestureRecognized += (sender, e) =>
{ // {
Console.WriteLine("Posture Hand Up reconnue !"); // Console.WriteLine("Posture Hand Up reconnue !");
}; // };
handsOnHeadPosture.GestureRecognized += (sender, e) => // handsOnHeadPosture.GestureRecognized += (sender, e) =>
{ // {
Console.WriteLine("Posture Hands On Head reconnue !"); // Console.WriteLine("Posture Hands On Head reconnue !");
}; // };
// Boucle pour tester les postures // // Boucle pour tester les postures
while (true) // while (true)
{ // {
Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps // Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps
if (body != null) // if (body != null)
{ // {
handUpPosture.TestGesture(body); // handUpPosture.TestGesture(body);
handsOnHeadPosture.TestGesture(body); // handsOnHeadPosture.TestGesture(body);
} // }
Thread.Sleep(50); // Une petite pause pour ne pas surcharger le CPU // Thread.Sleep(50); // Une petite pause pour ne pas surcharger le CPU
} // }
} }
} }

@ -1,97 +1,175 @@
//using Microsoft.Kinect; using Microsoft.Kinect;
//using System; using System;
//using System.Collections.Generic; using System.Collections.Generic;
//using System.Linq; using System.Linq;
//using System.Text; using System.Text;
//using System.Threading.Tasks; using System.Threading.Tasks;
//using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
//using System.Windows.Media; using System.Windows.Media;
//using System.Windows; using System.Windows;
//using System.Windows.Shapes; using System.Windows.Shapes;
using Lib;
//namespace Lib using System.Windows.Controls;
//{
// class ColorAndBodyImageStream : KinectStream namespace Lib
// { {
// private BodyFrameReader reader; public class ColorAndBodyImageStream : KinectStream
// public BodyFrameReader Reader {
// { private BodyFrameReader reader;
// get { return reader; } public BodyFrameReader Reader
// set { reader = value; } {
// } get { return reader; }
set { reader = value; }
// private Body[] bodies; }
// public Body[] Bodies
// { private Body[] bodies;
// get { return bodies; } public Body[] Bodies
// private set { bodies = value; } {
// } get { return bodies; }
// public ColorAndBodyImageStream(KinectManager kinectManager) : base(kinectManager) private set { bodies = value; }
// { }
// var frameDescription = KinectManager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); public override void Stop()
// this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); {
// reader = KinectManager.Sensor.BodyFrameSource.OpenReader(); if (reader != null)
// reader.FrameArrived += Reader_BodyFrameArrived; {
// // Initialiser le tableau des corps reader.Dispose();
// this.bodies = new Body[KinectManager.Sensor.BodyFrameSource.BodyCount]; reader = null;
// } }
}
// private void DrawSkeleton(Body body) private Canvas skeletonCanvas;
// { public Canvas SkeletonCanvas {
// foreach (JointType jointType in body.Joints.Keys) get { return skeletonCanvas; }
// { private set { skeletonCanvas = value; }
// Joint joint = body.Joints[jointType]; }
// if (joint.TrackingState == TrackingState.Tracked)
// { public ColorAndBodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
// // Convertir les coordonnées du joint en coordonnées de l'écran {
// Point point = new Point(); var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
// ColorSpacePoint colorPoint = KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position); Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
// point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X; reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
// point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y; reader.FrameArrived += Reader_BodyFrameArrived;
// initialiser le tableau des corps
// // Dessiner le joint this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
// DrawJoint(point); SkeletonCanvas = skeletonCanvas;
// } }
// }
private void drawbone(Body body, JointType JointType0, JointType JointType1)
// // Dessinez les os ici si nécessaire {
// } Joint joint0 = body.Joints[JointType0];
Joint joint1 = body.Joints[JointType1];
// private void DrawJoint(Point point)
// { // ne dessinez que si les deux joints sont suivis
// Ellipse ellipse = new Ellipse if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
// { {
// Width = 10, Line bone = new Line
// Height = 10, {
// Fill = new SolidColorBrush(Colors.Red) Stroke = new SolidColorBrush(Colors.LightBlue),
// }; StrokeThickness = 4,
X1 = MapJointToScreen(joint0).X,
// Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2); Y1 = MapJointToScreen(joint0).Y,
// Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2); X2 = MapJointToScreen(joint1).X,
Y2 = MapJointToScreen(joint1).Y
// skeletonCanvas.Children.Add(ellipse); };
// }
// private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) skeletonCanvas.Children.Add(bone);
// { }
// using (var bodyFrame = e.FrameReference.AcquireFrame()) }
// {
// if (bodyFrame != null) private Point MapJointToScreen(Joint joint)
// { {
// bodyFrame.GetAndRefreshBodyData(this.bodies); ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
// skeletonCanvas.Children.Clear(); // Nettoyer le canvas avant de dessiner // Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
// foreach (var body in this.bodies) float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
// {
// if (body.IsTracked) return new Point(x, y);
// { }
// // Dessiner le squelette
// DrawSkeleton(body); private void drawskeleton(Body body)
// } {
// } // tête et cou
// } drawbone(body, JointType.Head, JointType.Neck);
// } drawbone(body, JointType.Neck, JointType.SpineShoulder);
// }
// } // torse
//} drawbone(body, JointType.SpineShoulder, JointType.SpineMid);
drawbone(body, JointType.SpineMid, JointType.SpineBase);
drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight);
drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft);
drawbone(body, JointType.SpineBase, JointType.HipRight);
drawbone(body, JointType.SpineBase, JointType.HipLeft);
// bras droit
drawbone(body, JointType.ShoulderRight, JointType.ElbowRight);
drawbone(body, JointType.ElbowRight, JointType.WristRight);
drawbone(body, JointType.WristRight, JointType.HandRight);
drawbone(body, JointType.HandRight, JointType.HandTipRight);
drawbone(body, JointType.WristRight, JointType.ThumbRight);
// bras gauche
drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft);
drawbone(body, JointType.ElbowLeft, JointType.WristLeft);
drawbone(body, JointType.WristLeft, JointType.HandLeft);
drawbone(body, JointType.HandLeft, JointType.HandTipLeft);
drawbone(body, JointType.WristLeft, JointType.ThumbLeft);
// jambe droite
drawbone(body, JointType.HipRight, JointType.KneeRight);
drawbone(body, JointType.KneeRight, JointType.AnkleRight);
drawbone(body, JointType.AnkleRight, JointType.FootRight);
// jambe gauche
drawbone(body, JointType.HipLeft, JointType.KneeLeft);
drawbone(body, JointType.KneeLeft, JointType.AnkleLeft);
drawbone(body, JointType.AnkleLeft, JointType.FootLeft);
// dessinez les joints
foreach (JointType JointType in body.Joints.Keys)
{
Joint joint = body.Joints[JointType];
if (joint.TrackingState == TrackingState.Tracked)
{
DrawJoint(MapJointToScreen(joint));
}
}
}
private void DrawJoint(Point point)
{
Ellipse ellipse = new Ellipse
{
Width = 10,
Height = 10,
Fill = new SolidColorBrush(Colors.Red)
};
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
skeletonCanvas.Children.Add(ellipse);
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyframe = e.FrameReference.AcquireFrame())
{
if (bodyframe != null)
{
bodyframe.GetAndRefreshBodyData(this.bodies);
SkeletonCanvas.Children.Clear(); // nettoyer le Canvas avant de dessiner
foreach (var body in this.bodies)
{
if (body.IsTracked)
{
// dessiner le squelette
drawskeleton(body);
}
}
}
}
}
}
}

@ -11,6 +11,7 @@ namespace Lib
None, None,
Color, Color,
Depth, Depth,
IR IR,
ColorAndBody
} }
} }

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls;
namespace Lib namespace Lib
{ {
@ -14,32 +15,33 @@ namespace Lib
private set { _kinectManager = value; } private set { _kinectManager = value; }
} }
private Dictionary<KinectStreams, Func<KinectStream>> _streamFactory; private Dictionary<KinectStreams, Func<Canvas,KinectStream>> _streamFactory;
public Dictionary<KinectStreams, Func<KinectStream>> StreamFactory public Dictionary<KinectStreams, Func<Canvas,KinectStream>> StreamFactory
{ {
get { return _streamFactory; } get { return _streamFactory; }
private set { _streamFactory = value; } private set { _streamFactory = value; }
} }
public KinectStreamsFactory(KinectManager kinect) public KinectStreamsFactory(KinectManager kinect, Canvas skeletonCanvas = null)
{ {
_kinectManager = kinect; _kinectManager = kinect;
// Initialisation de la fabrique avec les fonctions de création pour chaque type de flux. // Initialisation de la fabrique avec les fonctions de création pour chaque type de flux.
StreamFactory = new Dictionary<KinectStreams, Func<KinectStream>> StreamFactory = new Dictionary<KinectStreams, Func<Canvas,KinectStream>>
{ {
{ KinectStreams.Color, () => new ColorImageStream(KinectManager) }, { KinectStreams.Color, (canvas) => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, () => new DepthImageStream(KinectManager) }, { KinectStreams.Depth, (canvas) => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) } { KinectStreams.IR, (canvas) => new InfraredImageStream(KinectManager) },
{ KinectStreams.ColorAndBody, (canvas) => new ColorAndBodyImageStream(KinectManager,skeletonCanvas) }
}; };
} }
public KinectStream this[KinectStreams stream] public KinectStream this[KinectStreams stream, Canvas skeletonCanvas = null]
{ {
get get
{ {
if (StreamFactory.ContainsKey(stream)) if (StreamFactory.ContainsKey(stream))
{ {
return StreamFactory[stream](); return StreamFactory[stream](skeletonCanvas);
} }
else else
{ {

@ -35,6 +35,7 @@
<HintPath>..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll</HintPath> <HintPath>..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System;
using Microsoft.Kinect; using Microsoft.Kinect;
namespace LibMyGesturesBank namespace LibMyGesturesBank

@ -22,16 +22,12 @@
<Button Content="Filtre 1" Margin="5" Click="ToColorImageStream"/> <Button Content="Filtre 1" Margin="5" Click="ToColorImageStream"/>
<Button Content="Filtre 2" Margin="5" Click="ToDepthImageStream"/> <Button Content="Filtre 2" Margin="5" Click="ToDepthImageStream"/>
<Button Content="Filtre 3" Margin="5" Click="ToInfraredImageStream"/> <Button Content="Filtre 3" Margin="5" Click="ToInfraredImageStream"/>
<Button Content="Filtre 4" Margin="5"/> <Button Content="Filtre 4" Margin="5" Click="ToColorAndBodyImageStream"/>
<Button Content="Filtre 5" Margin="5"/> <Button Content="Filtre 5" Margin="5"/>
</StackPanel> </StackPanel>
<Viewbox Grid.Row="2" Stretch="Uniform"> <Image Grid.Row="2" Source="{Binding CurrentKinectStream.Bitmap}" />
<Grid> <Canvas Grid.Row="2" x:Name="skeletonCanvas" />
<Image Source="{Binding CurrentKinectStream.Bitmap}" />
<Canvas x:Name="skeletonCanvas" />
</Grid>
</Viewbox>
</Grid> </Grid>
</Window> </Window>

@ -96,5 +96,13 @@ namespace WpfApp
Debug.WriteLine(CurrentKinectStream.GetType().Name); Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start(); CurrentKinectStream.Start();
} }
private void ToColorAndBodyImageStream(object sender, RoutedEventArgs e)
{
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.ColorAndBody,skeletonCanvas];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
} }
} }

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Lib;
namespace WpfApp
{
class StreamTemplateSelector : DataTemplateSelector
{
public DataTemplate ColorAndBodyImageStreamTemplate { get; set; }
public DataTemplate OtherStreamTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is ColorAndBodyImageStream) return ColorAndBodyImageStreamTemplate;
else return OtherStreamTemplate;
}
}
}

@ -58,6 +58,7 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="StreamTemplateSelector.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>

Loading…
Cancel
Save