Coverage Report

Created: 2025-06-13 07:15

/src/tesseract/src/wordrec/tface.cpp
Line
Count
Source (jump to first uncovered line)
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
32
/**
33
 * @name program_editup
34
 *
35
 * Initialize all the things in the program that need to be initialized.
36
 * init_permute determines whether to initialize the permute functions
37
 * and Dawg models.
38
 */
39
void Wordrec::program_editup(const std::string &textbase, TessdataManager *init_classifier,
40
2
                             TessdataManager *init_dict) {
41
2
  if (!textbase.empty()) {
42
0
    imagefile = textbase;
43
0
  }
44
2
#ifndef DISABLED_LEGACY_ENGINE
45
2
  InitFeatureDefs(&feature_defs_);
46
2
  InitAdaptiveClassifier(init_classifier);
47
2
  if (init_dict) {
48
2
    getDict().SetupForLoad(Dict::GlobalDawgCache());
49
2
    getDict().Load(lang, init_dict);
50
2
    getDict().FinishLoad();
51
2
  }
52
2
  pass2_ok_split = chop_ok_split;
53
2
#endif // ndef DISABLED_LEGACY_ENGINE
54
2
}
55
56
/**
57
 * @name end_recog
58
 *
59
 * Cleanup and exit the recog program.
60
 */
61
0
int Wordrec::end_recog() {
62
0
  program_editdown(0);
63
64
0
  return (0);
65
0
}
66
67
/**
68
 * @name program_editdown
69
 *
70
 * This function holds any necessary post processing for the Wise Owl
71
 * program.
72
 */
73
0
void Wordrec::program_editdown(int32_t elapsed_time) {
74
0
#ifndef DISABLED_LEGACY_ENGINE
75
0
  EndAdaptiveClassifier();
76
0
#endif // ndef DISABLED_LEGACY_ENGINE
77
0
  getDict().End();
78
0
}
79
80
/**
81
 * @name dict_word()
82
 *
83
 * Test the dictionaries, returning NO_PERM (0) if not found, or one
84
 * of the PermuterType values if found, according to the dictionary.
85
 */
86
76.7k
int Wordrec::dict_word(const WERD_CHOICE &word) {
87
76.7k
  return getDict().valid_word(word);
88
76.7k
}
89
90
#ifndef DISABLED_LEGACY_ENGINE
91
92
/**
93
 * @name set_pass1
94
 *
95
 * Get ready to do some pass 1 stuff.
96
 */
97
31.9k
void Wordrec::set_pass1() {
98
31.9k
  chop_ok_split.set_value(70.0);
99
31.9k
  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1);
100
31.9k
  SetupPass1();
101
31.9k
}
102
103
/**
104
 * @name set_pass2
105
 *
106
 * Get ready to do some pass 2 stuff.
107
 */
108
44.7k
void Wordrec::set_pass2() {
109
44.7k
  chop_ok_split.set_value(pass2_ok_split);
110
44.7k
  language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2);
111
44.7k
  SetupPass2();
112
44.7k
}
113
114
/**
115
 * @name cc_recog
116
 *
117
 * Recognize a word.
118
 */
119
98.6k
void Wordrec::cc_recog(WERD_RES *word) {
120
98.6k
  getDict().reset_hyphen_vars(word->word->flag(W_EOL));
121
98.6k
  chop_word_main(word);
122
98.6k
  word->DebugWordChoices(getDict().stopper_debug_level >= 1, getDict().word_to_debug.c_str());
123
98.6k
  ASSERT_HOST(word->StatesAllValid());
124
98.6k
}
125
126
/**
127
 * @name call_matcher
128
 *
129
 * Called from Tess with a blob in tess form.
130
 * The blob may need rotating to the correct orientation for classification.
131
 */
132
1.20M
BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) {
133
  // Rotate the blob for classification if necessary.
134
1.20M
  TBLOB *rotated_blob = tessblob->ClassifyNormalizeIfNeeded();
135
1.20M
  if (rotated_blob == nullptr) {
136
1.20M
    rotated_blob = tessblob;
137
1.20M
  }
138
1.20M
  auto *ratings = new BLOB_CHOICE_LIST(); // matcher result
139
1.20M
  AdaptiveClassifier(rotated_blob, ratings);
140
1.20M
  if (rotated_blob != tessblob) {
141
0
    delete rotated_blob;
142
0
  }
143
1.20M
  return ratings;
144
1.20M
}
145
146
#endif // ndef DISABLED_LEGACY_ENGINE
147
148
} // namespace tesseract