This commit is contained in:
MarcEricMartel 2023-05-03 10:51:33 -04:00
commit ffe39cd55c
3 changed files with 91 additions and 7 deletions

View File

@ -285,8 +285,6 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Folder Include="Vue\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -22,7 +22,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Canvas x:Name="pDessinSquelette" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="0" Height="300px" Margin="0,0,0,0" VerticalAlignment="Top" Width="300px" Background="Black"/>
<Image x:Name="picKinect" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="1" Height="300px" Margin="0,0,0,0" VerticalAlignment="Top" Width="300px" Grid.RowSpan="2" Source="/Resources/téléchargement.jpg" />
<Image x:Name="picKinect" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="1" Height="300px" Margin="0,0,0,0" VerticalAlignment="Top" Width="300px" Grid.RowSpan="2" Source="/Resources/téléchargement.jpg" Stretch="UniformToFill" />
<TextBox x:Name="txtConsole" HorizontalAlignment="Center" Margin="0,0,0,0" Grid.Row="2" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="300" Height="300" Grid.RowSpan="2"/>
<Image x:Name="picPositionAFaire" Grid.Column="1" HorizontalAlignment="Left" Height="822" VerticalAlignment="Top" Width="828" Grid.RowSpan="3"/>

View File

@ -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,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>
@ -54,6 +139,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 +168,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;