Compare commits
10 Commits
5ce0a50ae1
...
ecaa884861
Author | SHA1 | Date | |
---|---|---|---|
|
ecaa884861 | ||
|
db2b79baf8 | ||
|
c330afc0e3 | ||
|
2db47abee0 | ||
|
12d745d1b0 | ||
|
fe589a29e7 | ||
|
3e954843b3 | ||
|
241d2a6ffb | ||
|
0388e18999 | ||
|
c494485a05 |
@ -61,12 +61,11 @@
|
|||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
<Compile Include="Model\CstApplication.cs" />
|
<Compile Include="Model\CstApplication.cs" />
|
||||||
<Compile Include="Model\GestionFichiersSorties.cs" />
|
<Compile Include="Model\GestionFichiersSorties.cs" />
|
||||||
|
<Compile Include="Model\GestionKinect.cs" />
|
||||||
<Compile Include="Model\IGestionFichiers.cs" />
|
<Compile Include="Model\IGestionFichiers.cs" />
|
||||||
<Compile Include="Model\Perceptron.cs" />
|
<Compile Include="Model\Perceptron.cs" />
|
||||||
<Compile Include="Model\GestionPerceptrons.cs" />
|
<Compile Include="Model\GestionPerceptrons.cs" />
|
||||||
<Compile Include="Model\ROGER.cs" />
|
|
||||||
<Compile Include="Model\Squelette.cs" />
|
<Compile Include="Model\Squelette.cs" />
|
||||||
<Compile Include="Model\GestionWEntrainement.cs" />
|
|
||||||
<Compile Include="Presenter\JouerMp3.cs" />
|
<Compile Include="Presenter\JouerMp3.cs" />
|
||||||
<Compile Include="Presenter\JouerSon.cs" />
|
<Compile Include="Presenter\JouerSon.cs" />
|
||||||
<Compile Include="App.xaml.cs">
|
<Compile Include="App.xaml.cs">
|
||||||
|
@ -1,21 +1,67 @@
|
|||||||
using System.Collections.Generic;
|
using JeuHoy_WPF;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace JeuHoy_WPF_Natif.Model
|
namespace JeuHoy_WPF_Natif.Model {
|
||||||
{
|
public class GestionFichiersSorties : IGestionFichiers {
|
||||||
public class GestionFichiersSorties : IGestionFichiers
|
public GestionFichiersSorties(){}
|
||||||
{
|
|
||||||
public GestionFichiersSorties()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Squelette> ChargerCoordonnees(string fichier)
|
public List<Squelette> ChargerCoordonnees(string fichier) {
|
||||||
{
|
List<Squelette> lstSql = new List<Squelette>();
|
||||||
throw new System.NotImplementedException();
|
string sLigne = "";
|
||||||
}
|
string[] sTabAttributs = null;
|
||||||
|
|
||||||
public int SauvegarderCoordonnees(string fichier, List<Squelette> lstData)
|
if (!File.Exists(fichier))
|
||||||
{
|
return lstSql;
|
||||||
throw new System.NotImplementedException();
|
|
||||||
|
StreamReader lecteur = new StreamReader(fichier);
|
||||||
|
|
||||||
|
if (!lecteur.EndOfStream) {
|
||||||
|
sLigne = lecteur.ReadLine();
|
||||||
|
int nbElements = Convert.ToInt32(sLigne);
|
||||||
|
|
||||||
|
sLigne = lecteur.ReadLine();
|
||||||
|
int nbAttributs = Convert.ToInt32(sLigne);
|
||||||
|
|
||||||
|
for (int i = 0; i < nbElements; i++) {
|
||||||
|
double[] doubles = new double[nbAttributs];
|
||||||
|
sLigne = lecteur.ReadLine();
|
||||||
|
sTabAttributs = sLigne.Split('\t');
|
||||||
|
for (int j = 0; j < sTabAttributs.Length - 1; j++) {
|
||||||
|
doubles[j] = Convert.ToDouble(sTabAttributs[j]);
|
||||||
|
}
|
||||||
|
string rep = Convert.ToInt32(sTabAttributs[sTabAttributs.Length - 1]).ToString();
|
||||||
|
lstSql.Add(new Squelette(doubles, rep));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lstSql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SauvegarderCoordonnees(string fichier, List<Squelette> lstData) {
|
||||||
|
StreamWriter sw = null;
|
||||||
|
try {
|
||||||
|
sw = new StreamWriter(fichier);
|
||||||
|
} catch {
|
||||||
|
return CstApplication.ERREUR;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sw.WriteLine(lstData.Count);
|
||||||
|
sw.WriteLine(CstApplication.SKELETONCOUNT * 2);
|
||||||
|
foreach (Squelette s in lstData) {
|
||||||
|
foreach (double point in s.Points) {
|
||||||
|
sw.Write(point.ToString() + "\t");
|
||||||
|
}
|
||||||
|
sw.Write(s.Reponse + "\r\n");
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
sw.Close();
|
||||||
|
return CstApplication.ERREUR;
|
||||||
|
}
|
||||||
|
|
||||||
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
|
return CstApplication.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
189
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/GestionKinect.cs
Normal file
189
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/GestionKinect.cs
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
using JeuHoy_WPF;
|
||||||
|
using Microsoft.Kinect;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace JeuHoy_WPF_Natif.Model {
|
||||||
|
public class GestionKinect {
|
||||||
|
public Image Image { get; set; }
|
||||||
|
public string Console { get; set; }
|
||||||
|
public Canvas Canvas { get; set; }
|
||||||
|
public double[] Body { get; set; }
|
||||||
|
|
||||||
|
private KinectSensor _sensor;
|
||||||
|
private MultiSourceFrameReader _multiSourceFrameReader;
|
||||||
|
private BodyFrameReader _bodyFrameReader;
|
||||||
|
private WriteableBitmap _bitmap;
|
||||||
|
|
||||||
|
private byte[] _picPixels = null;
|
||||||
|
public GestionKinect(Image img, Canvas cnv) {
|
||||||
|
Image = img;
|
||||||
|
Canvas = cnv;
|
||||||
|
_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
Image.Source = _bitmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public WriteableBitmap GetImage() => _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>
|
||||||
|
/// <param name="joueur">Le joueur détecté</param>
|
||||||
|
/// <param name="sensor">Le sensor Kinect</param>
|
||||||
|
private void DessinerSquelette(Body body, KinectSensor sensor) {
|
||||||
|
try {
|
||||||
|
if (body != null) {
|
||||||
|
Canvas.Children.Clear();
|
||||||
|
Joint[] joints = body.Joints.Values.ToArray();
|
||||||
|
for (int i = 0; i < joints.Count(); i++)
|
||||||
|
DrawJoint(sensor, joints[i], CstApplication.BODY_ELLIPSE_SIZE, Canvas);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Console = ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Body is null)
|
||||||
|
Body = new double[CstApplication.SKELETONCOUNT * 2];
|
||||||
|
|
||||||
|
Vector trans = (Vector)GetPoint(sensor, body.Joints[JointType.Head].Position, new Vector(0, 0));
|
||||||
|
for (int i = 0; i < CstApplication.SKELETONCOUNT; ++i) {
|
||||||
|
Point po = GetPoint(sensor, body.Joints[Squelette.Joints[i]].Position, trans);
|
||||||
|
Body[i * 2] = po.X;
|
||||||
|
Body[i * 2 + 1] = po.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dessine le joint d'un squellete d'un senseur Kinect sur le canvas passé en paramètre
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sensor"></param>
|
||||||
|
/// <param name="joint"></param>
|
||||||
|
/// <param name="size"></param>
|
||||||
|
/// <param name="canvas"></param>
|
||||||
|
private void DrawJoint(KinectSensor sensor, Joint joint, int size, Canvas canvas) {
|
||||||
|
if (joint.Position.X != 0 && joint.Position.Y != 0 && joint.Position.Z != 0) {
|
||||||
|
// Convertir la position du joint en coordonnées d'écran
|
||||||
|
System.Windows.Point point = GetPoint(sensor, joint.Position, canvas.Height, canvas.Width);
|
||||||
|
|
||||||
|
// Créer un cercle à la position du joint
|
||||||
|
Ellipse ellipse = new Ellipse();
|
||||||
|
ellipse.Fill = new SolidColorBrush(Colors.Yellow);
|
||||||
|
ellipse.Width = size;
|
||||||
|
ellipse.Height = size;
|
||||||
|
|
||||||
|
// Positionner le cercle sur l'élément de dessin Canvas
|
||||||
|
Canvas.SetLeft(ellipse, point.X - size / 2);
|
||||||
|
Canvas.SetTop(ellipse, point.Y - size / 2);
|
||||||
|
|
||||||
|
// Ajouter le cercle à l'élément de dessin Canvas
|
||||||
|
canvas.Children.Add(ellipse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne le point x,y d'un joint par rapport à la taille d'un canvas.
|
||||||
|
/// J'ai permis de dépasser le canvas car je trouvais ça drole :-)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sensor"></param>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <param name="iCanvasHeight"></param>
|
||||||
|
/// <param name="iCanvasWidth"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public System.Windows.Point GetPoint(KinectSensor sensor, CameraSpacePoint position, double iCanvasHeight, double iCanvasWidth) {
|
||||||
|
System.Windows.Point point = new System.Windows.Point();
|
||||||
|
|
||||||
|
DepthSpacePoint depthPoint = sensor.CoordinateMapper.MapCameraPointToDepthSpace(position);
|
||||||
|
point.X = float.IsInfinity(depthPoint.X) ? 0.0 : depthPoint.X;
|
||||||
|
point.Y = float.IsInfinity(depthPoint.Y) ? 0.0 : depthPoint.Y;
|
||||||
|
|
||||||
|
// La Kinect pour Xbox One utilise également le SDK 2 de Microsoft, et sa résolution de profondeur est de 512x424 pixels.
|
||||||
|
//// Ainsi, la résolution de la carte de profondeur pour la Kinect pour Xbox One est également de 512x424 pixels.
|
||||||
|
point.X = point.X / 512 * iCanvasHeight;
|
||||||
|
point.Y = point.Y / 424 * iCanvasWidth;
|
||||||
|
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point GetPoint(KinectSensor sensor, CameraSpacePoint position, Vector trans) {
|
||||||
|
Point point = new System.Windows.Point();
|
||||||
|
|
||||||
|
DepthSpacePoint depthPoint = sensor.CoordinateMapper.MapCameraPointToDepthSpace(position);
|
||||||
|
point.X = float.IsInfinity(depthPoint.X) ? 0.0 : depthPoint.X;
|
||||||
|
point.Y = float.IsInfinity(depthPoint.Y) ? 0.0 : depthPoint.Y;
|
||||||
|
|
||||||
|
// La Kinect pour Xbox One utilise également le SDK 2 de Microsoft, et sa résolution de profondeur est de 512x424 pixels.
|
||||||
|
//// Ainsi, la résolution de la carte de profondeur pour la Kinect pour Xbox One est également de 512x424 pixels.
|
||||||
|
point.X = point.X / 512;
|
||||||
|
point.Y = point.Y / 424;
|
||||||
|
|
||||||
|
return Point.Subtract(point, trans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,19 +4,25 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using JeuHoy_WPF_Natif.Model;
|
||||||
|
|
||||||
namespace JeuHoy_WPF_Natif.Model {
|
namespace JeuHoy_WPF_Natif.Model {
|
||||||
public class GestionPerceptrons {
|
public class GestionPerceptrons {
|
||||||
private Dictionary<string, Perceptron> _lstPerceptrons = new Dictionary<string, Perceptron>();
|
private Dictionary<string, Perceptron> _lstPerceptrons = new Dictionary<string, Perceptron>();
|
||||||
private Model.IGestionFichiers _gestionSortie = new GestionFichiersSorties();
|
private IGestionFichiers _gestionSortie = new GestionFichiersSorties();
|
||||||
private List<Squelette> _lstData = new List<Squelette>();
|
private List<Squelette> _lstData;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructeur
|
/// Constructeur
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GestionPerceptrons() {
|
public GestionPerceptrons() {
|
||||||
|
_lstData = _gestionSortie.ChargerCoordonnees("train.txt");
|
||||||
|
|
||||||
for (char x = '0'; x <= '9'; ++x)
|
for (char x = '0'; x <= '9'; ++x)
|
||||||
_lstPerceptrons.Add(x.ToString(), new Perceptron(x.ToString()));
|
_lstPerceptrons.Add(x.ToString(), new Perceptron(x.ToString()));
|
||||||
|
|
||||||
|
foreach (Squelette sql in _lstData)
|
||||||
|
Entrainement(sql, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -44,6 +50,7 @@ namespace JeuHoy_WPF_Natif.Model {
|
|||||||
if (reponse != "") {
|
if (reponse != "") {
|
||||||
coordo.Reponse = reponse;
|
coordo.Reponse = reponse;
|
||||||
_lstData.Add(coordo);
|
_lstData.Add(coordo);
|
||||||
|
SauvegarderCoordonnees("train.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lstData is null)
|
if (_lstData is null)
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace JeuHoy_WPF_Natif.Model
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Description: Logique pour la vue Entrainement
|
|
||||||
/// </summary>
|
|
||||||
public class GestionWEntrainement
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Presentation3Tiers.DAL
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Auteur : Hugo St-Louis
|
|
||||||
/// Description : Classe concrète qui gère un fichier texte.
|
|
||||||
/// Date : 2023-03-29
|
|
||||||
/// </summary>
|
|
||||||
public class GestionFichierTexte : ILectureFichier
|
|
||||||
{
|
|
||||||
public BDApprentissageAuto BD { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// permet de remplir la structure de données pour l'apprentissage automatique à partir dun fichier texte
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sNomFichier"></param>
|
|
||||||
public BDApprentissageAuto RemplirDonneesBD(string sNomFichier)
|
|
||||||
{
|
|
||||||
StreamReader lecteur = new StreamReader(sNomFichier);
|
|
||||||
string sLigne = "";
|
|
||||||
BD = new BDApprentissageAuto();
|
|
||||||
string[] sTabElements = null;
|
|
||||||
|
|
||||||
if (!lecteur.EndOfStream)
|
|
||||||
{
|
|
||||||
sLigne = lecteur.ReadLine();
|
|
||||||
BD.NbElements = Convert.ToInt32(sLigne);
|
|
||||||
|
|
||||||
sLigne = lecteur.ReadLine();
|
|
||||||
BD.NbAttributs = Convert.ToInt32(sLigne);
|
|
||||||
|
|
||||||
BD.Elements = new double[BD.NbElements, BD.NbAttributs - 1];
|
|
||||||
BD.Resultats = new int[BD.NbElements];
|
|
||||||
for (int i = 0; i < BD.NbElements; i++)
|
|
||||||
{
|
|
||||||
sLigne = lecteur.ReadLine();
|
|
||||||
sTabElements = sLigne.Split('\t');
|
|
||||||
for (int j = 0; j < sTabElements.Length - 1; j++)
|
|
||||||
{
|
|
||||||
BD.Elements[i, j] = Convert.ToDouble(sTabElements[j]);
|
|
||||||
}
|
|
||||||
BD.Resultats[i] = Convert.ToInt32(sTabElements[sTabElements.Length - 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return BD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rempli et affiche les resultats dun fichier dapprentissage auto
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sNomFichier"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string RemplirEtAfficherDonneesBD(string sNomFichier)
|
|
||||||
{
|
|
||||||
RemplirDonneesBD(sNomFichier);
|
|
||||||
string sResultat = "";
|
|
||||||
sResultat = "nb elements : " + BD.NbElements + "\r\n";
|
|
||||||
sResultat += "nb attribut : " + BD.NbAttributs + "\r\n";
|
|
||||||
sResultat += "Voici les attribut et valeur de verité" + "\r\n";
|
|
||||||
for (int i = 0; i < BD.NbElements; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < BD.NbAttributs - 1; j++)
|
|
||||||
{
|
|
||||||
sResultat += BD.Elements[i, j] + "\t";
|
|
||||||
}
|
|
||||||
sResultat += "\r\nValeur de verite : " + BD.Resultats[i] + "\r\n";
|
|
||||||
}
|
|
||||||
return sResultat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Lit et retourne le contenu d'un fichier texte
|
|
||||||
/// pour lequel le nom est passé en paramètre.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sNomFichier"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string LireFichierTexte(string sNomFichier)
|
|
||||||
{
|
|
||||||
bool bFichierExiste = File.Exists(sNomFichier);
|
|
||||||
string sContenuFichier = "";
|
|
||||||
StreamReader sr = null;
|
|
||||||
if (!bFichierExiste)
|
|
||||||
return "Le fichier n'existe pas ....";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sr = new StreamReader(sNomFichier);
|
|
||||||
sContenuFichier = sr.ReadToEnd();
|
|
||||||
return sContenuFichier;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return "Erreur lors de la lecture du fichier : " +
|
|
||||||
ex.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,7 +9,7 @@ using System.Windows;
|
|||||||
|
|
||||||
namespace JeuHoy_WPF_Natif.Model {
|
namespace JeuHoy_WPF_Natif.Model {
|
||||||
public class Squelette {
|
public class Squelette {
|
||||||
static private JointType[] _joints = new JointType[CstApplication.SKELETONCOUNT] {
|
static public readonly JointType[] Joints = new JointType[CstApplication.SKELETONCOUNT] {
|
||||||
JointType.HandLeft,
|
JointType.HandLeft,
|
||||||
JointType.HandRight,
|
JointType.HandRight,
|
||||||
JointType.ElbowLeft,
|
JointType.ElbowLeft,
|
||||||
@ -22,42 +22,20 @@ namespace JeuHoy_WPF_Natif.Model {
|
|||||||
JointType.Neck
|
JointType.Neck
|
||||||
};
|
};
|
||||||
|
|
||||||
private double[] _sque = new double[CstApplication.SKELETONCOUNT * 2];
|
private double[] _sque;
|
||||||
private string _rep = "?";
|
private string _rep = "?";
|
||||||
|
|
||||||
public string Reponse { get => _rep; set => _rep = value; }
|
public string Reponse { get => _rep; set => _rep = value; }
|
||||||
|
|
||||||
public double[] Points => _sque;
|
public double[] Points => _sque;
|
||||||
|
|
||||||
public Squelette(KinectSensor kin, Body body, string reponse) {
|
public Squelette(double[] body, string reponse) {
|
||||||
Vector trans = (Vector)GetPoint(kin, body.Joints[JointType.Head].Position, new Vector(0,0));
|
if (body.Length != CstApplication.SKELETONCOUNT * 2) {
|
||||||
|
_sque = new double[CstApplication.SKELETONCOUNT * 2];
|
||||||
for (int i = 0; i < CstApplication.SKELETONCOUNT; ++i) {
|
} else {
|
||||||
Point po = GetPoint(kin, body.Joints[_joints[i]].Position, trans);
|
_sque = body;
|
||||||
|
|
||||||
_sque[i * 2] = po.X;
|
|
||||||
_sque[i * 2 + 1] = po.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reponse.Length == 1)
|
|
||||||
_rep = reponse;
|
_rep = reponse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point GetPoint(KinectSensor sensor, CameraSpacePoint position, Vector trans) {
|
|
||||||
Point point = new System.Windows.Point();
|
|
||||||
|
|
||||||
DepthSpacePoint depthPoint = sensor.CoordinateMapper.MapCameraPointToDepthSpace(position);
|
|
||||||
point.X = float.IsInfinity(depthPoint.X) ? 0.0 : depthPoint.X;
|
|
||||||
point.Y = float.IsInfinity(depthPoint.Y) ? 0.0 : depthPoint.Y;
|
|
||||||
|
|
||||||
// La Kinect pour Xbox One utilise également le SDK 2 de Microsoft, et sa résolution de profondeur est de 512x424 pixels.
|
|
||||||
//// Ainsi, la résolution de la carte de profondeur pour la Kinect pour Xbox One est également de 512x424 pixels.
|
|
||||||
point.X = point.X / 512;
|
|
||||||
point.Y = point.Y / 424;
|
|
||||||
|
|
||||||
return Point.Subtract(point, trans);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,21 +14,22 @@ namespace JeuHoy_WPF_Natif.Presenter
|
|||||||
public class PresentateurWEntrainement
|
public class PresentateurWEntrainement
|
||||||
{
|
{
|
||||||
private IwEntrainement _vue;
|
private IwEntrainement _vue;
|
||||||
private GestionWEntrainement _gestionnaire;
|
private GestionPerceptrons _gestionnairePerceptron;
|
||||||
|
private GestionKinect _gestionnaireKinect;
|
||||||
|
|
||||||
public PresentateurWEntrainement(IwEntrainement vue)
|
public PresentateurWEntrainement(IwEntrainement vue)
|
||||||
{
|
{
|
||||||
_vue = vue;
|
_vue = vue;
|
||||||
_gestionnaire = new GestionWEntrainement();
|
_gestionnairePerceptron = new GestionPerceptrons();
|
||||||
|
_gestionnaireKinect = new GestionKinect(_vue.Image, _vue.Canvas);
|
||||||
_vue.EntrainementEvt += _vue_EntrainementEvt;
|
_vue.EntrainementEvt += _vue_EntrainementEvt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void _vue_EntrainementEvt(object sender, EventArgs e)
|
private void _vue_EntrainementEvt(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Perceptron!!!
|
// Perceptron!!!
|
||||||
throw new NotImplementedException();
|
string position = (_vue.GetPositionEnCour() - 1).ToString();
|
||||||
|
_vue.Console = _gestionnairePerceptron.Entrainement(new Squelette(_gestionnaireKinect.Body, position), position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,8 @@ namespace JeuHoy_WPF_Natif.View
|
|||||||
string Console { get; set; }
|
string Console { get; set; }
|
||||||
Canvas Canvas { get; set; }
|
Canvas Canvas { get; set; }
|
||||||
event EventHandler EntrainementEvt;
|
event EventHandler EntrainementEvt;
|
||||||
}
|
|
||||||
|
int GetPositionEnCour();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using JeuHoy_WPF_Natif.View;
|
|||||||
using Microsoft.Kinect;
|
using Microsoft.Kinect;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@ -33,190 +34,23 @@ namespace JeuHoy_WPF.View
|
|||||||
public string Console { get => txtConsole.Text; set => txtConsole.Text = value; }
|
public string Console { get => txtConsole.Text; set => txtConsole.Text = value; }
|
||||||
public Canvas Canvas { get => pDessinSquelette; set => pDessinSquelette = value; }
|
public Canvas Canvas { get => pDessinSquelette; set => pDessinSquelette = value; }
|
||||||
|
|
||||||
private KinectSensor _sensor;
|
|
||||||
private MultiSourceFrameReader _multiSourceFrameReader;
|
|
||||||
private BodyFrameReader _bodyFrameReader;
|
|
||||||
private WriteableBitmap _bitmap;
|
|
||||||
//private DisplayFrameType _displayFrameType = DisplayFrameType.Color;
|
|
||||||
|
|
||||||
private byte[] _picPixels = null;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructeur
|
/// Constructeur
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public wEntrainement()
|
public wEntrainement()
|
||||||
{
|
{
|
||||||
_presentateur = new PresentateurWEntrainement(this);
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
_presentateur = new PresentateurWEntrainement(this);
|
||||||
|
|
||||||
_sensor = KinectSensor.GetDefault();
|
for (int x = 1; x <= CstApplication.NBFIGURE; ++x)
|
||||||
if (_sensor != null)
|
if (File.Exists("HoyContent/fig" + x.ToString() + ".png"))
|
||||||
{
|
_dicImgFigure.Add("fig" + x, new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"./HoyContent/fig" + x.ToString() + ".png", UriKind.Absolute)));
|
||||||
_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);
|
|
||||||
_dicImgFigure.Add("fig" + i, new BitmapImage(uriSource));
|
|
||||||
}
|
|
||||||
|
|
||||||
lblNbPositions.Content = "/ " + CstApplication.NBFIGURE.ToString();
|
|
||||||
ChargerFigure();
|
ChargerFigure();
|
||||||
_son.JouerSonAsync(@"./HoyContent/hoy.wav");
|
_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>
|
|
||||||
/// <param name="joueur">Le joueur détecté</param>
|
|
||||||
/// <param name="sensor">Le sensor Kinect</param>
|
|
||||||
private void DessinerSquelette(Body body, KinectSensor sensor)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
txtConsole.Text = ex.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Dessine le joint d'un squellete d'un senseur Kinect sur le canvas passé en paramètre
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sensor"></param>
|
|
||||||
/// <param name="joint"></param>
|
|
||||||
/// <param name="size"></param>
|
|
||||||
/// <param name="canvas"></param>
|
|
||||||
private void DrawJoint(KinectSensor sensor, Joint joint, int size, Canvas canvas)
|
|
||||||
{
|
|
||||||
if (joint.Position.X != 0 && joint.Position.Y != 0 && joint.Position.Z != 0)
|
|
||||||
{
|
|
||||||
// Convertir la position du joint en coordonnées d'écran
|
|
||||||
System.Windows.Point point = GetPoint(sensor, joint.Position, canvas.Height, canvas.Width);
|
|
||||||
|
|
||||||
// Créer un cercle à la position du joint
|
|
||||||
Ellipse ellipse = new Ellipse();
|
|
||||||
ellipse.Fill = new SolidColorBrush(Colors.Yellow);
|
|
||||||
ellipse.Width = size;
|
|
||||||
ellipse.Height = size;
|
|
||||||
|
|
||||||
// Positionner le cercle sur l'élément de dessin Canvas
|
|
||||||
Canvas.SetLeft(ellipse, point.X - size / 2);
|
|
||||||
Canvas.SetTop(ellipse, point.Y - size / 2);
|
|
||||||
|
|
||||||
// Ajouter le cercle à l'élément de dessin Canvas
|
|
||||||
canvas.Children.Add(ellipse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retourne le point x,y d'un joint par rapport à la taille d'un canvas.
|
|
||||||
/// J'ai permis de dépasser le canvas car je trouvais ça drole :-)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sensor"></param>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <param name="iCanvasHeight"></param>
|
|
||||||
/// <param name="iCanvasWidth"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public System.Windows.Point GetPoint(KinectSensor sensor, CameraSpacePoint position, double iCanvasHeight, double iCanvasWidth)
|
|
||||||
{
|
|
||||||
System.Windows.Point point = new System.Windows.Point();
|
|
||||||
|
|
||||||
DepthSpacePoint depthPoint = sensor.CoordinateMapper.MapCameraPointToDepthSpace(position);
|
|
||||||
point.X = float.IsInfinity(depthPoint.X) ? 0.0 : depthPoint.X;
|
|
||||||
point.Y = float.IsInfinity(depthPoint.Y) ? 0.0 : depthPoint.Y;
|
|
||||||
|
|
||||||
// La Kinect pour Xbox One utilise également le SDK 2 de Microsoft, et sa résolution de profondeur est de 512x424 pixels.
|
|
||||||
//// Ainsi, la résolution de la carte de profondeur pour la Kinect pour Xbox One est également de 512x424 pixels.
|
|
||||||
point.X = point.X / 512 * iCanvasHeight;
|
|
||||||
point.Y = point.Y / 424 * iCanvasWidth;
|
|
||||||
|
|
||||||
return point;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Charger la figure de danse en cours.
|
/// Charger la figure de danse en cours.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -298,6 +132,6 @@ namespace JeuHoy_WPF.View
|
|||||||
EntrainementEvt(this, e);
|
EntrainementEvt(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetPositionEnCour() { return _positionEnCours; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user