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

📄 tfacepp.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/********************************************************************** * File:        tfacepp.cpp  (Formerly tface++.c) * Description: C++ side of the C/C++ Tess/Editor interface. * Author:					Ray Smith * Created:					Thu Apr 23 15:39:23 BST 1992 * * (C) Copyright 1992, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. * **********************************************************************/#include "mfcpch.h"#ifdef __UNIX__#include          <assert.h>#endif#include          "errcode.h"#include          "tessarray.h"//#include                                                      "fxtop.h"#include          "werd.h"#include          "tfacep.h"#include          "tstruct.h"#include          "tfacepp.h"#include          "tessvars.h"#include          "reject.h"#define EXTERNEXTERN BOOL_VAR (tessedit_override_permuter, TRUE, "According to dict_word");static POLY_MATCHER tess_matcher;//current matcherstatic POLY_TESTER tess_tester;  //current testerstatic POLY_TESTER tess_trainer; //current trainerstatic DENORM *tess_denorm;      //current denormstatic WERD *tess_word;          //current word#define MAX_UNDIVIDED_LENGTH 24/********************************************************************** * recog_word * * Convert the word to tess form and pass it to the tess segmenter. * Convert the output back to editor form. **********************************************************************/WERD_CHOICE *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                       ) {  WERD_CHOICE *word_choice;  UINT8 perm_type;  UINT8 real_dict_perm_type;  if (word->blob_list ()->empty ()) {    word_choice = new WERD_CHOICE ("", 10.0f, -1.0f, TOP_CHOICE_PERM);    raw_choice = new WERD_CHOICE ("", 10.0f, -1.0f, TOP_CHOICE_PERM);    outword = word->poly_copy (denorm->row ()->x_height ());  }  else    word_choice = recog_word_recursive (word, denorm, matcher, tester,      trainer, testing, raw_choice,      blob_choices, outword);  if ((word_choice->string ().length () !=    outword->blob_list ()->length ()) ||  (word_choice->string ().length () != blob_choices->length ())) {    tprintf      ("recog_word ASSERT FAIL String:\"%s\"; Strlen=%d; #Blobs=%d; #Choices=%d\n",      word_choice->string ().string (), word_choice->string ().length (),      outword->blob_list ()->length (), blob_choices->length ());  }  ASSERT_HOST (word_choice->string ().length () ==    outword->blob_list ()->length ());  ASSERT_HOST (word_choice->string ().length () == blob_choices->length ());  /* Copy any reject blobs into the outword */  outword->rej_blob_list ()->deep_copy (word->rej_blob_list ());  if (tessedit_override_permuter) {    /* Override the permuter type if a straight dictionary check disagrees. */    perm_type = word_choice->permuter ();    if ((perm_type != SYSTEM_DAWG_PERM) &&    (perm_type != FREQ_DAWG_PERM) && (perm_type != USER_DAWG_PERM)) {      real_dict_perm_type = dict_word (word_choice->string ().string ());      if (((real_dict_perm_type == SYSTEM_DAWG_PERM) ||        (real_dict_perm_type == FREQ_DAWG_PERM) ||        (real_dict_perm_type == USER_DAWG_PERM)) &&        (alpha_count (word_choice->string ().string ()) > 0))        word_choice->set_permuter (real_dict_perm_type);      //Use dict perm    }    if (tessedit_rejection_debug && perm_type != word_choice->permuter ()) {      tprintf ("Permuter Type Flipped from %d to %d\n",        perm_type, word_choice->permuter ());    }  }  assert ((word_choice == NULL) == (raw_choice == NULL));  return word_choice;}/********************************************************************** * recog_word_recursive * * Convert the word to tess form and pass it to the tess segmenter. * Convert the output back to editor form. **********************************************************************/WERD_CHOICE *recog_word_recursive(                           //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 initial_blob_choice_len;  INT32 word_length;             //no of blobs  STRING word_string;            //converted from tess  ARRAY tess_ratings;            //tess results  A_CHOICE tess_choice;          //best word  A_CHOICE tess_raw;             //raw result  TWERD *tessword;               //tess format  BLOB_CHOICE_LIST *choice_list; //fake list                                 //iterator  BLOB_CHOICE_LIST_C_IT choice_it;  tess_matcher = matcher;        //install matcher  tess_tester = testing ? tester : NULL;  tess_trainer = testing ? trainer : NULL;  tess_denorm = denorm;  tess_word = word;  //      blob_matchers[1]=call_matcher;  if (word->blob_list ()->length () > MAX_UNDIVIDED_LENGTH) {    return split_and_recog_word (word, denorm, matcher, tester, trainer,      testing, raw_choice, blob_choices,      outword);  }  else {    if (word->flag (W_EOL))      last_word_on_line = TRUE;    else      last_word_on_line = FALSE;    initial_blob_choice_len = blob_choices->length ();    tessword = make_tess_word (word, NULL);    tess_ratings = cc_recog (tessword, &tess_choice, &tess_raw,      testing      && tester != NULL /* ? call_tester : NULL */ ,      testing      && trainer !=      NULL /* ? call_train_tester : NULL */ );                                 //convert word    outword = make_ed_word (tessword, word);    if (outword == NULL) {      outword = word->poly_copy (denorm->row ()->x_height ());    }    delete_word(tessword);  //get rid of it                                 //no of blobs    word_length = outword->blob_list ()->length ();                                 //convert all ratings    convert_choice_lists(tess_ratings, blob_choices);                                 //copy string    word_string = tess_raw.string;    while (word_string.length () < word_length)      word_string += " ";        //pad with blanks    raw_choice = new WERD_CHOICE (word_string.string (),      tess_raw.rating, tess_raw.certainty,      tess_raw.permuter);    word_string = tess_choice.string;    if (word_string.length () > word_length) {      tprintf ("recog_word: Discarded long string \"%s\"\n",        word_string.string ());      word_string = NULL;        //should never happen    }    if (blob_choices->length () - initial_blob_choice_len != word_length) {      word_string = NULL;        //force rejection      tprintf ("recog_word: Choices list len:%d; blob lists len:%d\n",        blob_choices->length (), word_length);                                 //list of lists      choice_it.set_to_list (blob_choices);      while (blob_choices->length () - initial_blob_choice_len <      word_length) {                                 //get fake one        choice_list = new BLOB_CHOICE_LIST;                                 //add to list        choice_it.add_to_end (choice_list);        tprintf ("recog_word: Added dummy choice list\n");      }      while (blob_choices->length () - initial_blob_choice_len >      word_length) {        choice_it.move_to_last ();                                 //should never happen

⌨️ 快捷键说明

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