tesseract  5.0.0-alpha-619-ge9db
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 "callcpp.h"
25 #include "chop.h"
26 #include "featdefs.h"
27 #include "pageres.h"
28 #include "params_model.h"
29 #endif
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 
62 int Wordrec::end_recog() {
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 
89 int Wordrec::dict_word(const WERD_CHOICE &word) {
90  return getDict().valid_word(word);
91 }
92 
93 
94 #ifndef DISABLED_LEGACY_ENGINE
95 
101 void Wordrec::set_pass1() {
102  chop_ok_split.set_value(70.0);
103  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1);
104  SettupPass1();
105 }
106 
107 
113 void Wordrec::set_pass2() {
114  chop_ok_split.set_value(pass2_ok_split);
115  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2);
116  SettupPass2();
117 }
118 
119 
125 void Wordrec::cc_recog(WERD_RES *word) {
128  word->DebugWordChoices(getDict().stopper_debug_level >= 1,
129  getDict().word_to_debug.c_str());
130  ASSERT_HOST(word->StatesAllValid());
131 }
132 
133 
140 BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) {
141  // Rotate the blob for classification if necessary.
142  TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded();
143  if (rotated_blob == nullptr) {
144  rotated_blob = tessblob;
145  }
146  auto *ratings = new BLOB_CHOICE_LIST(); // matcher result
147  AdaptiveClassifier(rotated_blob, ratings);
148  if (rotated_blob != tessblob) {
149  delete rotated_blob;
150  }
151  return ratings;
152 }
153 
154 #endif // ndef DISABLED_LEGACY_ENGINE
155 
156 } // namespace tesseract
tesseract::Wordrec::chop_ok_split
double chop_ok_split
Definition: wordrec.h:221
TBLOB::ClassifyNormalizeIfNeeded
TBLOB * ClassifyNormalizeIfNeeded() const
Definition: blobs.cpp:345
pageres.h
InitFeatureDefs
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs)
Definition: featdefs.cpp:111
WERD::flag
bool flag(WERD_FLAGS mask) const
Definition: werd.h:116
tesseract::Wordrec::end_recog
int end_recog()
Definition: tface.cpp:76
tesseract::Wordrec::chop_word_main
void chop_word_main(WERD_RES *word)
Definition: chopper.cpp:389
WERD_CHOICE
Definition: ratngs.h:261
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
tesseract::Classify::EndAdaptiveClassifier
void EndAdaptiveClassifier()
Definition: adaptmatch.cpp:459
chop.h
wordrec.h
tesseract::Wordrec::program_editdown
void program_editdown(int32_t elasped_time)
Definition: tface.cpp:89
tesseract::Wordrec::cc_recog
void cc_recog(WERD_RES *word)
Definition: tface.cpp:139
tesseract::Wordrec::set_pass1
void set_pass1()
Definition: tface.cpp:115
tesseract::Wordrec::dict_word
int dict_word(const WERD_CHOICE &word)
Definition: tface.cpp:103
WERD_RES
Definition: pageres.h:160
tesseract::Dict::Load
void Load(const STRING &lang, TessdataManager *data_file)
Definition: dict.cpp:210
tesseract::CCUtil::imagefile
STRING imagefile
Definition: ccutil.h:61
tesseract::Wordrec::program_editup
void program_editup(const char *textbase, TessdataManager *init_classifier, TessdataManager *init_dict)
Definition: tface.cpp:54
tesseract::Dict::GlobalDawgCache
static TESS_API DawgCache * GlobalDawgCache()
Definition: dict.cpp:184
tesseract::Classify::getDict
virtual Dict & getDict()
Definition: classify.h:107
WERD_RES::DebugWordChoices
void DebugWordChoices(bool debug, const char *word_to_debug)
Definition: pageres.cpp:476
tesseract::ParamsModel::PTRAIN_PASS1
Definition: params_model.h:35
tesseract::Dict::End
void End()
Definition: dict.cpp:372
W_EOL
end of line
Definition: werd.h:47
tesseract::Classify::AdaptiveClassifier
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:191
tesseract::Dict::SetupForLoad
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:192
tesseract::Classify::feature_defs_
FEATURE_DEFS_STRUCT feature_defs_
Definition: classify.h:541
tesseract::CCUtil::lang
STRING lang
Definition: ccutil.h:55
tesseract::Classify::InitAdaptiveClassifier
void InitAdaptiveClassifier(TessdataManager *mgr)
Definition: adaptmatch.cpp:527
tesseract
Definition: baseapi.h:65
tesseract::ParamsModel::PTRAIN_PASS2
Definition: params_model.h:36
callcpp.h
tesseract::Wordrec::set_pass2
void set_pass2()
Definition: tface.cpp:127
WERD_RES::StatesAllValid
bool StatesAllValid()
Definition: pageres.cpp:454
tesseract::Dict::FinishLoad
bool FinishLoad()
Definition: dict.cpp:351
TBLOB
Definition: blobs.h:282
tesseract::Dict::reset_hyphen_vars
void reset_hyphen_vars(bool last_word_on_line)
Definition: hyphen.cpp:42
params_model.h
featdefs.h
tesseract::Wordrec::call_matcher
BLOB_CHOICE_LIST * call_matcher(TBLOB *blob)
Definition: tface.cpp:154
tesseract::Wordrec::pass2_ok_split
PRIORITY pass2_ok_split
Definition: wordrec.h:472
tesseract::Dict::valid_word
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:778
WERD_RES::word
WERD * word
Definition: pageres.h:180
tesseract::Classify::SettupPass1
void SettupPass1()
Definition: adaptmatch.cpp:652
tesseract::Wordrec::language_model_
std::unique_ptr< LanguageModel > language_model_
Definition: wordrec.h:471
tesseract::Classify::SettupPass2
void SettupPass2()
Definition: adaptmatch.cpp:669