public CharRow Recognize(string the_word, List <string> arrAddLetters, Point pt_in = default(Point)) { m_bmp_template = null; m_bmp_original = null; //Graphics gr = Graphics.FromImage(bmp_menu); //listBox1.Items.Clear(); List <string> arrLetters = the_word.Select(x => new string(x, 1)).ToList(); arrLetters.AddRange(arrAddLetters); Font[] font = { new Font("Tahoma", 10), new Font(SystemFonts.MenuFont.FontFamily, 10) }; for (int ff = 0; ff < font.Length; ff++) { List <LetterBitmapTemplate> list_templ = new List <LetterBitmapTemplate>(); for (int i = 0; i < arrLetters.Count; i++) { LetterBitmapTemplate temp = new LetterBitmapTemplate(); temp.bmp = GetLetterRect(arrLetters[i], font[ff]); temp.LetterString = arrLetters[i]; list_templ.Add(temp); //temp.bmp.Save(@"F:\templ_" + arrLetters[i] + "_.bmp"); } for (int j = 0; j < chars_row.Count; j++) { string cur_word = string.Empty; CharRow row = chars_row[j]; for (int i = 0; i < row.Count; i++) { float cur_res = 0; string cur_letter = string.Empty; CharRect char_rect = row[i]; char_rect.m_weights.Clear(); for (int l = 0; l < list_templ.Count; l++) { Bitmap bmp_templ = list_templ[l].bmp; Rectangle rect = char_rect.m_rect; if (rect.Width <= 1 || rect.Height <= 1) { continue; } if (pt_in != Point.Empty && !rect.Contains(pt_in) ) { continue; } Bitmap bmp_orig = GetBWRect(rect, new Rectangle(0, 0, bmp_templ.Width, bmp_templ.Height)); if (pt_in != Point.Empty) { #if DEBUG bmp_orig.Save(@"F:\orig_" + arrLetters[l] + "_.bmp"); #endif } float result = Compare(bmp_templ, bmp_orig); char_rect.m_weights[list_templ[l].LetterString] = result; if (cur_res < result) { cur_res = result; cur_letter = list_templ[l].LetterString; char_rect.LetterString = cur_letter; m_bmp_original = bmp_orig; m_bmp_template = bmp_templ; } } cur_word += cur_letter; } if (cur_word.ToLower().Contains(the_word.ToLower())) { return(row); } } } return(null); }
bool FindPrintWord(Bitmap bmp_menu_in) { Pen pen = new Pen(new SolidBrush(Color.Red)); Pen pen_green = new Pen(new SolidBrush(Color.Green)); Pen pen_yell = new Pen(new SolidBrush(Color.Yellow)); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; pen_green.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; List <string> arrAddLetters = new List <string>(); arrAddLetters.Add("Pr"); arrAddLetters.Add("ri"); arrAddLetters.Add("nt"); listBox1.Items.Clear(); Bitmap bmp_menu = null; for (int k = 0; k < 2; k++) { bmp_menu = bmp_menu_in.Clone(new Rectangle(0, 0, bmp_menu_in.Width, bmp_menu_in.Height), bmp_menu_in.PixelFormat); Graphics gr = Graphics.FromImage(bmp_menu); recogn.LoadBmp(bmp_menu, k == 1); CharRow row = recogn.Recognize("Print", arrAddLetters); gr.DrawRectangle(pen_yell, recogn.m_cut_menu_rect); for (int i = 0; i < recogn.lines.Count; i++) { gr.DrawLine(pen_green, 0, recogn.lines[i], bmp_menu.Width - 1, recogn.lines[i]); } if (row != null) { gr.DrawRectangle(pen, row.m_FullRect); gr.Flush(); pictureBox1.Image = bmp_menu; return(true); } else { string word = string.Empty; for (int i = 0; i < recogn.chars_row.Count; i++) { CharRow letters = recogn.chars_row[i]; for (int j = 0; j < letters.Count; j++) { CharRect letter = letters[j]; gr.DrawRectangle(pen, letter.m_rect); word += letter.LetterString; } listBox1.Items.Add(word); } gr.Flush(); } } //pictureBox1.Image = recogn.m_bw; pictureBox1.Image = bmp_menu; return(false); }