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; GestureName = gestureName;
} }
} }
} }

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

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

@ -12,8 +12,8 @@ namespace KinectUtils
{ {
public static class GestureManager public static class GestureManager
{ {
static private BodyFrameReader bodyFrameReader; private static BodyFrameReader bodyFrameReader;
static private Body[] bodies; private static Body[] bodies;
static event EventHandler GestureRecognized; static event EventHandler GestureRecognized;
static KinectManager KinectManager { get; set; } static KinectManager KinectManager { get; set; }
static List<BaseGesture> KnownGestures { get; set; } = new List<BaseGesture>(); static List<BaseGesture> KnownGestures { get; set; } = new List<BaseGesture>();
@ -26,6 +26,7 @@ namespace KinectUtils
AddGesture(gesture); AddGesture(gesture);
} }
} }
public static void AddGesture(BaseGesture gesture) public static void AddGesture(BaseGesture gesture)
{ {
if (!KnownGestures.Contains(gesture)) if (!KnownGestures.Contains(gesture))
@ -34,6 +35,7 @@ namespace KinectUtils
gesture.GestureRecognized += (sender, e) => GestureRecognized?.Invoke(sender, e); gesture.GestureRecognized += (sender, e) => GestureRecognized?.Invoke(sender, e);
} }
} }
public static void RemoveGesture(BaseGesture gesture) public static void RemoveGesture(BaseGesture gesture)
{ {
if (KnownGestures.Contains(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 = kinectManager.Sensor.BodyFrameSource.OpenReader();
bodyFrameReader.FrameArrived += Reader_BodyFrameArrived; 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()) using (var bodyframe = e.FrameReference.AcquireFrame())
{ {
if (bodyframe != null) if (bodyframe != null)
{ {
if (bodies == null)
if(bodies == null)
{ {
bodies = new Body[bodyframe.BodyCount]; bodies = new Body[bodyframe.BodyCount];
} }
bodyframe.GetAndRefreshBodyData(bodies); 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 public interface IGestureFactory
{ {
IEnumerable<BaseGesture> CreateGestures(); IEnumerable<BaseGesture> CreateGestures();
} }
} }

@ -28,6 +28,7 @@ namespace Lib
get { return bodies; } get { return bodies; }
private set { bodies = value; } private set { bodies = value; }
} }
public override void Stop() public override void Stop()
{ {
if (Reader != null) if (Reader != null)
@ -35,13 +36,22 @@ namespace Lib
Reader.Dispose(); Reader.Dispose();
Reader = null; 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); var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); ColorImageFormat.Bgra
);
Bitmap = new WriteableBitmap(
framedescription.Width,
framedescription.Height,
96.0,
96.0,
PixelFormats.Bgr32,
null
);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader(); reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived; reader.FrameArrived += Reader_BodyFrameArrived;
@ -56,7 +66,10 @@ namespace Lib
Joint joint1 = body.Joints[JointType1]; Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis // 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 Line bone = new Line
{ {
@ -74,7 +87,10 @@ namespace Lib
private Point MapJointToScreen(Joint joint) 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 // Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X; float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
@ -84,86 +100,86 @@ namespace Lib
} }
private void drawskeleton(Body 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)
{ {
// tête et cou Joint joint = body.Joints[JointType];
drawbone(body, JointType.Head, JointType.Neck); if (joint.TrackingState == TrackingState.Tracked)
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]; DrawJoint(MapJointToScreen(joint));
if (joint.TrackingState == TrackingState.Tracked)
{
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,
Width = 10, Fill = new SolidColorBrush(Colors.Red)
Height = 10, };
Fill = new SolidColorBrush(Colors.Red)
};
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2); Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2); Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
Canvas.Children.Add(ellipse); Canvas.Children.Add(ellipse);
} }
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
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 // nettoyer le Canvas avant de dessiner
if (Canvas != null) if (Canvas != null)
{
Canvas.Children.Clear();
foreach (var body in this.bodies)
{ {
Canvas.Children.Clear(); if (body.IsTracked)
foreach (var body in this.bodies)
{ {
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; private ColorFrameReader _colorReader;
public ColorFrameReader ColorReader { public ColorFrameReader ColorReader
{
get { return _colorReader; } get { return _colorReader; }
private set { _colorReader = value; } private set { _colorReader = value; }
} }
@ -33,6 +34,7 @@ namespace Lib
get { return bodies; } get { return bodies; }
private set { bodies = value; } private set { bodies = value; }
} }
public override void Stop() public override void Stop()
{ {
if (Reader != null) if (Reader != null)
@ -40,18 +42,27 @@ namespace Lib
Reader.Dispose(); Reader.Dispose();
Reader = null; Reader = null;
} }
if(ColorReader != null) if (ColorReader != null)
{ {
ColorReader.Dispose(); ColorReader.Dispose();
ColorReader = null; 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); var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); ColorImageFormat.Bgra
);
Bitmap = new WriteableBitmap(
framedescription.Width,
framedescription.Height,
96.0,
96.0,
PixelFormats.Bgr32,
null
);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader(); reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived; reader.FrameArrived += Reader_BodyFrameArrived;
ColorReader = KinectManager.Sensor.ColorFrameSource.OpenReader(); ColorReader = KinectManager.Sensor.ColorFrameSource.OpenReader();
@ -67,7 +78,10 @@ namespace Lib
Joint joint1 = body.Joints[JointType1]; Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis // 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 Line bone = new Line
{ {
@ -85,7 +99,10 @@ namespace Lib
private Point MapJointToScreen(Joint joint) 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 // Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X; float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
@ -157,6 +174,7 @@ namespace Lib
Canvas.Children.Add(ellipse); Canvas.Children.Add(ellipse);
} }
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{ {
using (var bodyframe = e.FrameReference.AcquireFrame()) using (var bodyframe = e.FrameReference.AcquireFrame())
@ -178,6 +196,7 @@ namespace Lib
} }
} }
} }
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e) private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{ {
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame()) using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
@ -193,14 +212,22 @@ namespace Lib
this.Bitmap.Lock(); this.Bitmap.Lock();
// Vérifier si la taille de l'image a changé // 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( colorFrame.CopyConvertedFrameDataToIntPtr(
this.Bitmap.BackBuffer, this.Bitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4), (uint)(
ColorImageFormat.Bgra); colorFrameDescription.Width * colorFrameDescription.Height * 4
),
this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)); ColorImageFormat.Bgra
);
this.Bitmap.AddDirtyRect(
new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)
);
} }
this.Bitmap.Unlock(); this.Bitmap.Unlock();

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

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

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

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

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

@ -10,7 +10,8 @@ namespace Lib
public class KinectStreamsFactory public class KinectStreamsFactory
{ {
private KinectManager _kinectManager; private KinectManager _kinectManager;
public KinectManager KinectManager { public KinectManager KinectManager
{
get { return _kinectManager; } get { return _kinectManager; }
private set { _kinectManager = value; } private set { _kinectManager = value; }
} }
@ -22,18 +23,21 @@ namespace Lib
private set { _streamFactory = value; } private set { _streamFactory = value; }
} }
public KinectStreamsFactory(KinectManager kinect,Canvas SkeletonCanvas) public KinectStreamsFactory(KinectManager kinect, Canvas SkeletonCanvas)
{ {
_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<KinectStream>>
{ {
{ KinectStreams.Color, () => new ColorImageStream(KinectManager) }, { KinectStreams.Color, () => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, () => new DepthImageStream(KinectManager) }, { KinectStreams.Depth, () => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) }, { KinectStreams.IR, () => new InfraredImageStream(KinectManager) },
{ KinectStreams.Body, () => new BodyImageStream(KinectManager,SkeletonCanvas) }, { KinectStreams.Body, () => new BodyImageStream(KinectManager, SkeletonCanvas) },
{ KinectStreams.ColorAndBody, () => new ColorAndBodyImageStream(KinectManager,SkeletonCanvas) } {
}; KinectStreams.ColorAndBody,
() => new ColorAndBodyImageStream(KinectManager, SkeletonCanvas)
}
};
} }
public KinectStream this[KinectStreams stream] public KinectStream this[KinectStreams stream]
@ -51,4 +55,4 @@ namespace Lib
} }
} }
} }
} }

@ -23,7 +23,9 @@ namespace MyGesturesBank
var handLeft = body.Joints[JointType.HandLeft].Position; var handLeft = body.Joints[JointType.HandLeft].Position;
// Vérifie si les mains sont à une hauteur similaire et devant le corps // 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) 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é // Le clap est un geste instantané, donc si les conditions sont remplies une fois, le geste est considéré comme terminé
return true; return true;
} }
public override string GestureName => "Clap Hands"; public override string GestureName => "Clap Hands";
} }
} }

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

@ -15,10 +15,10 @@ namespace MyGesturesBank
// Ajustez les seuils selon la précision souhaitée // Ajustez les seuils selon la précision souhaitée
var threshold = 0.1f; // Seuil pour ajuster la précision de la détection 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"; public override string GestureName => "Posture Hands On Head";
} }
} }

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

@ -10,7 +10,6 @@ namespace MyGesturesBank
{ {
public class SwipeRightHand : Gesture public class SwipeRightHand : Gesture
{ {
private float previousX = float.NaN; private float previousX = float.NaN;
protected override bool TestInitialConditions(Body body) 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 // 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 return handRight.X > spineBase.X + 0.5f; // Ajustez cette valeur selon le besoin
} }
public override string GestureName => "Swipe Right Hand"; public override string GestureName => "Swipe Right Hand";
} }
} }

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

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

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

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

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

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

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

Loading…
Cancel
Save