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

📄 tfacepp.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        delete choice_it.extract ();        tprintf ("recog_word: Deleted choice list\n");      }    }    while (word_string.length () < word_length)      word_string += " ";        //pad with blanks    assert (raw_choice != NULL);    if (tess_choice.string)      strfree(tess_choice.string);    if (tess_raw.string)      strfree(tess_raw.string);    return new WERD_CHOICE (word_string.string (),      tess_choice.rating, tess_choice.certainty,      tess_choice.permuter);  }}/********************************************************************** * split_and_recog_word * * Convert the word to tess form and pass it to the tess segmenter. * Convert the output back to editor form. **********************************************************************/WERD_CHOICE *split_and_recog_word(                           //recog one owrd                                  WERD *word,                //word to do                                  DENORM *denorm,            //de-normaliser                                  POLY_MATCHER matcher,      //matcher function                                  POLY_TESTER tester,        //tester function                                  POLY_TESTER trainer,       //trainer function                                  BOOL8 testing,             //true if answer driven                                  WERD_CHOICE *&raw_choice,  //raw result //list of blob lists                                  BLOB_CHOICE_LIST_CLIST *blob_choices,                                  WERD *&outword             //bln word output                                 ) {  //   INT32                                                      outword1_len;  //   INT32                                                      outword2_len;  WERD *first_word;              //poly copy of word  WERD *second_word;             //fabricated word  WERD *outword2;                //2nd output word  PBLOB *blob;  WERD_CHOICE *result;           //resturn value  WERD_CHOICE *result2;          //output of 2nd word  WERD_CHOICE *raw_choice2;      //raw version of 2nd  float gap;                     //blob gap  float bestgap;                 //biggest gap  PBLOB_LIST new_blobs;          //list of gathered blobs  PBLOB_IT blob_it;                                 //iterator  PBLOB_IT new_blob_it = &new_blobs;  first_word = word->poly_copy (denorm->row ()->x_height ());  blob_it.set_to_list (first_word->blob_list ());  bestgap = -MAX_INT32;  while (!blob_it.at_last ()) {    blob = blob_it.data ();                                 //gap to next    gap = blob_it.data_relative (1)->bounding_box ().left () - blob->bounding_box ().right ();    blob_it.forward ();    if (gap > bestgap) {      bestgap = gap;             //find biggest      new_blob_it = blob_it;     //save position    }  }                                 //take 2nd half  new_blobs.assign_to_sublist (&new_blob_it, &blob_it);                                 //make it a word  second_word = new WERD (&new_blobs, 1, NULL);  ASSERT_HOST (word->blob_list ()->length () ==    first_word->blob_list ()->length () +    second_word->blob_list ()->length ());  result = recog_word_recursive (first_word, denorm, matcher,    tester, trainer, testing, raw_choice,    blob_choices, outword);  delete first_word;             //done that one  result2 = recog_word_recursive (second_word, denorm, matcher,    tester, trainer, testing, raw_choice2,    blob_choices, outword2);  delete second_word;            //done that too  *result += *result2;           //combine ratings  delete result2;  *raw_choice += *raw_choice2;  delete raw_choice2;            //finished with it  //   outword1_len= outword->blob_list()->length();  //   outword2_len= outword2->blob_list()->length();  outword->join_on (outword2);   //join words  delete outword2;  //   if ( outword->blob_list()->length() != outword1_len + outword2_len )  //      tprintf( "Split&Recog: part1len=%d; part2len=%d; combinedlen=%d\n",  //                                outword1_len, outword2_len, outword->blob_list()->length() );  //   ASSERT_HOST( outword->blob_list()->length() == outword1_len + outword2_len );  return result;}/********************************************************************** * call_matcher * * Called from Tess with a blob in tess form. * Convert the blob to editor form. * Call the matcher setup by the segmenter in tess_matcher. * Convert the output choices back to tess form. **********************************************************************/LIST call_matcher(                  //call a matcher                  TBLOB *ptblob,    //previous                  TBLOB *tessblob,  //blob to match                  TBLOB *ntblob,    //next                  void *,           //unused parameter                  TEXTROW *         //always null anyway                 ) {  PBLOB *pblob;                  //converted blob  PBLOB *blob;                   //converted blob  PBLOB *nblob;                  //converted blob  LIST result;                   //tess output  BLOB_CHOICE *choice;           //current choice  char string[2];                //char converted  BLOB_CHOICE_LIST ratings;      //matcher result  BLOB_CHOICE_IT it;             //iterator  blob = make_ed_blob (tessblob);//convert blob  if (blob == NULL)    return NULL;                 //can't do it  pblob = ptblob != NULL ? make_ed_blob (ptblob) : NULL;  nblob = ntblob != NULL ? make_ed_blob (ntblob) : NULL;  (*tess_matcher) (pblob, blob, nblob, tess_word, tess_denorm, ratings);  //match it  delete blob;                   //don't need that now  if (pblob != NULL)    delete pblob;  if (nblob != NULL)    delete nblob;  it.set_to_list (&ratings);     //get list  result = NULL;  string[1] = '\0';  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {    choice = it.data ();    string[0] = choice->char_class ();    result = append_choice (result, string,      choice->rating (), choice->certainty (),      choice->config ());  }  return result;                 //converted list}/********************************************************************** * call_tester * * Called from Tess with a blob in tess form. * Convert the blob to editor form. * Call the tester setup by the segmenter in tess_tester. **********************************************************************/void call_tester(                     //call a tester                 TBLOB *tessblob,     //blob to test                 BOOL8 correct_blob,  //true if good                 char *text,          //source text                 INT32 count,         //chars in text                 LIST result          //output of matcher                ) {  PBLOB *blob;                   //converted blob  BLOB_CHOICE_LIST ratings;      //matcher result  blob = make_ed_blob (tessblob);//convert blob  if (blob == NULL)    return;                                 //make it right type  convert_choice_list(result, ratings);  if (tess_tester != NULL)    (*tess_tester) (blob, tess_denorm, correct_blob, text, count, &ratings);  delete blob;                   //don't need that now}/********************************************************************** * call_train_tester * * Called from Tess with a blob in tess form. * Convert the blob to editor form. * Call the trainer setup by the segmenter in tess_trainer. **********************************************************************/void call_train_tester(                     //call a tester                       TBLOB *tessblob,     //blob to test                       BOOL8 correct_blob,  //true if good                       char *text,          //source text                       INT32 count,         //chars in text                       LIST result          //output of matcher                      ) {  PBLOB *blob;                   //converted blob  BLOB_CHOICE_LIST ratings;      //matcher result  blob = make_ed_blob (tessblob);//convert blob  if (blob == NULL)    return;                                 //make it right type  convert_choice_list(result, ratings);  if (tess_trainer != NULL)    (*tess_trainer) (blob, tess_denorm, correct_blob, text, count, &ratings);  delete blob;                   //don't need that now}

⌨️ 快捷键说明

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