tesseract
3.03
|
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 "fxdefs.h" 00025 #include "globals.h" 00026 #include "gradechop.h" 00027 #include "pageres.h" 00028 #include "wordrec.h" 00029 #include "featdefs.h" 00030 #include "params_model.h" 00031 00032 #include <math.h> 00033 #ifdef __UNIX__ 00034 #include <unistd.h> 00035 #endif 00036 00037 00038 namespace tesseract { 00039 00047 void Wordrec::program_editup(const char *textbase, 00048 bool init_classifier, 00049 bool init_dict) { 00050 if (textbase != NULL) imagefile = textbase; 00051 InitFeatureDefs(&feature_defs_); 00052 SetupExtractors(&feature_defs_); 00053 InitAdaptiveClassifier(init_classifier); 00054 if (init_dict) getDict().Load(Dict::GlobalDawgCache()); 00055 pass2_ok_split = chop_ok_split; 00056 } 00057 00063 int Wordrec::end_recog() { 00064 program_editdown (0); 00065 00066 return (0); 00067 } 00068 00069 00076 void Wordrec::program_editdown(inT32 elasped_time) { 00077 EndAdaptiveClassifier(); 00078 getDict().End(); 00079 } 00080 00081 00087 void Wordrec::set_pass1() { 00088 chop_ok_split.set_value(70.0); 00089 language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1); 00090 SettupPass1(); 00091 } 00092 00093 00099 void Wordrec::set_pass2() { 00100 chop_ok_split.set_value(pass2_ok_split); 00101 language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2); 00102 SettupPass2(); 00103 } 00104 00105 00111 void Wordrec::cc_recog(WERD_RES *word) { 00112 getDict().reset_hyphen_vars(word->word->flag(W_EOL)); 00113 chop_word_main(word); 00114 word->DebugWordChoices(getDict().stopper_debug_level >= 1, 00115 getDict().word_to_debug.string()); 00116 ASSERT_HOST(word->StatesAllValid()); 00117 } 00118 00119 00126 int Wordrec::dict_word(const WERD_CHOICE &word) { 00127 return getDict().valid_word(word); 00128 } 00129 00136 BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) { 00137 // Rotate the blob for classification if necessary. 00138 TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded(); 00139 if (rotated_blob == NULL) { 00140 rotated_blob = tessblob; 00141 } 00142 BLOB_CHOICE_LIST *ratings = new BLOB_CHOICE_LIST(); // matcher result 00143 AdaptiveClassifier(rotated_blob, ratings); 00144 if (rotated_blob != tessblob) { 00145 delete rotated_blob; 00146 } 00147 return ratings; 00148 } 00149 00150 00151 } // namespace tesseract