squelette.Entrainement
This commit is contained in:
parent
be9041cd6f
commit
249f2edbfe
@ -282,8 +282,6 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Vue\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@ -19,11 +19,22 @@ namespace JeuHoy_WPF.View
|
||||
/// </summary>
|
||||
public partial class wEntrainement : Window
|
||||
{
|
||||
|
||||
|
||||
private Dictionary<string, BitmapImage> _dicImgFigure = new Dictionary<string, BitmapImage>();
|
||||
private JouerSon _son = new JouerSon();
|
||||
private int _positionEnCours = 1;
|
||||
|
||||
|
||||
|
||||
private KinectSensor _sensor;
|
||||
private MultiSourceFrameReader _multiSourceFrameReader;
|
||||
private BodyFrameReader _bodyFrameReader;
|
||||
private WriteableBitmap _bitmap;
|
||||
//private DisplayFrameType _displayFrameType = DisplayFrameType.Color;
|
||||
|
||||
private byte[] _picPixels = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructeur
|
||||
@ -32,6 +43,27 @@ namespace JeuHoy_WPF.View
|
||||
{
|
||||
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);
|
||||
@ -43,6 +75,71 @@ 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>
|
||||
@ -54,6 +151,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);
|
||||
@ -82,7 +180,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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user