|
tesseract 3.04.01
|
00001 /********************************************************************** 00002 * File: tface.c (Formerly tface.c) 00003 * Description: C side of the Tess/tessedit C/C++ interface. 00004 * Author: Ray Smith 00005 * Created: Mon Apr 27 11:57:06 BST 1992 00006 * 00007 * (C) Copyright 1992, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #include "callcpp.h" 00021 #include "chop.h" 00022 #include "chopper.h" 00023 #include "danerror.h" 00024 #include "globals.h" 00025 #include "gradechop.h" 00026 #include "pageres.h" 00027 #include "wordrec.h" 00028 #include "featdefs.h" 00029 #include "params_model.h" 00030 00031 #include <math.h> 00032 #ifdef __UNIX__ 00033 #include <unistd.h> 00034 #endif 00035 00036 00037 namespace tesseract { 00038 00046 void Wordrec::program_editup(const char *textbase, 00047 bool init_classifier, 00048 bool init_dict) { 00049 if (textbase != NULL) imagefile = textbase; 00050 InitFeatureDefs(&feature_defs_); 00051 InitAdaptiveClassifier(init_classifier); 00052 if (init_dict) getDict().Load(Dict::GlobalDawgCache()); 00053 pass2_ok_split = chop_ok_split; 00054 } 00055 00061 int Wordrec::end_recog() { 00062 program_editdown (0); 00063 00064 return (0); 00065 } 00066 00067 00074 void Wordrec::program_editdown(inT32 elasped_time) { 00075 EndAdaptiveClassifier(); 00076 getDict().End(); 00077 } 00078 00079 00085 void Wordrec::set_pass1() { 00086 chop_ok_split.set_value(70.0); 00087 language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1); 00088 SettupPass1(); 00089 } 00090 00091 00097 void Wordrec::set_pass2() { 00098 chop_ok_split.set_value(pass2_ok_split); 00099 language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2); 00100 SettupPass2(); 00101 } 00102 00103 00109 void Wordrec::cc_recog(WERD_RES *word) { 00110 getDict().reset_hyphen_vars(word->word->flag(W_EOL)); 00111 chop_word_main(word); 00112 word->DebugWordChoices(getDict().stopper_debug_level >= 1, 00113 getDict().word_to_debug.string()); 00114 ASSERT_HOST(word->StatesAllValid()); 00115 } 00116 00117 00124 int Wordrec::dict_word(const WERD_CHOICE &word) { 00125 return getDict().valid_word(word); 00126 } 00127 00134 BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) { 00135 // Rotate the blob for classification if necessary. 00136 TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded(); 00137 if (rotated_blob == NULL) { 00138 rotated_blob = tessblob; 00139 } 00140 BLOB_CHOICE_LIST *ratings = new BLOB_CHOICE_LIST(); // matcher result 00141 AdaptiveClassifier(rotated_blob, ratings); 00142 if (rotated_blob != tessblob) { 00143 delete rotated_blob; 00144 } 00145 return ratings; 00146 } 00147 00148 00149 } // namespace tesseract