tesseract  4.0.0-1-g2a2b
tface.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: tface.cpp (Formerly tface.c)
3  * Description: C side of the Tess/tessedit C/C++ interface.
4  * Author: Ray Smith
5  * Created: Mon Apr 27 11:57:06 BST 1992
6  *
7  * (C) Copyright 1992, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include "callcpp.h"
21 #include "chop.h"
22 #include "chopper.h"
23 #include "globals.h"
24 #include "pageres.h"
25 #include "wordrec.h"
26 #include "featdefs.h"
27 #include "params_model.h"
28 
29 #include <cmath>
30 
31 namespace tesseract {
32 
40 void Wordrec::program_editup(const char *textbase,
41  TessdataManager *init_classifier,
42  TessdataManager *init_dict) {
43  if (textbase != nullptr) imagefile = textbase;
44 #ifndef DISABLED_LEGACY_ENGINE
46  InitAdaptiveClassifier(init_classifier);
47  if (init_dict) {
49  getDict().Load(lang, init_dict);
50  getDict().FinishLoad();
51  }
53 #endif // ndef DISABLED_LEGACY_ENGINE
54 }
55 
56 
63  program_editdown (0);
64 
65  return (0);
66 }
67 
68 
75 void Wordrec::program_editdown(int32_t elasped_time) {
76 #ifndef DISABLED_LEGACY_ENGINE
78 #endif // ndef DISABLED_LEGACY_ENGINE
79  getDict().End();
80 }
81 
82 
83 #ifndef DISABLED_LEGACY_ENGINE
84 
90  chop_ok_split.set_value(70.0);
91  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1);
92  SettupPass1();
93 }
94 
95 
102  chop_ok_split.set_value(pass2_ok_split);
103  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2);
104  SettupPass2();
105 }
106 
107 
115  chop_word_main(word);
116  word->DebugWordChoices(getDict().stopper_debug_level >= 1,
117  getDict().word_to_debug.string());
118  ASSERT_HOST(word->StatesAllValid());
119 }
120 #endif // ndef DISABLED_LEGACY_ENGINE
121 
122 
129 int Wordrec::dict_word(const WERD_CHOICE &word) {
130  return getDict().valid_word(word);
131 }
132 
133 
134 #ifndef DISABLED_LEGACY_ENGINE
135 
141 BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) {
142  // Rotate the blob for classification if necessary.
143  TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded();
144  if (rotated_blob == nullptr) {
145  rotated_blob = tessblob;
146  }
147  BLOB_CHOICE_LIST *ratings = new BLOB_CHOICE_LIST(); // matcher result
148  AdaptiveClassifier(rotated_blob, ratings);
149  if (rotated_blob != tessblob) {
150  delete rotated_blob;
151  }
152  return ratings;
153 }
154 #endif // ndef DISABLED_LEGACY_ENGINE
155 
156 } // namespace tesseract
static DawgCache * GlobalDawgCache()
Definition: dict.cpp:193
void End()
Definition: dict.cpp:343
void InitAdaptiveClassifier(TessdataManager *mgr)
Definition: adaptmatch.cpp:528
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:129
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:753
void reset_hyphen_vars(bool last_word_on_line)
Definition: hyphen.cpp:28
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:192
Definition: werd.h:35
std::unique_ptr< LanguageModel > language_model_
Definition: wordrec.h:476
bool flag(WERD_FLAGS mask) const
Definition: werd.h:126
void cc_recog(WERD_RES *word)
Definition: tface.cpp:113
void DebugWordChoices(bool debug, const char *word_to_debug)
Definition: pageres.cpp:486
void set_pass2()
Definition: tface.cpp:101
STRING lang
Definition: ccutil.h:66
void chop_word_main(WERD_RES *word)
Definition: chopper.cpp:399
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs)
Definition: featdefs.cpp:112
void program_editdown(int32_t elasped_time)
Definition: tface.cpp:75
void Load(const STRING &lang, TessdataManager *data_file)
Definition: dict.cpp:219
bool FinishLoad()
Definition: dict.cpp:323
STRING imagefile
Definition: ccutil.h:70
TBLOB * ClassifyNormalizeIfNeeded() const
Definition: blobs.cpp:356
void program_editup(const char *textbase, TessdataManager *init_classifier, TessdataManager *init_dict)
Definition: tface.cpp:40
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:201
void EndAdaptiveClassifier()
Definition: adaptmatch.cpp:460
double chop_ok_split
Definition: wordrec.h:225
void set_pass1()
Definition: tface.cpp:89
virtual Dict & getDict()
Definition: classify.h:107
Definition: blobs.h:268
BLOB_CHOICE_LIST * call_matcher(TBLOB *blob)
Definition: tface.cpp:141
bool StatesAllValid()
Definition: pageres.cpp:464
FEATURE_DEFS_STRUCT feature_defs_
Definition: classify.h:548
PRIORITY pass2_ok_split
Definition: wordrec.h:477
#define ASSERT_HOST(x)
Definition: errcode.h:84
WERD * word
Definition: pageres.h:189