Exemplo n.º 1
0
        // Метод для сравнения файлов весов
        public String Comparer(Web obj, TextBox stats, PictureBox pic)
        {
            this.Maxcomp = -1;

            FileInfo[] bmps = obj.dir.GetFiles("*.txt");
            int[] tempcomp = new int[obj.bmpfiles.Length];
            int[] comp = new int[obj.bmpfiles.Length];

            int p = 0; // Счётчик файлов
            foreach (FileInfo f in bmps) // Перебор файлов весов изображений-образцов
            {
                string[] readf = File.ReadAllLines(f.FullName);
                string[] readi = File.ReadAllLines("Target.txt");

                int iterationQuantity = readf.Length < readi.Length // Минимальное число строк
                                       ? readf.Length
                                       : readi.Length;
                for (int i = 0; i < iterationQuantity; i++)
                {
                    int localQuantity = readf[i].Length < readi[i].Length // Минимальное число столбцов
                                           ? readf[i].Length
                                           : readi[i].Length;

                    for (int j = 0; j < localQuantity; j++)
                    {
                        if (((readf[i][j] == readi[i][j]) && (readi[i][j] != ' ')) && (readi[i][j] != '\n'))
                            tempcomp[p] += 1;
                    }
                }
                p++;
            }
            Array.Sort(tempcomp); // Сортировка массива совпадений по возрастанию
            int t = tempcomp.Length - 1;
            this.Maxcomp = tempcomp[t]; // Максимальным значением совпаденией будет последнее значение сортированного массива
            p = 0;

            foreach (FileInfo f in bmps)
            {
                string[] readf = File.ReadAllLines(f.FullName);
                string[] readi = File.ReadAllLines("Target.txt");

                int iterationQuantity = readf.Length < readi.Length //Минимальное число строк
                                       ? readf.Length
                                       : readi.Length;
                for (int i = 0; i < iterationQuantity; i++)
                {
                    int localQuantity = readf[i].Length < readi[i].Length//Минимальное число столбцов
                                           ? readf[i].Length
                                           : readi[i].Length;

                    for (int j = 0; j < localQuantity; j++)
                    {
                        if (((readf[i][j] == readi[i][j]) && (readi[i][j] != ' ')) && (readi[i][j] != '\n'))
                        {
                            comp[p] += 1;
                        }
                    }
                }
                if (comp[p] == tempcomp[t]) // Число совпадений для файла весов изображения-образца и выделенной области максимально
                {
                    String filename = Path.GetFileNameWithoutExtension(f.Name);
                    String bmpf = obj.dir.FullName + "\\" + filename + ".bmp";
                    pic.Image = Image.FromFile(bmpf);
                    stats.Text += Environment.NewLine + "Файл образца: " + f.Name;
                    for (int l = 0; l < iterationQuantity; l++)
                    {
                        stats.Text += Environment.NewLine + readf[l];
                    }
                    double percent = this.Maxcomp / (this.input.Height * this.input.Width);
                    stats.Text += Environment.NewLine + Environment.NewLine + "Процент совпадений: " + Convert.ToString(percent) + "%" + Environment.NewLine + Environment.NewLine + Environment.NewLine;
                    return filename;
                }
                p++;
            }
            return "Error";
        }
Exemplo n.º 2
0
        // Обработка события по нажатии на кнопку "Распознать"
        private void Comp_button_Click(object sender, EventArgs e)
        {
            String file, query;
            Web Sample = new Web(size_x, size_y); // Создание файлов весов изображений-образцов
            Web target = new Web(trimg, Stat_textBox); // Создание файлов весов выделенной области
            file = target.Comparer(Sample, Stat_textBox, signBox); // Запись имени файла распознанного изображения-образца

            query = "select distinct Sign_Name, Sign_Description, Type_Name, Type_Description " +
                    "from dbo.Main, dbo.Types, dbo.Description " +
                    "where Main.type_id=Types.type_id AND Main.id=Description.id AND File_Name = \'" + file + "\'"; // Запрос к БД
            ReadOrderData(query, Inf_textBox); // Считывание информации из БД
        }