comparison mupdf-source/thirdparty/tesseract/src/wordrec/tface.cpp @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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 TessdataManager *init_dict) {
41 if (!textbase.empty()) {
42 imagefile = textbase;
43 }
44 #ifndef DISABLED_LEGACY_ENGINE
45 InitFeatureDefs(&feature_defs_);
46 InitAdaptiveClassifier(init_classifier);
47 if (init_dict) {
48 getDict().SetupForLoad(Dict::GlobalDawgCache());
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
56 /**
57 * @name end_recog
58 *
59 * Cleanup and exit the recog program.
60 */
61 int Wordrec::end_recog() {
62 program_editdown(0);
63
64 return (0);
65 }
66
67 /**
68 * @name program_editdown
69 *
70 * This function holds any necessary post processing for the Wise Owl
71 * program.
72 */
73 void Wordrec::program_editdown(int32_t elapsed_time) {
74 #ifndef DISABLED_LEGACY_ENGINE
75 EndAdaptiveClassifier();
76 #endif // ndef DISABLED_LEGACY_ENGINE
77 getDict().End();
78 }
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 int Wordrec::dict_word(const WERD_CHOICE &word) {
87 return getDict().valid_word(word);
88 }
89
90 #ifndef DISABLED_LEGACY_ENGINE
91
92 /**
93 * @name set_pass1
94 *
95 * Get ready to do some pass 1 stuff.
96 */
97 void Wordrec::set_pass1() {
98 chop_ok_split.set_value(70.0);
99 language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS1);
100 SetupPass1();
101 }
102
103 /**
104 * @name set_pass2
105 *
106 * Get ready to do some pass 2 stuff.
107 */
108 void Wordrec::set_pass2() {
109 chop_ok_split.set_value(pass2_ok_split);
110 language_model_->getParamsModel().SetPass(ParamsModel::PTRAIN_PASS2);
111 SetupPass2();
112 }
113
114 /**
115 * @name cc_recog
116 *
117 * Recognize a word.
118 */
119 void Wordrec::cc_recog(WERD_RES *word) {
120 getDict().reset_hyphen_vars(word->word->flag(W_EOL));
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
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 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