Format(Gesture): en rend conforme le code au convention de CSharpier

pull/21/head
Louis DUFOUR 1 year ago
parent 7a0e038241
commit 94405148f6

@ -32,5 +32,4 @@ namespace KinectUtils
GestureName = gestureName;
}
}
}

@ -13,21 +13,25 @@ namespace KinectUtils
{
throw new NotImplementedException();
}
public void SubscribeToEndGesture(BaseGesture gesture)
{
throw new NotImplementedException();
}
public void SubscribeToToggleGesture(BaseGesture gesture)
{
throw new NotImplementedException();
}
protected T Mapping(Body body)
{
throw new NotImplementedException();
}
public bool TestMapping(Body body, out T output)
{
throw new NotImplementedException();
public bool TestMapping(Body body, out T output)
{
throw new NotImplementedException();
}
}
}

@ -10,7 +10,7 @@ namespace KinectUtils
public abstract class Gesture : BaseGesture
{
public bool IsRecognitionRunning { get; set; } = false;
protected int MinNbOfFrames = 10; // Exemple de valeur, ajustez selon le geste
protected int MaxNbOfFrames = 50; // Exemple de valeur, ajustez selon le geste
private int currentFrameCount = 0;
@ -29,7 +29,11 @@ namespace KinectUtils
{
currentFrameCount++;
if (!TestPosture(body) || !TestRunningGesture(body) || currentFrameCount > MaxNbOfFrames)
if (
!TestPosture(body)
|| !TestRunningGesture(body)
|| currentFrameCount > MaxNbOfFrames
)
{
IsRecognitionRunning = false;
}
@ -42,10 +46,9 @@ namespace KinectUtils
}
}
abstract protected bool TestInitialConditions(Body body);
abstract protected bool TestPosture(Body body);
abstract protected bool TestRunningGesture(Body body);
abstract protected bool TestEndConditions(Body body);
protected abstract bool TestInitialConditions(Body body);
protected abstract bool TestPosture(Body body);
protected abstract bool TestRunningGesture(Body body);
protected abstract bool TestEndConditions(Body body);
}
}

@ -12,8 +12,8 @@ namespace KinectUtils
{
public static class GestureManager
{
static private BodyFrameReader bodyFrameReader;
static private Body[] bodies;
private static BodyFrameReader bodyFrameReader;
private static Body[] bodies;
static event EventHandler GestureRecognized;
static KinectManager KinectManager { get; set; }
static List<BaseGesture> KnownGestures { get; set; } = new List<BaseGesture>();
@ -26,6 +26,7 @@ namespace KinectUtils
AddGesture(gesture);
}
}
public static void AddGesture(BaseGesture gesture)
{
if (!KnownGestures.Contains(gesture))
@ -34,6 +35,7 @@ namespace KinectUtils
gesture.GestureRecognized += (sender, e) => GestureRecognized?.Invoke(sender, e);
}
}
public static void RemoveGesture(BaseGesture gesture)
{
if (KnownGestures.Contains(gesture))
@ -43,34 +45,32 @@ namespace KinectUtils
}
}
static public void StartAcquiringFrames(KinectManager kinectManager)
public static void StartAcquiringFrames(KinectManager kinectManager)
{
bodyFrameReader = kinectManager.Sensor.BodyFrameSource.OpenReader();
bodyFrameReader.FrameArrived += Reader_BodyFrameArrived;
}
static private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
private static void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyframe = e.FrameReference.AcquireFrame())
{
if (bodyframe != null)
{
if(bodies == null)
if (bodies == null)
{
bodies = new Body[bodyframe.BodyCount];
}
bodyframe.GetAndRefreshBodyData(bodies);
if (bodies != null)
if (bodies != null)
{
foreach (var body in bodies)
{
foreach (var body in bodies)
if (body.IsTracked)
{
if (body.IsTracked)
foreach (var gesture in KnownGestures)
{
foreach (var gesture in KnownGestures)
{
gesture.TestGesture(body);
}
gesture.TestGesture(body);
}
}
}
@ -79,3 +79,4 @@ namespace KinectUtils
}
}
}
}

@ -8,6 +8,6 @@ namespace KinectUtils
{
public interface IGestureFactory
{
IEnumerable<BaseGesture> CreateGestures();
IEnumerable<BaseGesture> CreateGestures();
}
}

@ -28,6 +28,7 @@ namespace Lib
get { return bodies; }
private set { bodies = value; }
}
public override void Stop()
{
if (Reader != null)
@ -35,13 +36,22 @@ namespace Lib
Reader.Dispose();
Reader = null;
}
}
public BodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
public BodyImageStream(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);
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;
@ -56,7 +66,10 @@ namespace Lib
Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis
if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
if (
joint0.TrackingState == TrackingState.Tracked
&& joint1.TrackingState == TrackingState.Tracked
)
{
Line bone = new Line
{
@ -74,7 +87,10 @@ namespace Lib
private Point MapJointToScreen(Joint joint)
{
ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
ColorSpacePoint colorPoint =
this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(
joint.Position
);
// Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
@ -84,86 +100,86 @@ namespace Lib
}
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)
{
// 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)
{
Joint joint = body.Joints[JointType];
if (joint.TrackingState == TrackingState.Tracked)
{
DrawJoint(MapJointToScreen(joint));
}
DrawJoint(MapJointToScreen(joint));
}
}
}
private void DrawJoint(Point point)
private void DrawJoint(Point point)
{
Ellipse ellipse = new Ellipse
{
Ellipse ellipse = new Ellipse
{
Width = 10,
Height = 10,
Fill = new SolidColorBrush(Colors.Red)
};
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);
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
Canvas.Children.Add(ellipse);
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
Canvas.Children.Add(ellipse);
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyframe = e.FrameReference.AcquireFrame())
{
using (var bodyframe = e.FrameReference.AcquireFrame())
if (bodyframe != null)
{
if (bodyframe != null)
{
bodyframe.GetAndRefreshBodyData(this.bodies);
bodyframe.GetAndRefreshBodyData(this.bodies);
// nettoyer le Canvas avant de dessiner
if (Canvas != null)
if (Canvas != null)
{
Canvas.Children.Clear();
foreach (var body in this.bodies)
{
Canvas.Children.Clear();
foreach (var body in this.bodies)
if (body.IsTracked)
{
if (body.IsTracked)
{
// dessiner le squelette
drawskeleton(body);
}
// dessiner le squelette
drawskeleton(body);
}
}
}
@ -171,4 +187,4 @@ namespace Lib
}
}
}
}

@ -22,7 +22,8 @@ namespace Lib
}
private ColorFrameReader _colorReader;
public ColorFrameReader ColorReader {
public ColorFrameReader ColorReader
{
get { return _colorReader; }
private set { _colorReader = value; }
}
@ -33,6 +34,7 @@ namespace Lib
get { return bodies; }
private set { bodies = value; }
}
public override void Stop()
{
if (Reader != null)
@ -40,18 +42,27 @@ namespace Lib
Reader.Dispose();
Reader = null;
}
if(ColorReader != null)
if (ColorReader != null)
{
ColorReader.Dispose();
ColorReader = null;
}
}
public ColorAndBodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
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);
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;
ColorReader = KinectManager.Sensor.ColorFrameSource.OpenReader();
@ -67,7 +78,10 @@ namespace Lib
Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis
if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
if (
joint0.TrackingState == TrackingState.Tracked
&& joint1.TrackingState == TrackingState.Tracked
)
{
Line bone = new Line
{
@ -85,7 +99,10 @@ namespace Lib
private Point MapJointToScreen(Joint joint)
{
ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
ColorSpacePoint colorPoint =
this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(
joint.Position
);
// Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
@ -157,6 +174,7 @@ namespace Lib
Canvas.Children.Add(ellipse);
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyframe = e.FrameReference.AcquireFrame())
@ -178,6 +196,7 @@ namespace Lib
}
}
}
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
@ -193,14 +212,22 @@ namespace Lib
this.Bitmap.Lock();
// Vérifier si la taille de l'image a changé
if ((colorFrameDescription.Width == this.Bitmap.PixelWidth) && (colorFrameDescription.Height == this.Bitmap.PixelHeight))
if (
(colorFrameDescription.Width == this.Bitmap.PixelWidth)
&& (colorFrameDescription.Height == this.Bitmap.PixelHeight)
)
{
colorFrame.CopyConvertedFrameDataToIntPtr(
this.Bitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
ColorImageFormat.Bgra);
this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight));
(uint)(
colorFrameDescription.Width * colorFrameDescription.Height * 4
),
ColorImageFormat.Bgra
);
this.Bitmap.AddDirtyRect(
new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)
);
}
this.Bitmap.Unlock();

@ -9,19 +9,26 @@ namespace Lib
public class ColorImageStream : KinectStream
{
private ColorFrameReader reader;
public ColorFrameReader Reader {
get {
return reader;
}
set
{
reader = value;
}
public ColorFrameReader Reader
{
get { return reader; }
set { reader = value; }
}
public ColorImageStream(KinectManager kinectManager) : base(kinectManager)
public ColorImageStream(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);
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.ColorFrameSource.OpenReader();
reader.FrameArrived += Reader_ColorFrameArrived;
}
@ -50,14 +57,22 @@ namespace Lib
this.Bitmap.Lock();
// Vérifier si la taille de l'image a changé
if ((colorFrameDescription.Width == this.Bitmap.PixelWidth) && (colorFrameDescription.Height == this.Bitmap.PixelHeight))
if (
(colorFrameDescription.Width == this.Bitmap.PixelWidth)
&& (colorFrameDescription.Height == this.Bitmap.PixelHeight)
)
{
colorFrame.CopyConvertedFrameDataToIntPtr(
this.Bitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
ColorImageFormat.Bgra);
(uint)(
colorFrameDescription.Width * colorFrameDescription.Height * 4
),
ColorImageFormat.Bgra
);
this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight));
this.Bitmap.AddDirtyRect(
new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)
);
}
this.Bitmap.Unlock();

@ -15,33 +15,33 @@ namespace Lib
private DepthFrameReader reader;
public DepthFrameReader Reader
{
get
{
return reader;
}
set
{
reader = value;
}
get { return reader; }
set { reader = value; }
}
private byte[] depthPixels;
public byte[] DepthPixels {
get {
return depthPixels;
}
set
{
depthPixels = value;
}
public byte[] DepthPixels
{
get { return depthPixels; }
set { depthPixels = value; }
}
public DepthImageStream(KinectManager kinectManager) : base(kinectManager)
public DepthImageStream(KinectManager kinectManager)
: base(kinectManager)
{
var frameDescription = KinectManager.Sensor.DepthFrameSource.FrameDescription;
this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
this.Bitmap = new WriteableBitmap(
frameDescription.Width,
frameDescription.Height,
96.0,
96.0,
PixelFormats.Gray8,
null
);
reader = KinectManager.Sensor.DepthFrameSource.OpenReader();
reader.FrameArrived += Reader_DepthFrameArrived;
DepthPixels = new byte[frameDescription.Width * frameDescription.Height];
}
private void Reader_DepthFrameArrived(object sender, DepthFrameArrivedEventArgs e)
{
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
@ -55,14 +55,25 @@ namespace Lib
depthFrame.CopyFrameDataToArray(depthData);
// Traitez les données de profondeur
ProcessDepthFrameData(depthData, depthFrameDescription.LengthInPixels, depthFrame.DepthMinReliableDistance, depthFrame.DepthMaxReliableDistance);
ProcessDepthFrameData(
depthData,
depthFrameDescription.LengthInPixels,
depthFrame.DepthMinReliableDistance,
depthFrame.DepthMaxReliableDistance
);
// Mettez à jour le bitmap de profondeur
this.Bitmap.WritePixels(
new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height),
new Int32Rect(
0,
0,
depthFrameDescription.Width,
depthFrameDescription.Height
),
this.depthPixels,
depthFrameDescription.Width,
0);
0
);
}
}
}
@ -76,7 +87,12 @@ namespace Lib
}
}
private void ProcessDepthFrameData(ushort[] depthData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
private void ProcessDepthFrameData(
ushort[] depthData,
uint depthFrameDataSize,
ushort minDepth,
ushort maxDepth
)
{
// Convertir les données de profondeur en niveaux de gris
for (int i = 0; i < depthFrameDataSize; ++i)
@ -85,6 +101,5 @@ namespace Lib
DepthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth % 256) : 0);
}
}
}
}

@ -16,30 +16,27 @@ namespace Lib
private byte[] infraredPixels;
public byte[] InfraredPixels
{
get
{
return infraredPixels;
}
private set
{
infraredPixels = value;
}
get { return infraredPixels; }
private set { infraredPixels = value; }
}
public InfraredFrameReader Reader
{
get
{
return reader;
}
private set
{
reader = value;
}
get { return reader; }
private set { reader = value; }
}
public InfraredImageStream(KinectManager kinectManager) : base(kinectManager)
public InfraredImageStream(KinectManager kinectManager)
: base(kinectManager)
{
var frameDescription = KinectManager.Sensor.InfraredFrameSource.FrameDescription;
this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
this.Bitmap = new WriteableBitmap(
frameDescription.Width,
frameDescription.Height,
96.0,
96.0,
PixelFormats.Gray8,
null
);
reader = KinectManager.Sensor.InfraredFrameSource.OpenReader();
reader.FrameArrived += Reader_InfraredFrameArrived;
infraredPixels = new byte[frameDescription.Width * frameDescription.Height];
@ -53,6 +50,7 @@ namespace Lib
reader = null;
}
}
private void ProcessInfraredFrameData(ushort[] frameData, uint frameDataSize)
{
// Convertir les données infrarouges en niveaux de gris
@ -81,10 +79,16 @@ namespace Lib
// Mettez à jour le bitmap infrarouge
this.Bitmap.WritePixels(
new Int32Rect(0, 0, infraredFrameDescription.Width, infraredFrameDescription.Height),
new Int32Rect(
0,
0,
infraredFrameDescription.Width,
infraredFrameDescription.Height
),
this.infraredPixels,
infraredFrameDescription.Width,
0);
0
);
}
}
}

@ -8,10 +8,9 @@ namespace Lib
public class KinectManager : INotifyPropertyChanged
{
private KinectSensor sensor;
public KinectSensor Sensor {
get {
return sensor;
}
public KinectSensor Sensor
{
get { return sensor; }
set
{
sensor = value;
@ -31,6 +30,7 @@ namespace Lib
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
@ -46,16 +46,20 @@ namespace Lib
sensor.IsAvailableChanged += KinectSensor_IsAvailableChanged;
}
}
public void StartSensor()
{
if (sensor != null && !sensor.IsOpen) {
if (sensor != null && !sensor.IsOpen)
{
sensor.Open();
}
else {
else
{
sensor = KinectSensor.GetDefault();
sensor.Open();
}
}
public void StopSensor()
{
if (sensor != null)
@ -64,6 +68,7 @@ namespace Lib
sensor = null;
}
}
public bool Status
{
get { return Sensor != null && Sensor.IsAvailable; }
@ -72,9 +77,10 @@ namespace Lib
public string StatusText
{
get { return _statusText; }
set {
set
{
_statusText = value;
if(this.PropertyChanged != null)
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("StatusText"));
}
@ -110,4 +116,4 @@ namespace Lib
}
}
}
}
}

@ -39,6 +39,7 @@ namespace Lib
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
@ -60,6 +61,5 @@ namespace Lib
}
public abstract void Stop();
}
}

@ -10,7 +10,8 @@ namespace Lib
public class KinectStreamsFactory
{
private KinectManager _kinectManager;
public KinectManager KinectManager {
public KinectManager KinectManager
{
get { return _kinectManager; }
private set { _kinectManager = value; }
}
@ -22,18 +23,21 @@ namespace Lib
private set { _streamFactory = value; }
}
public KinectStreamsFactory(KinectManager kinect,Canvas SkeletonCanvas)
public KinectStreamsFactory(KinectManager kinect, Canvas SkeletonCanvas)
{
_kinectManager = kinect;
// Initialisation de la fabrique avec les fonctions de création pour chaque type de flux.
StreamFactory = new Dictionary<KinectStreams, Func<KinectStream>>
{
{ KinectStreams.Color, () => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, () => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) },
{ KinectStreams.Body, () => new BodyImageStream(KinectManager,SkeletonCanvas) },
{ KinectStreams.ColorAndBody, () => new ColorAndBodyImageStream(KinectManager,SkeletonCanvas) }
};
{
{ KinectStreams.Color, () => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, () => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) },
{ KinectStreams.Body, () => new BodyImageStream(KinectManager, SkeletonCanvas) },
{
KinectStreams.ColorAndBody,
() => new ColorAndBodyImageStream(KinectManager, SkeletonCanvas)
}
};
}
public KinectStream this[KinectStreams stream]
@ -51,4 +55,4 @@ namespace Lib
}
}
}
}
}

@ -23,7 +23,9 @@ namespace MyGesturesBank
var handLeft = body.Joints[JointType.HandLeft].Position;
// Vérifie si les mains sont à une hauteur similaire et devant le corps
return Math.Abs(handRight.Y - handLeft.Y) < 0.5f && handRight.Z < 0.5f && handLeft.Z < 0.5f;
return Math.Abs(handRight.Y - handLeft.Y) < 0.5f
&& handRight.Z < 0.5f
&& handLeft.Z < 0.5f;
}
protected override bool TestRunningGesture(Body body)
@ -40,7 +42,7 @@ namespace MyGesturesBank
// Le clap est un geste instantané, donc si les conditions sont remplies une fois, le geste est considéré comme terminé
return true;
}
public override string GestureName => "Clap Hands";
}
}

@ -13,8 +13,7 @@ namespace MyGesturesBank
return handRight.Y > head.Y || handLeft.Y > head.Y;
}
public override string GestureName => "Posture Hand Up";
}
}

@ -15,10 +15,10 @@ namespace MyGesturesBank
// Ajustez les seuils selon la précision souhaitée
var threshold = 0.1f; // Seuil pour ajuster la précision de la détection
return Math.Abs(handRight.Y - head.Y) < threshold && Math.Abs(handLeft.Y - head.Y) < threshold;
return Math.Abs(handRight.Y - head.Y) < threshold
&& Math.Abs(handLeft.Y - head.Y) < threshold;
}
public override string GestureName => "Posture Hands On Head";
}
}

@ -17,7 +17,7 @@ namespace MyGesturesBank
return handRight.Y > head.Y;
}
public override string GestureName => "Right Hand Up";
}
}

@ -10,7 +10,6 @@ namespace MyGesturesBank
{
public class SwipeRightHand : Gesture
{
private float previousX = float.NaN;
protected override bool TestInitialConditions(Body body)
@ -55,7 +54,7 @@ namespace MyGesturesBank
// Condition de fin : la main droite est bien à droite de la base de la colonne vertébrale
return handRight.X > spineBase.X + 0.5f; // Ajustez cette valeur selon le besoin
}
public override string GestureName => "Swipe Right Hand";
}
}

@ -18,7 +18,7 @@ namespace MyGesturesBank
return handRight.Y > head.Y && handLeft.Y > head.Y;
}
public override string GestureName => "Two Hands Dragon";
}
}

@ -11,7 +11,5 @@ namespace WpfApp
/// <summary>
/// Logique d'interaction pour App.xaml
/// </summary>
public partial class App : Application
{
}
public partial class App : Application { }
}

@ -11,9 +11,10 @@ namespace WpfApp
public class Bone : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propName)
{
if(PropertyChanged != null)
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
@ -23,23 +24,17 @@ namespace WpfApp
public double Top
{
get { return _top; }
set {
set
{
_top = value;
OnPropertyChanged(nameof(Top));
}
}
public double Left
{
get;
set;
}
public double Left { get; set; }
public double Diameter
{
get
{
return _diameter;
}
get { return _diameter; }
set
{
_diameter = value;
@ -47,9 +42,6 @@ namespace WpfApp
}
}
private double _diameter;
public SolidColorBrush ColorBrush {
get;
set;
}
public SolidColorBrush ColorBrush { get; set; }
}
}

@ -9,9 +9,9 @@ namespace WpfApp
{
class Bones : Collection<Bone>
{
public Bones() {
public Bones()
{
Add(new Bone { });
}
}
}

@ -22,7 +22,7 @@ namespace WpfApp
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window,INotifyPropertyChanged
public partial class MainWindow : Window, INotifyPropertyChanged
{
private KinectManager kinectManager;
public KinectManager KinectManager
@ -34,7 +34,8 @@ namespace WpfApp
public KinectStream CurrentKinectStream
{
get { return _currentKinectStream; }
set {
set
{
_currentKinectStream = value;
OnPropertyChanged(nameof(CurrentKinectStream));
}
@ -63,10 +64,8 @@ namespace WpfApp
Debug.WriteLine(CurrentKinectStream.KinectManager.StatusText);
CurrentKinectStream.Start();
Debug.WriteLine(CurrentKinectStream.KinectManager.StatusText);
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Debug.WriteLine(CurrentKinectStream.KinectManager.StatusText);
@ -104,6 +103,7 @@ namespace WpfApp
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
private void ToColorAndBodyImageStream(object sender, RoutedEventArgs e)
{
CurrentKinectStream.Stop();
@ -112,4 +112,4 @@ namespace WpfApp
CurrentKinectStream.Start();
}
}
}
}

@ -33,14 +33,13 @@ using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //où se trouvent les dictionnaires de ressources spécifiques à un thème
//(utilisé si une ressource est introuvable dans la page,
// ou dictionnaires de ressources de l'application)
//(utilisé si une ressource est introuvable dans la page,
// ou dictionnaires de ressources de l'application)
ResourceDictionaryLocation.SourceAssembly //où se trouve le dictionnaire de ressources générique
//(utilisé si une ressource est introuvable dans la page,
// dans l'application ou dans l'un des dictionnaires de ressources spécifiques à un thème)
//(utilisé si une ressource est introuvable dans la page,
// dans l'application ou dans l'un des dictionnaires de ressources spécifiques à un thème)
)]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale

@ -16,8 +16,10 @@ namespace WpfApp
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is BodyImageStream) return ColorAndBodyImageStreamTemplate;
else return OtherStreamTemplate;
if (item is BodyImageStream)
return ColorAndBodyImageStreamTemplate;
else
return OtherStreamTemplate;
}
}
}

Loading…
Cancel
Save