|
|
@ -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();
|
|
|
|