⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 training.cpp

📁 Ocr source code. provides an Ocr engine that works in C++ language.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
     else if(tool_selection == 2) {                    *tool_split_chars = true;          *tool_join_letters = false;          *tool_rm_spots = false;     }}void training_window::on_tools_action_button_click() {     if(*tool_join_letters) {               if(selected_chars->size() <= 1) {               selected_chars->clear();               *tool_join_letters = false;               signals.do_tr_refresh();               return;          }                    // error checking:          box_t big_box = find_biggest_box(                                  (*selected_chars)[0].pc->self_node.self_box,                                   (*selected_chars)[1].pc->self_node.self_box);          for(int i = 2; i < selected_chars->size(); i++)               big_box = find_biggest_box(big_box,                                   (*selected_chars)[i].pc->self_node.self_box);          if(!fits_in_box((*selected_chars)[0].pl->self_node.self_box,big_box)){               popup_message(*this, "The characters are out of the line box.");               selected_chars->clear();               *tool_join_letters = false;               signals.do_tr_refresh();               return;          }          int rmost_index = 0, lmost_index = 0;          for(int i = 1; i < selected_chars->size(); i++) {               if((*selected_chars)[i].pc->self_node.self_box.xy.x <                  (*selected_chars)[lmost_index].pc->self_node.self_box.xy.x)                    lmost_index = i;               if((*selected_chars)[i].pc->self_node.self_box.xy.x >                  (*selected_chars)[rmost_index].pc->self_node.self_box.xy.x)                    rmost_index = i;          }          char_node node;          node.self_box = big_box;          node.is_space = false;          parsed_char *new_node = new parsed_char(node);                              new_node->prev = (*selected_chars)[lmost_index].pc->prev;          if((*selected_chars)[lmost_index].pc->prev != NULL)               (*selected_chars)[lmost_index].pc->prev->next = new_node;          new_node->next = (*selected_chars)[rmost_index].pc->next;          if((*selected_chars)[rmost_index].pc->next != NULL)               (*selected_chars)[rmost_index].pc->next->prev = new_node;                   // reset pc_begin, pc_end:          if(new_node->prev == NULL)               (*selected_chars)[0].pl->pc_begin = new_node;          if(new_node->next == NULL)               (*selected_chars)[0].pl->pc_end = new_node;                    for(int k = 0; k < selected_chars->size(); k++)               delete (*selected_chars)[k].pc;          remap_characters(tr_parse_list, image_text.get_text());          selected_chars->clear();          *tool_join_letters = false;          signals.do_tr_refresh();               }     else if(*tool_rm_spots) {          parsed_char *cur_pc;          for(int i = 0; i < selected_chars->size(); i++) {                         cur_pc = (*selected_chars)[i].pc;               if(cur_pc->prev != NULL)                    cur_pc->prev->next = cur_pc->next;               if(cur_pc->next != NULL)                    cur_pc->next->prev = cur_pc->prev;                              // reset pc_begin, pc_end:               if(cur_pc->prev == NULL)                    (*selected_chars)[i].pl->pc_begin = cur_pc->next;               if(cur_pc->next == NULL)                    (*selected_chars)[i].pl->pc_end = cur_pc->prev;                              delete cur_pc;          }          remap_characters(tr_parse_list, image_text.get_text());          selected_chars->clear();          *tool_rm_spots = false;          signals.do_tr_refresh();     }     else if(*tool_split_chars) {          int x;          box_t sel_char_box, char_node_box;          char_node first_char_node, second_char_node;          first_char_node.is_space = second_char_node.is_space = false;          parsed_char *first_char, *second_char, *orig_char;          for(int i = 0; i < selected_chars->size(); i++) {                              x = (*tool_split_chars_divider_pos)[i];               sel_char_box = (*selected_chars)[i].pc->self_node.self_box;                              if((x == sel_char_box.xy.x) ||                   (x == (sel_char_box.xy.x + sel_char_box.horiz_len - 1)))                    continue;                              // first char:               char_node_box.xy = sel_char_box.xy;               char_node_box.horiz_len = x - sel_char_box.xy.x;               char_node_box.vert_len = sel_char_box.vert_len;               first_char_node.self_box = char_node_box;               first_char = new parsed_char(first_char_node);               // second char:               char_node_box.xy.x = x;               char_node_box.xy.y = sel_char_box.xy.y;               char_node_box.horiz_len = sel_char_box.xy.x +                                          sel_char_box.horiz_len - x;               char_node_box.vert_len = sel_char_box.vert_len;               second_char_node.self_box = char_node_box;               second_char = new parsed_char(second_char_node);               orig_char = (*selected_chars)[i].pc;               if(orig_char->prev == NULL)                    (*selected_chars)[i].pl->pc_begin = first_char;               if(orig_char->next == NULL)                    (*selected_chars)[i].pl->pc_end = second_char;               if(orig_char->prev != NULL)                    orig_char->prev->next = first_char;               first_char->prev = orig_char->prev;               first_char->next = second_char;               second_char->prev = first_char;               if(orig_char->next != NULL)                    orig_char->next->prev = second_char;               second_char->next = orig_char->next;               delete orig_char;          } // for i          remap_characters(tr_parse_list, image_text.get_text());                              selected_chars->clear();          tool_split_chars_divider_pos->clear();          *tool_split_chars = false;          signals.do_tr_refresh();               }         }void training_window::on_tools_clear_selected_click() {     selected_chars->clear();     tool_split_chars_divider_pos->clear();     signals.do_tr_refresh();}void training_window::on_tools_search_alternate_click() {     *tools_search_alternate = tools_search_alternate_checkbutton.get_active();}/////// grid configuration:grid_cfg_da::grid_cfg_da() : grid_char_da() {     signals.signal_grid_cfg_new_letter().connect(sigc::mem_fun(*this,                                         &grid_cfg_da::on_new_grid_cfg_letter));}// place a scrolling window around the drawing area:grid_config_display::grid_config_display() {          set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);     //set_size_request(trcfg_grid_size_x, trcfg_grid_size_y);     add(da);          show_all_children();}void grid_config_display::set_size(int size_x, int size_y) {     set_size_request(size_x, size_y);}// the main dialog that will pop up:grid_config_dialog::grid_config_dialog() : plus_char_button("[+] char"),     minus_char_button("[-] char"), add_to_config_button("Add to config"),     grid_fill_label("show grid fill    "), close_button("Close"),     gs_x_label("grid size x:     "), gs_y_label("grid size y:     "),     gc_x_label("grid cell size x:  "), gc_y_label("grid cell size y:  "),     gs_update_button("Update"), gc_update_button("Update") {     set_title("Gridding Configuration");     get_vbox()->set_spacing(15);     cur_pl = NULL;     cur_pc = NULL;          if((tr_parse_list == NULL) || (tr_parse_list->pl_begin == NULL) ||         (tr_parse_list->pl_begin->pc_begin == NULL)) {                    gs_x = trcfg_grid_size_x;          gs_y = trcfg_grid_size_y;          gc_x = trcfg_gridcell_size_x;          gc_y = trcfg_gridcell_size_y;          cur_char_box = NULL_BOX();               }     else {                    cur_char_box = find_biggest_char_box_hlen(tr_parse_list);          gs_x = cur_char_box.horiz_len;          cur_char_box = find_biggest_char_box_vlen(tr_parse_list);          gs_y = cur_char_box.vert_len;          gc_x = gs_x / 10;          gc_y = gs_y / 10;          if((gs_x % gc_x) != 0)               gs_x = gs_x + (gc_x - (gs_x % gc_x));          if((gs_y % gc_y) != 0)               gs_y = gs_y + (gc_y - (gs_y % gc_y));     }          // grid display:     display.set_size(gs_x, gs_y);     get_vbox()->add(display);     display.da.set_grid_params(gs_x, gs_y, gc_x, gc_y);     signals.do_grid_cfg_new_letter(cur_char_box);          // ctrl set of buttons:     ctrl_buttonbox.pack_start(minus_char_button, Gtk::PACK_SHRINK);     ctrl_buttonbox.pack_start(plus_char_button, Gtk::PACK_SHRINK);     ctrl_buttonbox.pack_start(add_to_config_button, Gtk::PACK_SHRINK);     ctrl_buttonbox.set_layout(Gtk::BUTTONBOX_SPREAD);     ctrl_buttonbox.set_spacing(10);     //ctrl_hbox.set_spacing(10);     ctrl_hbox.pack_start(ctrl_buttonbox, Gtk::PACK_SHRINK);     ctrl_hbox.pack_start(grid_fill_check);     ctrl_hbox.pack_start(grid_fill_label);     get_vbox()->add(ctrl_hbox);          // grid size:     gs_x_entry.set_text(int_to_string(gs_x));     gs_x_entry.set_width_chars(GRID_CFG_ENTRY_SIZE);     gs_y_entry.set_text(int_to_string(gs_y));     gs_y_entry.set_width_chars(GRID_CFG_ENTRY_SIZE);          gs_x_hbox.pack_start(gs_x_label, Gtk::PACK_SHRINK);     gs_x_hbox.pack_start(gs_x_entry, Gtk::PACK_SHRINK);     gs_y_hbox.pack_start(gs_y_label, Gtk::PACK_SHRINK);     gs_y_hbox.pack_start(gs_y_entry, Gtk::PACK_SHRINK);     gs_vbox.pack_start(gs_x_hbox, Gtk::PACK_SHRINK);     gs_vbox.pack_start(gs_y_hbox, Gtk::PACK_SHRINK);     gs_update_buttonbox.pack_end(gs_update_button);     gs_update_buttonbox.set_layout(Gtk::BUTTONBOX_START);     gs_vbox.pack_start(gs_update_buttonbox);          // grid cell:     gc_x_entry.set_text(int_to_string(gc_x));     gc_x_entry.set_width_chars(GRID_CFG_ENTRY_SIZE);     gc_y_entry.set_text(int_to_string(gc_y));     gc_y_entry.set_width_chars(GRID_CFG_ENTRY_SIZE);          gc_x_hbox.pack_start(gc_x_label, Gtk::PACK_SHRINK);     gc_x_hbox.pack_start(gc_x_entry, Gtk::PACK_SHRINK);     gc_y_hbox.pack_start(gc_y_label, Gtk::PACK_SHRINK);     gc_y_hbox.pack_start(gc_y_entry, Gtk::PACK_SHRINK);     gc_vbox.pack_start(gc_x_hbox, Gtk::PACK_SHRINK);     gc_vbox.pack_start(gc_y_hbox, Gtk::PACK_SHRINK);     gc_update_buttonbox.pack_end(gc_update_button);     gc_update_buttonbox.set_layout(Gtk::BUTTONBOX_START);     gc_vbox.pack_start(gc_update_buttonbox);          grid_sections_hbox.pack_start(gs_vbox);     grid_sections_hbox.pack_start(gc_vbox);     grid_sections_hbox.set_spacing(10);     get_vbox()->add(grid_sections_hbox);     get_vbox()->add(line);          close_buttonbox.pack_end(close_button);     close_buttonbox.set_layout(Gtk::BUTTONBOX_END);     close_buttonbox.set_spacing(15);     get_vbox()->add(close_buttonbox);     // signal handlers:     plus_char_button.signal_clicked().connect(sigc::mem_fun(*this,                                 &grid_config_dialog::on_plus_char_click));     minus_char_button.signal_clicked().connect(sigc::mem_fun(*this,                                 &grid_config_dialog::on_minus_char_click));     add_to_config_button.signal_clicked().connect(sigc::mem_fun(*this,                                  &grid_config_dialog::on_add_to_config_click));     grid_fill_check.signal_toggled().connect(sigc::mem_fun(*this,                                 &grid_config_dialog::on_grid_fill_toggle));     gs_update_button.signal_clicked().connect(sigc::mem_fun(*this,                                  &grid_config_dialog::on_gs_update));     gc_update_button.signal_clicked().connect(sigc::mem_fun(*this,                                  &grid_config_dialog::on_gc_update));     close_button.signal_clicked().connect(sigc::mem_fun(*this,                                  &grid_config_dialog::on_close_button_click));     show_all_children();}void grid_config_dialog::on_plus_char_click() {     if((tr_parse_list->pl_begin == NULL) ||         (tr_parse_list->pl_begin->pc_begin == NULL))          return;          if((cur_pl == NULL) || (cur_pc == tr_parse_list->pl_end->pc_end)) {                    cur_pl = tr_parse_list->pl_begin;          cur_pc = cur_pl->pc_begin;     }     else if(cur_pc == cur_pl->pc_end) {          cur_pl = cur_pl->next;          cur_pc = cur_pl->pc_begin;     }     else          cur_pc = cur_pc->next;          cur_char_box = cur_pc->self_node.self_box;     signals.do_grid_cfg_new_letter(cur_char_box);     display.da.refresh();}void grid_config_dialog::on_minus_char_click() {     if((tr_parse_list->pl_end == NULL) ||         (tr_parse_list->pl_end->pc_end == NULL))          return;          if((cur_pl == NULL) || (cur_pc == tr_parse_list->pl_begin->pc_begin)) {                    cur_pl = tr_parse_list->pl_end;          cur_pc = cur_pl->pc_end;     }     else if(cur_pc == cur_pl->pc_begin) {          cur_pl = cur_pl->prev;          cur_pc = cur_pl->pc_end;     }     else          cur_pc = cur_pc->prev;          cur_char_box = cur_pc->self_node.self_box;     signals.do_grid_cfg_new_letter(cur_char_box);     display.da.refresh();}void grid_config_dialog::on_add_to_config_click() {     if((tr_profile != NULL) && ((gs_x != trcfg_grid_size_x) ||         (gs_y != trcfg_grid_size_y) || (gc_x != trcfg_gridcell_size_x) ||        (gc_y != trcfg_gridcell_size_y))) {          popup_message(*this, "The grid(cell) sizes changed are not consistent with the current training profile. Try clearing the profile first.");          return;     }          trcfg_grid_size_x = gs_x;     trcfg_grid_size_y = gs_y;     trcfg_gridcell_size_x = gc_x;     trcfg_gridcell_size_y = gc_y;     write_config_file(CONFIG_FILE_PATH);}void grid_config_dialog::on_grid_fill_toggle() {     if(grid_fill_check.get_active())          display.da.set_grid_draw_fill(true);     else          display.da.set_grid_draw_fill(false);     display.da.refresh();}// to get grid correctly these will change the vars so that:// ((gs_x % gc_x) = 0) and ((gs_y % gc_y) = 0):void grid_config_dialog::on_gs_update() {     int gsx = atoi(gs_x_entry.get_text().c_str());     int gsy = atoi(gs_y_entry.get_text().c_str());     if((gsx < 0) || (gsy < 0))          return;          // change keeping grid cell values the same:     if((gsx % gc_x) != 0)          gsx = gsx + (gc_x - (gsx % gc_x));     if((gsy % gc_y) != 0)          gsy = gsy + (gc_y - (gsy % gc_y));     gs_x = gsx;     gs_y = gsy;     gs_x_entry.set_text(int_to_string(gs_x));     gs_y_entry.set_text(int_to_string(gs_y));     display.da.set_grid_params(gs_x, gs_y, gc_x, gc_y);     display.da.refresh();}void grid_config_dialog::on_gc_update() {     int gcx = atoi(gc_x_entry.get_text().c_str());     int gcy = atoi(gc_y_entry.get_text().c_str());     if((gcx < 0) || (gcy < 0))          return;          // change keeping grid cell values the same:     if((gs_x % gcx) != 0)          gs_x = gs_x + (gcx - (gs_x % gcx));     if((gs_y % gcy) != 0)          gs_y = gs_y + (gcy - (gs_y % gcy));     gc_x = gcx;     gc_y = gcy;     gs_x_entry.set_text(int_to_string(gs_x));     gs_y_entry.set_text(int_to_string(gs_y));     display.da.set_grid_params(gs_x, gs_y, gc_x, gc_y);     display.da.refresh();}void grid_config_dialog::on_close_button_click() {     hide();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -