merge
This commit is contained in:
@@ -21,7 +21,7 @@ namespace JeuHoy_WPF.View
|
||||
/// </summary>
|
||||
public partial class wEntrainement : Window, IwEntrainement
|
||||
{
|
||||
|
||||
|
||||
private Dictionary<string, BitmapImage> _dicImgFigure = new Dictionary<string, BitmapImage>();
|
||||
private JouerSon _son = new JouerSon();
|
||||
private int _positionEnCours = 1;
|
||||
@@ -33,15 +33,47 @@ namespace JeuHoy_WPF.View
|
||||
public string Console { get => txtConsole.Text; set => txtConsole.Text = value; }
|
||||
public Canvas Canvas { get => pDessinSquelette; set => pDessinSquelette = value; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructeur
|
||||
/// </summary>
|
||||
public wEntrainement()
|
||||
private KinectSensor _sensor;
|
||||
private MultiSourceFrameReader _multiSourceFrameReader;
|
||||
private BodyFrameReader _bodyFrameReader;
|
||||
private WriteableBitmap _bitmap;
|
||||
//private DisplayFrameType _displayFrameType = DisplayFrameType.Color;
|
||||
|
||||
private byte[] _picPixels = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructeur
|
||||
/// </summary>
|
||||
public wEntrainement()
|
||||
{
|
||||
_presentateur = new PresentateurWEntrainement(this);
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
_sensor = KinectSensor.GetDefault();
|
||||
if (_sensor != null)
|
||||
{
|
||||
_sensor.Open();
|
||||
|
||||
//Lecture des images
|
||||
_multiSourceFrameReader = _sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color);
|
||||
_multiSourceFrameReader.MultiSourceFrameArrived += MultiSourceFrameReader_MultiSourceFrameArrived;
|
||||
|
||||
FrameDescription frameDescription = _sensor.ColorFrameSource.FrameDescription;
|
||||
_picPixels = new byte[frameDescription.Width * frameDescription.Height * 4];
|
||||
|
||||
//Lecture des squelettes détectés
|
||||
_bodyFrameReader = _sensor.BodyFrameSource.OpenReader();
|
||||
_bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (int i = 1; i <= CstApplication.NBFIGURE; i++)
|
||||
{
|
||||
Uri uriSource = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"./HoyContent/fig" + i + ".png", UriKind.Absolute);
|
||||
@@ -53,6 +85,59 @@ namespace JeuHoy_WPF.View
|
||||
_son.JouerSonAsync(@"./HoyContent/hoy.wav");
|
||||
}
|
||||
|
||||
|
||||
private void MultiSourceFrameReader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
|
||||
{
|
||||
MultiSourceFrame multiSource = e.FrameReference.AcquireFrame();
|
||||
|
||||
if (multiSource == null)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
using (ColorFrame colorFrame = multiSource.ColorFrameReference.AcquireFrame())
|
||||
{
|
||||
if (colorFrame != null)
|
||||
{
|
||||
FrameDescription frameDescription = colorFrame.FrameDescription;
|
||||
if (_bitmap == null)
|
||||
_bitmap = new WriteableBitmap(frameDescription.Width,
|
||||
frameDescription.Height,
|
||||
96.0,
|
||||
96.0,
|
||||
PixelFormats.Bgra32,
|
||||
null);
|
||||
colorFrame.CopyConvertedFrameDataToArray(_picPixels, ColorImageFormat.Bgra);
|
||||
_bitmap.Lock();
|
||||
Marshal.Copy(_picPixels, 0, _bitmap.BackBuffer, _picPixels.Length);
|
||||
_bitmap.AddDirtyRect(new Int32Rect(0, 0, _bitmap.PixelWidth, _bitmap.PixelHeight));
|
||||
_bitmap.Unlock();
|
||||
picKinect.Source = _bitmap;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void BodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
|
||||
{
|
||||
using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
|
||||
{
|
||||
if (bodyFrame == null)
|
||||
return;
|
||||
Body[] bodies = new Body[bodyFrame.BodyCount];
|
||||
bodyFrame.GetAndRefreshBodyData(bodies);
|
||||
Body body = bodies.FirstOrDefault(b => b.IsTracked);
|
||||
|
||||
if (body != null)
|
||||
{
|
||||
DessinerSquelette(body, _sensor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Dessine un ellipse pour chacune des jointure du squelette détecté.
|
||||
/// </summary>
|
||||
@@ -64,6 +149,7 @@ namespace JeuHoy_WPF.View
|
||||
{
|
||||
if (body != null)
|
||||
{
|
||||
pDessinSquelette.Children.Clear();
|
||||
Joint[] joints = body.Joints.Values.ToArray();
|
||||
for (int i = 0; i < joints.Count(); i++)
|
||||
DrawJoint(sensor, joints[i], CstApplication.BODY_ELLIPSE_SIZE, pDessinSquelette);
|
||||
@@ -92,7 +178,7 @@ namespace JeuHoy_WPF.View
|
||||
|
||||
// Créer un cercle à la position du joint
|
||||
Ellipse ellipse = new Ellipse();
|
||||
ellipse.Fill = new SolidColorBrush(Colors.Green);
|
||||
ellipse.Fill = new SolidColorBrush(Colors.Yellow);
|
||||
ellipse.Width = size;
|
||||
ellipse.Height = size;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user