Tesseract  3.02
tesseract-ocr/wordrec/tface.cpp
Go to the documentation of this file.
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 "bestfirst.h"
00021 #include "callcpp.h"
00022 #include "chop.h"
00023 #include "chopper.h"
00024 #include "danerror.h"
00025 #include "fxdefs.h"
00026 #include "globals.h"
00027 #include "gradechop.h"
00028 #include "matchtab.h"
00029 #include "pageres.h"
00030 #include "permute.h"
00031 #include "wordclass.h"
00032 #include "wordrec.h"
00033 #include "featdefs.h"
00034 
00035 #include <math.h>
00036 #ifdef __UNIX__
00037 #include <unistd.h>
00038 #endif
00039 
00040 
00041 namespace tesseract {
00042 
00050 void Wordrec::program_editup(const char *textbase,
00051                              bool init_classifier,
00052                              bool init_dict) {
00053   if (textbase != NULL) imagefile = textbase;
00054   InitFeatureDefs(&feature_defs_);
00055   SetupExtractors(&feature_defs_);
00056   InitAdaptiveClassifier(init_classifier);
00057   if (init_dict) getDict().Load();
00058   pass2_ok_split = chop_ok_split;
00059   pass2_seg_states = wordrec_num_seg_states;
00060 }
00061 
00067 int Wordrec::end_recog() {
00068   program_editdown (0);
00069 
00070   return (0);
00071 }
00072 
00073 
00080 void Wordrec::program_editdown(inT32 elasped_time) {
00081   EndAdaptiveClassifier();
00082   blob_match_table.end_match_table();
00083   getDict().InitChoiceAccum();
00084   getDict().End();
00085 }
00086 
00087 
00093 void Wordrec::set_pass1() {
00094   chop_ok_split.set_value(70.0);
00095   wordrec_num_seg_states.set_value(15);
00096   SettupPass1();
00097 }
00098 
00099 
00105 void Wordrec::set_pass2() {
00106   chop_ok_split.set_value(pass2_ok_split);
00107   wordrec_num_seg_states.set_value(pass2_seg_states);
00108   SettupPass2();
00109 }
00110 
00111 
00117 BLOB_CHOICE_LIST_VECTOR *Wordrec::cc_recog(WERD_RES *word) {
00118   getDict().InitChoiceAccum();
00119   getDict().reset_hyphen_vars(word->word->flag(W_EOL));
00120   blob_match_table.init_match_table();
00121   BLOB_CHOICE_LIST_VECTOR *results = chop_word_main(word);
00122   getDict().DebugWordChoices();
00123   return results;
00124 }
00125 
00126 
00133 int Wordrec::dict_word(const WERD_CHOICE &word) {
00134   return getDict().valid_word(word);
00135 }
00136 
00143 BLOB_CHOICE_LIST *Wordrec::call_matcher(const DENORM* denorm, TBLOB *tessblob) {
00144   // Rotate the blob for classification if necessary.
00145   TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded(&denorm);
00146   if (rotated_blob == NULL) {
00147     rotated_blob = tessblob;
00148   }
00149   BLOB_CHOICE_LIST *ratings = new BLOB_CHOICE_LIST();  // matcher result
00150   AdaptiveClassifier(rotated_blob, *denorm, ratings, NULL);
00151   if (rotated_blob != tessblob) {
00152     delete rotated_blob;
00153     delete denorm;
00154   }
00155   return ratings;
00156 }
00157 
00158 
00159 }  // namespace tesseract