/// <summary> /// Ré-initialise le dessin et les composants. /// </summary> public void EffacerDessin() { _coordonnees = new CoordDessin(_largeur, _hauteur); _objGraphics.Clear(pZoneDessin.BackColor); pZoneDessin.Refresh(); _coordonnees = new CoordDessin(_largeur, _hauteur); }
/// <summary> /// Constructeur. Initialise la zone de dessin. /// </summary> public ucZoneDessin() { InitializeComponent(); _largeur = CstApplication.TAILLEDESSINY; _hauteur = CstApplication.TAILLEDESSINX; pZoneDessin.Image = new Bitmap(_largeur, _hauteur); _objGraphics = Graphics.FromImage(pZoneDessin.Image); _coordonnees = new CoordDessin(_largeur, _hauteur); }
public List <CoordDessin> Extract() { List <CoordDessin> lstCoord = new List <CoordDessin>(); try { FileStream ifsLabels = new FileStream("..\\..\\Data\\t10k-labels.idx1-ubyte", FileMode.Open); // test labels FileStream ifsImages = new FileStream("..\\..\\Data\\t10k-images.idx3-ubyte", FileMode.Open); // test images BinaryReader brLabels = new BinaryReader(ifsLabels); BinaryReader brImages = new BinaryReader(ifsImages); int magic1 = brImages.ReadInt32(); // discard int numImages = brImages.ReadInt32(); int numRows = brImages.ReadInt32(); int numCols = brImages.ReadInt32(); int magic2 = brLabels.ReadInt32(); int numLabels = brLabels.ReadInt32(); byte[][] pixels = new byte[28][]; for (int i = 0; i < pixels.Length; ++i) { pixels[i] = new byte[28]; } // each test image for (int di = 0; di < 10000; ++di) { for (int i = 0; i < 28; ++i) { for (int j = 0; j < 28; ++j) { byte b = brImages.ReadByte(); pixels[i][j] = b; } } byte lbl = brLabels.ReadByte(); DigitImage dImage = new DigitImage(pixels, lbl); // Partie modifier string coordonner = dImage.ToString(); CoordDessin cd = new CoordDessin(CstApplication.TAILLEDESSINY, CstApplication.TAILLEDESSINX); string[] sTabElement = new string[coordonner.Length]; for (int i = 0; i < coordonner.Length; i++) { sTabElement[i] = coordonner[i].ToString(); } for (int x = 0; x < 28; x++) { for (int y = 0; y < 28; y++) { if (Convert.ToInt32(sTabElement[x + (28 * y)]) == 0) { cd.AjouterCoordonnees(x * (CstApplication.TAILLEDESSINX / 28), y * (CstApplication.TAILLEDESSINY / 28), CstApplication.LARGEURTRAIT, CstApplication.HAUTEURTRAIT); } } } cd.Reponse = dImage.label.ToString(); lstCoord.Add(cd); } // each image ifsImages.Close(); brImages.Close(); ifsLabels.Close(); brLabels.Close(); return(lstCoord); } catch (Exception ex) { MessageBox.Show(ex.Message); return(lstCoord); } } // Main
/// <summary> /// Permet d'extraire un fichier texte dans une matrice pour l'apprentissage automatique. /// </summary> public List <CoordDessin> ChargerCoordonnees() { _lstCoord = new List <CoordDessin>(); if (_source == 0) { string sFichier = ConfigurationManager.AppSettings["FichierApprentissage"]; StreamReader sr = new StreamReader(new FileStream(sFichier, FileMode.Open, FileAccess.Read)); string sLigne = ""; string[] sTabElement; int iTailleArray = 0; if (!sr.EndOfStream) { sLigne = sr.ReadLine(); iTailleArray = Convert.ToInt32(sLigne); } if (iTailleArray != CstApplication.NOMBRE_BITS_X * CstApplication.NOMBRE_BITS_Y) { return(_lstCoord); } while (!sr.EndOfStream) { sLigne = sr.ReadLine(); sTabElement = sLigne.Split('\t'); CoordDessin cd = new CoordDessin(CstApplication.TAILLEDESSINY, CstApplication.TAILLEDESSINX); for (int x = 0; x < CstApplication.NOMBRE_BITS_X; x++) { for (int y = 0; y < CstApplication.NOMBRE_BITS_Y; y++) { if (Convert.ToInt32(sTabElement[y + (CstApplication.NOMBRE_BITS_Y * x)]) == CstApplication.FAUX) { cd.AjouterCoordonnees(x * CstApplication.LARGEURTRAIT, y * CstApplication.HAUTEURTRAIT, CstApplication.LARGEURTRAIT, CstApplication.HAUTEURTRAIT); } } } cd.Reponse = sTabElement[sTabElement.Length - 1]; _lstCoord.Add(cd); } sr.Close(); } else if (_source == 1) { try { using (Entities context = new Entities()) { var qDessin = context.Dessin.Where(d => d.Taille == CstApplication.NOMBRE_BITS_X * CstApplication.NOMBRE_BITS_Y); if (qDessin.Count() <= 0) { return(_lstCoord); } List <Dessin> lstDessin = qDessin.ToList(); foreach (Dessin d in lstDessin) { CoordDessin cd = new CoordDessin(CstApplication.TAILLEDESSINY, CstApplication.TAILLEDESSINX); cd.Reponse = d.Charactère; string[] sTabElement = new string[d.Coordonnées.Length]; for (int i = 0; i < d.Coordonnées.Length; i++) { sTabElement[i] = d.Coordonnées[i].ToString(); } for (int x = 0; x < CstApplication.NOMBRE_BITS_X; x++) { for (int y = 0; y < CstApplication.NOMBRE_BITS_Y; y++) { if (Convert.ToInt32(sTabElement[y + (CstApplication.NOMBRE_BITS_Y * x)]) == 0) { cd.AjouterCoordonnees(x * CstApplication.LARGEURTRAIT, y * CstApplication.HAUTEURTRAIT, CstApplication.LARGEURTRAIT, CstApplication.HAUTEURTRAIT); } } } _lstCoord.Add(cd); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } return(_lstCoord); }