Пример #1
0
        private void ExzamenSys()
        {
            int[]          counterError = new int[11];//for err
            List <Vectors> vct          = new List <Vectors>();

            vct = MyCopyTo(VectorsImage);//изображения там
            List <Vectors> newMassiveEtalons = new List <Vectors>();

            newMassiveEtalons = MyCopyTo(massiveEtalons);//массивы здесь
            Random rn = new Random();

            Bar_prog.Invoke(new Action(() => { Bar_prog.Maximum = vct.Count; }));
            while (true)
            {
                int indexRandomImage = rn.Next(vct.Count);
                while (true)
                {
                    List <int> d = new List <int>();
                    searchD2(vct, newMassiveEtalons, indexRandomImage, d);
                    int ind = d.IndexOf(d.Min());
                    if (newMassiveEtalons[ind].ClassImage == vct[indexRandomImage].ClassImage)//etalonVector
                    {
                        vct.RemoveAt(indexRandomImage);
                        massiveEtalons[massiveEtalons.IndexOf(newMassiveEtalons[ind])].recog++;//считаем верно распознаные
                        newMassiveEtalons = MyCopyTo(massiveEtalons);
                        break;
                    }
                    else
                    {
                        counterError[newMassiveEtalons[ind].ClassImage]++;
                        newMassiveEtalons.RemoveAt(ind);
                        Bar_prog.Invoke(new Action(() => { Bar_prog.Value = Bar_prog.Maximum - vct.Count; }));
                        if (vct.Count == 0)
                        {
                            break;
                        }
                    }
                }
                if (vct.Count == 0)
                {
                    break;
                }
            }

            List <int[]> countRecog = new List <int[]>();

            foreach (var item in massiveEtalons)
            {
                countRecog.Add(new int[] { item.recog, item.ClassImage });
            }
            this.Invoke(new Action(() => { SaveClassEtalon(counterError, countRecog); }));
            Bar_prog.Invoke(new Action(() => { Bar_prog.Value = Bar_prog.Maximum; }));
        }
Пример #2
0
        private void searchEtalon()
        {
            Random         rn  = new Random();
            List <Vectors> vct = new List <Vectors>();

            vct = MyCopyTo(VectorsImage);
            Bar_prog.Invoke(new Action(() => { Bar_prog.Maximum = vct.Count; }));
            while (true)
            {
                int etalon      = rn.Next(vct.Count);
                int countEtalon = 0;

                while (true)
                {
                    List <int> d = new List <int>();
                    searchD(vct, vct, etalon - countEtalon, d);
                    int index = d.IndexOf((from x in d where x > 0 select x).Min());
                    if (vct[index].ClassImage == vct[etalon - countEtalon].ClassImage)//etalonVector
                    {
                        vct.RemoveAt(index);
                        if (index < etalon - countEtalon)
                        {
                            countEtalon++;
                        }
                    }
                    else
                    {
                        massiveEtalons.Add(vct[etalon - countEtalon]);
                        vct.RemoveAt(etalon - countEtalon);
                        countEtalon = 0;
                        break;
                    }
                    Bar_prog.Invoke(new Action(() => { Bar_prog.Value = Bar_prog.Maximum - vct.Count; }));
                    if (vct.Count == 1)
                    {
                        massiveEtalons.Add(vct[0]);
                        break;
                    }
                }
                if (vct.Count == 1)
                {
                    break;
                }
            }
            Bar_prog.Invoke(new Action(() => { Bar_prog.Value = Bar_prog.Maximum; }));
        }
Пример #3
0
 private void loader(object fileName)
 {
     try
     {
         int count = File.ReadAllLines(fileName.ToString()).Length;
         Bar_prog.Invoke(new Action(() => { Bar_prog.Maximum = count; }));
         using (StreamReader SR = new StreamReader(fileName.ToString()))
         {
             VectorsImage = new List <Vectors>();
             while (!SR.EndOfStream)
             {
                 string[] str    = SR.ReadLine().Split(';');
                 Vectors  vector = new Vectors();
                 vector.CounterWay           = new int[8];
                 vector.CounterAngle         = new int[3];
                 vector.CountPointsImage     = int.Parse(str[0]);
                 vector.CounterPointsContour = int.Parse(str[1]);
                 vector.CounterWay[0]        = int.Parse(str[2]);
                 vector.CounterWay[1]        = int.Parse(str[3]);
                 vector.CounterWay[2]        = int.Parse(str[4]);
                 vector.CounterWay[3]        = int.Parse(str[5]);
                 vector.CounterWay[4]        = int.Parse(str[6]);
                 vector.CounterWay[5]        = int.Parse(str[7]);
                 vector.CounterWay[6]        = int.Parse(str[8]);
                 vector.CounterWay[7]        = int.Parse(str[9]);
                 vector.CounterLength        = int.Parse(str[10]);
                 vector.CounterAngle[0]      = int.Parse(str[11]);
                 vector.CounterAngle[1]      = int.Parse(str[12]);
                 vector.CounterAngle[2]      = int.Parse(str[13]);
                 vector.ClassImage           = int.Parse(str[14]);
                 VectorsImage.Add(vector);
                 Bar_prog.Invoke(new Action(() => { Bar_prog.Value++; }));
             }
         }
     }
     catch (Exception ex)
     { MessageBox.Show("Не удалось загрузить!\r\n" + ex); }
 }
Пример #4
0
        private void ImageAnaliz(object path1)
        {
            string path = path1.ToString();

            if (path != String.Empty)
            {
                string[]        pathFiles       = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories);
                AttributeSearch attributeSearch = new AttributeSearch();
                Bar_prog.Invoke(new Action(() => { Bar_prog.Maximum = pathFiles.Length; }));
                using (StreamWriter SW = new StreamWriter(path + @"\FilesInfo.txt", false))
                {
                    for (int i = 0; i < pathFiles.Length; i++)
                    {
                        Bitmap  image  = new Bitmap(pathFiles[i]);
                        Vectors vector = new Vectors();
                        vector.ListPointsImage      = attributeSearch.ListPointsImage(image);
                        vector.CountPointsImage     = attributeSearch.CounterPoints(image);
                        vector.CounterPointsContour = attributeSearch.CounterPointsContour(vector.ListPointsImage);
                        vector.CounterWay           = attributeSearch.CounterWay(vector.ListPointsImage);
                        vector.CounterLength        = attributeSearch.CounterLength(vector.CounterWay);
                        vector.CounterAngle         = attributeSearch.CounterAngle(vector.ListPointsImage);
                        string temp = pathFiles[i].Remove(0, path.Length + 1);
                        if (temp.StartsWith("10"))
                        {
                            vector.ClassImage = 10;
                        }
                        else if (temp.StartsWith("2"))
                        {
                            vector.ClassImage = 2;
                        }
                        else if (temp.StartsWith("3"))
                        {
                            vector.ClassImage = 3;
                        }
                        else if (temp.StartsWith("4"))
                        {
                            vector.ClassImage = 4;
                        }
                        else if (temp.StartsWith("5"))
                        {
                            vector.ClassImage = 5;
                        }
                        else if (temp.StartsWith("6"))
                        {
                            vector.ClassImage = 6;
                        }
                        else if (temp.StartsWith("7"))
                        {
                            vector.ClassImage = 7;
                        }
                        else if (temp.StartsWith("8"))
                        {
                            vector.ClassImage = 8;
                        }
                        else if (temp.StartsWith("9"))
                        {
                            vector.ClassImage = 9;
                        }
                        else if (temp.StartsWith("1"))
                        {
                            vector.ClassImage = 1;
                        }
                        SW.WriteLine(
                            +vector.CountPointsImage + ";"
                            + vector.CounterPointsContour + ";"
                            + vector.CounterWay[0] + ";"
                            + vector.CounterWay[1] + ";"
                            + vector.CounterWay[2] + ";"
                            + vector.CounterWay[3] + ";"
                            + vector.CounterWay[4] + ";"
                            + vector.CounterWay[5] + ";"
                            + vector.CounterWay[6] + ";"
                            + vector.CounterWay[7] + ";"
                            + vector.CounterLength + ";"
                            + vector.CounterAngle[0] + ";"
                            + vector.CounterAngle[1] + ";"
                            + vector.CounterAngle[2] + ";"
                            + vector.ClassImage
                            );
                        Bar_prog.Invoke(new Action(() => { Bar_prog.Value = i + 1; }));
                    }
                }
            }
        }