tesseract  5.0.0
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  *
6  * (C) Copyright 1992, Hewlett-Packard Ltd.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  *
17  **********************************************************************/
18 
19 #include <cmath>
20 
21 #include "wordrec.h"
22 
23 #ifndef DISABLED_LEGACY_ENGINE
24 # include "chop.h"
25 # include "featdefs.h"
26 # include "pageres.h"
27 # include "params_model.h"
28 #endif
29 
30 namespace tesseract {
31 
39 void Wordrec::program_editup(const std::string &textbase, TessdataManager *init_classifier,
40  TessdataManager *init_dict) {
41  if (!textbase.empty()) {
42  imagefile = textbase;
43  }
44 #ifndef DISABLED_LEGACY_ENGINE
46  InitAdaptiveClassifier(init_classifier);
47  if (init_dict) {
49  getDict().Load(lang, init_dict);
50  getDict().FinishLoad();
51  }
52  pass2_ok_split = chop_ok_split;
53 #endif // ndef DISABLED_LEGACY_ENGINE
54 }
55 
63 
64  return (0);
65 }
66 
73 void Wordrec::program_editdown(int32_t elasped_time) {
74 #ifndef DISABLED_LEGACY_ENGINE
76 #endif // ndef DISABLED_LEGACY_ENGINE
77  getDict().End();
78 }
79 
86 int Wordrec::dict_word(const WERD_CHOICE &word) {
87  return getDict().valid_word(word);
88 }
89 
90 #ifndef DISABLED_LEGACY_ENGINE
91 
98  chop_ok_split.set_value(70.0);
99  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1);
100  SettupPass1();
101 }
102 
109  chop_ok_split.set_value(pass2_ok_split);
110  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2);
111  SettupPass2();
112 }
113 
121  chop_word_main(word);
122  word->DebugWordChoices(getDict().stopper_debug_level >= 1, getDict().word_to_debug.c_str());
123  ASSERT_HOST(word->StatesAllValid());
124 }
125 
132 BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) {
133  // Rotate the blob for classification if necessary.
134  TBLOB *rotated_blob = tessblob->ClassifyNormalizeIfNeeded();
135  if (rotated_blob == nullptr) {
136  rotated_blob = tessblob;
137  }
138  auto *ratings = new BLOB_CHOICE_LIST(); // matcher result
139  AdaptiveClassifier(rotated_blob, ratings);
140  if (rotated_blob != tessblob) {
141  delete rotated_blob;
142  }
143  return ratings;
144 }
145 
146 #endif // ndef DISABLED_LEGACY_ENGINE
147 
148 } // namespace tesseract
#define ASSERT_HOST(x)
Definition: errcode.h:59
@ W_EOL
end of line
Definition: werd.h:35
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs)
Definition: featdefs.cpp:87
TBLOB * ClassifyNormalizeIfNeeded() const
Definition: blobs.cpp:353
void DebugWordChoices(bool debug, const char *word_to_debug)
Definition: pageres.cpp:483
bool flag(WERD_FLAGS mask) const
Definition: werd.h:128
std::string imagefile
Definition: ccutil.h:65
std::string lang
Definition: ccutil.h:59
FEATURE_DEFS_STRUCT feature_defs_
Definition: classify.h:447
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:202
void InitAdaptiveClassifier(TessdataManager *mgr)
Definition: adaptmatch.cpp:527
virtual Dict & getDict()
Definition: classify.h:98
void EndAdaptiveClassifier()
Definition: adaptmatch.cpp:464
static DawgCache * GlobalDawgCache()
Definition: dict.cpp:172
void reset_hyphen_vars(bool last_word_on_line)
Definition: hyphen.cpp:27
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:801
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:180
void End()
Definition: dict.cpp:379
bool FinishLoad()
Definition: dict.cpp:357
void Load(const std::string &lang, TessdataManager *data_file)
Definition: dict.cpp:200
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:86
void set_pass1()
Definition: tface.cpp:97
BLOB_CHOICE_LIST * call_matcher(TBLOB *blob)
Definition: tface.cpp:132
void program_editdown(int32_t elasped_time)
Definition: tface.cpp:73
void chop_word_main(WERD_RES *word)
Definition: chopper.cpp:385
void program_editup(const std::string &textbase, TessdataManager *init_classifier, TessdataManager *init_dict)
Definition: tface.cpp:39
PRIORITY pass2_ok_split
Definition: wordrec.h:383
void set_pass2()
Definition: tface.cpp:108
void cc_recog(WERD_RES *word)
Definition: tface.cpp:119
std::unique_ptr< LanguageModel > language_model_
Definition: wordrec.h:382