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)
{
KinectManager kinectManager = new KinectManager();
if (!kinectManager.StartSensor())
{
Console.WriteLine("Kinect n'est pas connecté ou non reconnu.");
return;
}
// KinectManager kinectManager = new KinectManager();
// if (kinectManager.StartSensor())
// {
// Console.WriteLine("Kinect n'est pas connecté ou non reconnu.");
// return;
// }
// Créez les instances de vos postures
PostureHandUp handUpPosture = new PostureHandUp();
PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead();
// // Créez les instances de vos postures
// PostureHandUp handUpPosture = new PostureHandUp();
// PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead();
// Abonnez-vous aux événements de reconnaissance de posture
handUpPosture.GestureRecognized += (sender, e) =>
{
Console.WriteLine("Posture Hand Up reconnue !");
};
// // Abonnez-vous aux événements de reconnaissance de posture
// handUpPosture.GestureRecognized += (sender, e) =>
// {
// Console.WriteLine("Posture Hand Up reconnue !");
// };
handsOnHeadPosture.GestureRecognized += (sender, e) =>
{
Console.WriteLine("Posture Hands On Head reconnue !");
};
// handsOnHeadPosture.GestureRecognized += (sender, e) =>
// {
// Console.WriteLine("Posture Hands On Head reconnue !");
// };
// Boucle pour tester les postures
while (true)
{
Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps
if (body != null)
{
handUpPosture.TestGesture(body);
handsOnHeadPosture.TestGesture(body);
}
// // Boucle pour tester les postures
// while (true)
// {
// Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps
// if (body != null)
// {
// handUpPosture.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 System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using System.Windows.Media.Imaging;
//using System.Windows.Media;
//using System.Windows;
//using System.Windows.Shapes;
//namespace Lib
//{
// class ColorAndBodyImageStream : KinectStream
// {
// private BodyFrameReader reader;
// public BodyFrameReader Reader
// {
// get { return reader; }
// set { reader = value; }
// }
// private Body[] bodies;
// public Body[] Bodies
// {
// get { return bodies; }
// private set { bodies = value; }
// }
// public ColorAndBodyImageStream(KinectManager kinectManager) : base(kinectManager)
// {
// var frameDescription = KinectManager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
// this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
// reader = KinectManager.Sensor.BodyFrameSource.OpenReader();
// reader.FrameArrived += Reader_BodyFrameArrived;
// // Initialiser le tableau des corps
// this.bodies = new Body[KinectManager.Sensor.BodyFrameSource.BodyCount];
// }
// private void DrawSkeleton(Body body)
// {
// foreach (JointType jointType in body.Joints.Keys)
// {
// Joint joint = body.Joints[jointType];
// if (joint.TrackingState == TrackingState.Tracked)
// {
// // Convertir les coordonnées du joint en coordonnées de l'écran
// Point point = new Point();
// ColorSpacePoint colorPoint = KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
// point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
// point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
// // Dessiner le joint
// DrawJoint(point);
// }
// }
// // Dessinez les os ici si nécessaire
// }
// 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);
// }
// }
// }
// }
// }
// }
//}
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows;
using System.Windows.Shapes;
using Lib;
using System.Windows.Controls;
namespace Lib
{
public class ColorAndBodyImageStream : KinectStream
{
private BodyFrameReader reader;
public BodyFrameReader Reader
{
get { return reader; }
set { reader = value; }
}
private Body[] bodies;
public Body[] Bodies
{
get { return bodies; }
private set { bodies = value; }
}
public override void Stop()
{
if (reader != null)
{
reader.Dispose();
reader = null;
}
}
private Canvas skeletonCanvas;
public Canvas SkeletonCanvas {
get { return skeletonCanvas; }
private set { skeletonCanvas = value; }
}
public ColorAndBodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
{
var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived;
// initialiser le tableau des corps
this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
SkeletonCanvas = skeletonCanvas;
}
private void drawbone(Body body, JointType JointType0, JointType JointType1)
{
Joint joint0 = body.Joints[JointType0];
Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis
if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
{
Line bone = new Line
{
Stroke = new SolidColorBrush(Colors.LightBlue),
StrokeThickness = 4,
X1 = MapJointToScreen(joint0).X,
Y1 = MapJointToScreen(joint0).Y,
X2 = MapJointToScreen(joint1).X,
Y2 = MapJointToScreen(joint1).Y
};
skeletonCanvas.Children.Add(bone);
}
}
private Point MapJointToScreen(Joint joint)
{
ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
// Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
return new Point(x, y);
}
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,
Color,
Depth,
IR
IR,
ColorAndBody
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace Lib
{
@ -14,32 +15,33 @@ namespace Lib
private set { _kinectManager = value; }
}
private Dictionary<KinectStreams, Func<KinectStream>> _streamFactory;
public Dictionary<KinectStreams, Func<KinectStream>> StreamFactory
private Dictionary<KinectStreams, Func<Canvas,KinectStream>> _streamFactory;
public Dictionary<KinectStreams, Func<Canvas,KinectStream>> StreamFactory
{
get { return _streamFactory; }
private set { _streamFactory = value; }
}
public KinectStreamsFactory(KinectManager kinect)
public KinectStreamsFactory(KinectManager kinect, Canvas skeletonCanvas = null)
{
_kinectManager = kinect;
// 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.Depth, () => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) }
{ KinectStreams.Color, (canvas) => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, (canvas) => new DepthImageStream(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
{
if (StreamFactory.ContainsKey(stream))
{
return StreamFactory[stream]();
return StreamFactory[stream](skeletonCanvas);
}
else
{

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

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

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

@ -96,5 +96,13 @@ namespace WpfApp
Debug.WriteLine(CurrentKinectStream.GetType().Name);
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>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="StreamTemplateSelector.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

Loading…
Cancel
Save