Beispiel #1
0
        private void DetectarBorde_Click(object sender, EventArgs e)
        {
            this.MascaraGenerica1 = conseguirMascara(MascaraTextX);
            this.MascaraGenerica2 = conseguirMascara(MascataTxtY);

            int c = 0;

            if (ImagenEnXOpt.Checked)
            {
                c = 1;
            }
            else
            if (ImagenEnY.Checked)
            {
                c = -1;
            }
            else
            if (ImagenEnZOpt.Checked)
            {
                c = 0;
            }


            this.ImagenEntrada.Image = (Image)PictureAnalizer.DetectarBordes(MascaraGenerica1, MascaraGenerica2, c, (Bitmap)ImagenEntrada.Image);
        }
Beispiel #2
0
        private void button26_Click(object sender, EventArgs e)
        {
            string[] nombres = { "Vacio", "Torres", "Caballos", "Alfiles", "Reinas", "Reyes", "Peones" };

            //ActivationNetwork rna = EntrenarRNA();

            // rna.Save("save1.rna");
            // para cada imagen en la direccion de entrenamiento
            DirectoryInfo sc = new DirectoryInfo(rutaEjemplos);

            FileInfo[] s = sc.GetFiles();
            Bitmap[,] Matzs = null;
            double[][] Carz = new double[8 * 8][];
            double[]   Obj  =
            {
                1, 2, 3, 4, 5, 3, 2, 1,
                6, 6, 6, 6, 6, 6, 6, 6,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 0, 0, 0, 0,
                6, 6, 6, 6, 6, 6, 6, 6,
                1, 2, 3, 4, 5, 3, 2, 1,
            };

            for (int k = 0; k < 64; k++)
            {
                Carz[k] = new double[6];
            }

            int b = 0;

            foreach (FileInfo imgEjemp in s)
            {
                ImagenEntrada.Image           = PictureAnalizer.ImagenColor2Gray((Bitmap)Image.FromFile(imgEjemp.FullName));
                PictureAnalizer.ImagenEntrada = (Bitmap)ImagenEntrada.Image;

                Mascara mX = new Mascara(Mascara.PRDF_Opdr_LPcX, new Size(3, 3), new Point(1, 1));
                Mascara mY = new Mascara(Mascara.PRDF_Opdr_LpcY, new Size(3, 3), new Point(1, 1));

                ImagenEntrada.Image = PictureAnalizer.DetectarBordes(mX, mY, 0, (Bitmap)ImagenEntrada.Image);
                ImagenEntrada.Image.Save(@"C:\Users\frodo\Desktop\ejemplos - copia\" + "imgBorde" + b.ToString() + ".jpeg");
                b++;


                Matzs = PictureAnalizer.DividirImagen((Bitmap)ImagenEntrada.Image, 8);
                ImagenEntrada.Refresh();
                System.Threading.Thread.Sleep(1000);


                int n = 0;
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        Bitmap im = Matzs[j, i];
                        ImagenEntrada.Image = im;
                        int           p      = (int)Obj[n];
                        string        dir    = "Piesas/" + nombres[p] + "/";
                        DirectoryInfo dest   = new DirectoryInfo(dir);
                        FileInfo[]    infDir = dest.GetFiles();
                        switch (p)
                        {
                        case 0: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;

                        case 1: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;

                        case 2: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;

                        case 3: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;

                        case 4: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;

                        case 5: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;

                        case 6: im.Save(dir + nombres[p] + infDir.Length + ".jpeg"); break;
                        }

                        Carz[n] = PictureAnalizer.CalcularCaracteristicasTextura(im);


                        for (int v = 0; v < Carz[n].Length; v++)
                        {
                            Console.WriteLine(Carz[n][v]);
                        }



                        ImagenEntrada.Refresh();
                        System.Threading.Thread.Sleep(100);
                        n++;
                    }
                }
            }



            List <Bitmap[]>   ListaEntradas = new List <Bitmap[]>();
            List <double[][]> ListaCarz     = new List <double[][]>();
            double            carTota       = 0;

            for (int k = 0; k < 7; k++)
            {
                ListaEntradas.Add(new Bitmap[1]);
                ListaCarz.Add(new double[6][]);
            }


            string[] rutasInternas = Directory.GetDirectories("Piesas/");
            for (int i = 0; i < rutasInternas.Length; i++)
            {
                string        ruta      = rutasInternas[i];
                string[]      rutaSgmnt = ruta.Split('/');
                int           indx      = Array.IndexOf(nombres.ToArray(), rutaSgmnt[1]);
                DirectoryInfo infDir    = new DirectoryInfo(ruta);
                FileInfo[]    infFile   = infDir.GetFiles("*.jpeg", SearchOption.AllDirectories);
                Bitmap[]      imgArr    = new Bitmap[infFile.Length];
                double[][]    carArr    = new double[infFile.Length][];
                carTota += infFile.Length;

                for (int j = 0; j < imgArr.Length; j++)
                {
                    imgArr[j] = (Bitmap)Image.FromFile(infFile[j].FullName);
                    carArr[j] = PictureAnalizer.CalcularCaracteristicasTextura(imgArr[j]);
                }

                ListaEntradas[indx] = imgArr;
                ListaCarz[indx]     = carArr;
            }

            double[][] lSalidas = new double[(int)carTota][];

            // { "Vacio", "Torres", "Caballos","Alfiles", "Reinas", "Reyes", "Peones" };


            int c = 2;

            double[][] MatEntr = new double[(int)carTota][];
            int        t       = 0;
            int        pi      = 0;

            foreach (double[][] Mat in ListaCarz)
            {
                foreach (double[] vector in Mat)
                {
                    MatEntr[t] = vector;

                    switch (pi)
                    {
                    case 0: lSalidas[t] = new double[] { 0, 0, 0, 0 }; break;

                    case 1: lSalidas[t] = new double[] { 0, 0, 0, 1 }; break;

                    case 2: lSalidas[t] = new double[] { 0, 0, 1, 0 }; break;

                    case 3: lSalidas[t] = new double[] { 0, 0, 1, 1 }; break;

                    case 4: lSalidas[t] = new double[] { 0, 1, 0, 0 }; break;

                    case 5: lSalidas[t] = new double[] { 0, 1, 0, 1 }; break;

                    case 6: lSalidas[t] = new double[] { 0, 1, 1, 0 }; break;
                    }

                    t++;
                }
                pi++;
            }

            ActivationNetwork rna = null;

            if (!Directory.Exists("rnsa.rna"))
            {
                rna = CrearRNA(MatEntr, lSalidas);
                rna.Save("rnsa.rna");
            }
            else
            {
                rna = (ActivationNetwork)Network.Load("rnsa.rna");
            }

            Bitmap [] ns = ListaEntradas[0];
            foreach (Bitmap x in ns)
            {
                double [] text = rna.Compute(PictureAnalizer.CalcularCaracteristicasTextura(x));



                int l = 0;
                for (int f = 0; f < text.Length; f++)
                {
                    if (text[f] == 1)
                    {
                        l += (int)Math.Pow(2, f);
                    }
                }
                Console.Write(l + " ");
            }



            // generar arbol
            nodo r = new nodo(8, "s");

            arbol a1 = new arbol();

            r.tablero = a1.TabEjemplo;
            a1.raiz   = r;

            arbol a2 = new arbol();

            r.tablero = a2.TabEjemplo;
            a2.raiz   = r;
            imprimirTablero(r);

            nodo n1 = a1.generarMovimientos(a1.raiz, arbol.ColorBlanco);

            imprimirTablero(n1);


            for (int i = 0; i < 10; i++)
            {
                n1 = a1.generarMovimientos(n1, arbol.ColorBlanco);
                imprimirTablero(n1);

                nodo n2 = a2.generarMovimientos(n1, arbol.ColorNegroo);
                imprimirTablero(n2);

                n1 = n2;
            }
        }