Skip to content

Commit 184b8d2

Browse files
committed
tesseract: trim the fat
1 parent f18d455 commit 184b8d2

2 files changed

Lines changed: 374 additions & 0 deletions

File tree

thirdparty/tesseract/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ list(APPEND PATCH_FILES
22
cmake_tweaks.patch
33
k2pdfopt.patch
44
no_debug_fonts.patch
5+
trim_the_fat.patch
56
)
67

78
list(APPEND CMAKE_ARGS
Lines changed: 373 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,373 @@
1+
diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp
2+
index 1329549e..d0c965df 100644
3+
--- a/src/api/baseapi.cpp
4+
+++ b/src/api/baseapi.cpp
5+
@@ -118,6 +118,7 @@ static const char *kOldVarsFile = "failed_vars.txt";
6+
static const char *kInputFile = "noname.tif";
7+
static const char kUnknownFontName[] = "UnknownFont";
8+
9+
+#if 0
10+
static STRING_VAR(classify_font_name, kUnknownFontName,
11+
"Default font name to be used in training");
12+
13+
@@ -145,6 +146,7 @@ static void ExtractFontName(std::string_view filename, std::string* fontname) {
14+
}
15+
}
16+
#endif
17+
+#endif
18+
19+
/* Add all available languages recursively.
20+
*/
21+
@@ -774,6 +776,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC *monitor) {
22+
23+
tesseract_->SetBlackAndWhitelist();
24+
recognition_done_ = true;
25+
+#if 0
26+
#ifndef DISABLED_LEGACY_ENGINE
27+
if (tesseract_->tessedit_resegment_from_line_boxes) {
28+
page_res_ = tesseract_->ApplyBoxes(input_file_.c_str(), true, block_list_);
29+
@@ -781,6 +784,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC *monitor) {
30+
page_res_ = tesseract_->ApplyBoxes(input_file_.c_str(), false, block_list_);
31+
} else
32+
#endif // ndef DISABLED_LEGACY_ENGINE
33+
+#endif
34+
{
35+
page_res_ =
36+
new PAGE_RES(tesseract_->AnyLSTMLang(), block_list_, &tesseract_->prev_word_best_choice_);
37+
@@ -790,6 +794,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC *monitor) {
38+
return -1;
39+
}
40+
41+
+#if 0
42+
if (tesseract_->tessedit_train_line_recognizer) {
43+
if (!tesseract_->TrainLineRecognizer(input_file_.c_str(), output_file_, block_list_)) {
44+
return -1;
45+
@@ -803,8 +808,10 @@ int TessBaseAPI::Recognize(ETEXT_DESC *monitor) {
46+
return 0;
47+
}
48+
#endif // ndef DISABLED_LEGACY_ENGINE
49+
+#endif
50+
51+
int result = 0;
52+
+#if 0
53+
if (tesseract_->interactive_display_mode) {
54+
#ifndef GRAPHICS_DISABLED
55+
tesseract_->pgeditor_main(rect_width_, rect_height_, page_res_);
56+
@@ -814,7 +821,10 @@ int TessBaseAPI::Recognize(ETEXT_DESC *monitor) {
57+
delete page_res_;
58+
page_res_ = nullptr;
59+
return -1;
60+
-#ifndef DISABLED_LEGACY_ENGINE
61+
+#else
62+
+ if (0) {
63+
+#endif
64+
+#if 0
65+
} else if (tesseract_->tessedit_train_from_boxes) {
66+
std::string fontname;
67+
ExtractFontName(output_file_, &fontname);
68+
@@ -1001,10 +1011,12 @@ bool TessBaseAPI::ProcessPages(const char *filename, const char *retry_config, i
69+
bool result = ProcessPagesInternal(filename, retry_config, timeout_millisec, renderer);
70+
#ifndef DISABLED_LEGACY_ENGINE
71+
if (result) {
72+
+#if 0
73+
if (tesseract_->tessedit_train_from_boxes && !tesseract_->WriteTRFile(output_file_.c_str())) {
74+
tprintf("Write of TR file failed: %s\n", output_file_.c_str());
75+
return false;
76+
}
77+
+#endif
78+
}
79+
#endif // ndef DISABLED_LEGACY_ENGINE
80+
return result;
81+
diff --git a/src/ccmain/paragraphs.cpp b/src/ccmain/paragraphs.cpp
82+
index 12866ebc..25234a96 100644
83+
--- a/src/ccmain/paragraphs.cpp
84+
+++ b/src/ccmain/paragraphs.cpp
85+
@@ -137,6 +137,8 @@ static std::string RtlEmbed(const std::string &word, bool rtlify) {
86+
return word;
87+
}
88+
89+
+#if 0
90+
+
91+
// Print the current thoughts of the paragraph detector.
92+
static void PrintDetectorState(const ParagraphTheory &theory,
93+
const std::vector<RowScratchRegisters> &rows) {
94+
@@ -186,6 +188,10 @@ static void DebugDump(bool should_print, const char *phase, const ParagraphTheor
95+
PrintDetectorState(theory, rows);
96+
}
97+
98+
+#else
99+
+# define DebugDump(...)
100+
+#endif
101+
+
102+
// Print out the text for rows[row_start, row_end)
103+
static void PrintRowRange(const std::vector<RowScratchRegisters> &rows, int row_start,
104+
int row_end) {
105+
diff --git a/src/ccmain/recogtraining.cpp b/src/ccmain/recogtraining.cpp
106+
index 02c60a6d..6fe2bc7a 100644
107+
--- a/src/ccmain/recogtraining.cpp
108+
+++ b/src/ccmain/recogtraining.cpp
109+
@@ -34,12 +34,14 @@ const int16_t kMaxBoxEdgeDiff = 2;
110+
// Sets flags necessary for recognition in the training mode.
111+
// Opens and returns the pointer to the output file.
112+
FILE *Tesseract::init_recog_training(const char *filename) {
113+
+#if 0
114+
if (tessedit_ambigs_training) {
115+
tessedit_tess_adaption_mode.set_value(0); // turn off adaption
116+
tessedit_enable_doc_dict.set_value(false); // turn off document dictionary
117+
// Explore all segmentations.
118+
getDict().stopper_no_acceptable_choices.set_value(true);
119+
}
120+
+#endif
121+
122+
std::string output_fname = filename;
123+
const char *lastdot = strrchr(output_fname.c_str(), '.');
124+
diff --git a/src/ccmain/tessedit.cpp b/src/ccmain/tessedit.cpp
125+
index 7ec89bd9..52fb467e 100644
126+
--- a/src/ccmain/tessedit.cpp
127+
+++ b/src/ccmain/tessedit.cpp
128+
@@ -215,7 +215,7 @@ bool Tesseract::init_tesseract_lang_data(const std::string &language, OcrEngineM
129+
unichar_ambigs.InitUnicharAmbigs(unicharset, use_ambigs_for_adaption);
130+
unichar_ambigs.LoadUniversal(encoder_unicharset, &unicharset);
131+
132+
- if (!tessedit_ambigs_training && mgr->GetComponent(TESSDATA_AMBIGS, &fp)) {
133+
+ if (/*!tessedit_ambigs_training && */mgr->GetComponent(TESSDATA_AMBIGS, &fp)) {
134+
unichar_ambigs.LoadUnicharAmbigs(encoder_unicharset, &fp, ambigs_debug_level,
135+
use_ambigs_for_adaption, &unicharset);
136+
}
137+
diff --git a/src/ccmain/tesseractclass.cpp b/src/ccmain/tesseractclass.cpp
138+
index ce896a84..79791e87 100644
139+
--- a/src/ccmain/tesseractclass.cpp
140+
+++ b/src/ccmain/tesseractclass.cpp
141+
@@ -51,6 +51,7 @@
142+
namespace tesseract {
143+
144+
Tesseract::Tesseract()
145+
+#if 0
146+
: BOOL_MEMBER(tessedit_resegment_from_boxes, false,
147+
"Take segmentation and labeling from box file", this->params())
148+
, BOOL_MEMBER(tessedit_resegment_from_line_boxes, false,
149+
@@ -62,6 +63,9 @@ Tesseract::Tesseract()
150+
, BOOL_MEMBER(tessedit_train_line_recognizer, false,
151+
"Break input into lines and remap boxes if present", this->params())
152+
, BOOL_MEMBER(tessedit_dump_pageseg_images, false,
153+
+#else
154+
+ : BOOL_MEMBER(tessedit_dump_pageseg_images, false,
155+
+#endif
156+
"Dump intermediate images made during page segmentation", this->params())
157+
// TODO: remove deprecated tessedit_do_invert in release 6.
158+
, BOOL_MEMBER(tessedit_do_invert, true,
159+
@@ -126,8 +130,10 @@ Tesseract::Tesseract()
160+
, STRING_MEMBER(tessedit_char_whitelist, "", "Whitelist of chars to recognize", this->params())
161+
, STRING_MEMBER(tessedit_char_unblacklist, "",
162+
"List of chars to override tessedit_char_blacklist", this->params())
163+
+#if 0
164+
, BOOL_MEMBER(tessedit_ambigs_training, false, "Perform training for ambiguities",
165+
this->params())
166+
+#endif
167+
, INT_MEMBER(pageseg_devanagari_split_strategy, tesseract::ShiroRekhaSplitter::NO_SPLIT,
168+
"Whether to use the top-line splitting process for Devanagari "
169+
"documents while performing page-segmentation.",
170+
@@ -389,7 +395,9 @@ Tesseract::Tesseract()
171+
, INT_MEMBER(tessedit_page_number, -1, "-1 -> All pages, else specific page to process",
172+
this->params())
173+
, BOOL_MEMBER(tessedit_write_images, false, "Capture the image from the IPE", this->params())
174+
+#if 0
175+
, BOOL_MEMBER(interactive_display_mode, false, "Run interactively?", this->params())
176+
+#endif
177+
, STRING_MEMBER(file_type, ".tif", "Filename extension", this->params())
178+
, BOOL_MEMBER(tessedit_override_permuter, true, "According to dict_word", this->params())
179+
, STRING_MEMBER(tessedit_load_sublangs, "", "List of languages to load with this one",
180+
diff --git a/src/ccmain/tesseractclass.h b/src/ccmain/tesseractclass.h
181+
index 9a8875c3..8014aab7 100644
182+
--- a/src/ccmain/tesseractclass.h
183+
+++ b/src/ccmain/tesseractclass.h
184+
@@ -742,11 +742,13 @@ public:
185+
float ComputeCompatibleXheight(WERD_RES *word_res, float *baseline_shift);
186+
//// Data members ///////////////////////////////////////////////////////
187+
// TODO(ocr-team): Find and remove obsolete parameters.
188+
+#if 0
189+
BOOL_VAR_H(tessedit_resegment_from_boxes);
190+
BOOL_VAR_H(tessedit_resegment_from_line_boxes);
191+
BOOL_VAR_H(tessedit_train_from_boxes);
192+
BOOL_VAR_H(tessedit_make_boxes_from_boxes);
193+
BOOL_VAR_H(tessedit_train_line_recognizer);
194+
+#endif
195+
BOOL_VAR_H(tessedit_dump_pageseg_images);
196+
// TODO: remove deprecated tessedit_do_invert in release 6.
197+
BOOL_VAR_H(tessedit_do_invert);
198+
@@ -763,7 +765,9 @@ public:
199+
STRING_VAR_H(tessedit_char_blacklist);
200+
STRING_VAR_H(tessedit_char_whitelist);
201+
STRING_VAR_H(tessedit_char_unblacklist);
202+
+#if 0
203+
BOOL_VAR_H(tessedit_ambigs_training);
204+
+#endif
205+
INT_VAR_H(pageseg_devanagari_split_strategy);
206+
INT_VAR_H(ocr_devanagari_split_strategy);
207+
STRING_VAR_H(tessedit_write_params_to_file);
208+
@@ -932,7 +936,9 @@ public:
209+
BOOL_VAR_H(tessedit_create_boxfile);
210+
INT_VAR_H(tessedit_page_number);
211+
BOOL_VAR_H(tessedit_write_images);
212+
+#if 0
213+
BOOL_VAR_H(interactive_display_mode);
214+
+#endif
215+
STRING_VAR_H(file_type);
216+
BOOL_VAR_H(tessedit_override_permuter);
217+
STRING_VAR_H(tessedit_load_sublangs);
218+
diff --git a/src/classify/adaptmatch.cpp b/src/classify/adaptmatch.cpp
219+
index 09e9d311..1c468269 100644
220+
--- a/src/classify/adaptmatch.cpp
221+
+++ b/src/classify/adaptmatch.cpp
222+
@@ -2091,6 +2091,8 @@ void Classify::ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features
223+
224+
#endif // !GRAPHICS_DISABLED
225+
226+
+#if 0
227+
+
228+
// Returns a string for the classifier class_id: either the corresponding
229+
// unicharset debug_str or the shape_table_ debug str.
230+
std::string Classify::ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id,
231+
@@ -2105,6 +2107,8 @@ std::string Classify::ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, i
232+
return class_string;
233+
}
234+
235+
+#endif
236+
+
237+
// Converts a classifier class_id index to a shape_table_ index
238+
int Classify::ClassAndConfigIDToFontOrShapeID(int class_id, int int_result_config) const {
239+
int font_set_id = PreTrainedTemplates->Class[class_id]->font_set_id;
240+
diff --git a/src/classify/classify.h b/src/classify/classify.h
241+
index 1a511c28..4b51ef3c 100644
242+
--- a/src/classify/classify.h
243+
+++ b/src/classify/classify.h
244+
@@ -209,10 +209,12 @@ public:
245+
void RemoveBadMatches(ADAPT_RESULTS *Results);
246+
void SetAdaptiveThreshold(float Threshold);
247+
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features);
248+
+#if 0
249+
// Returns a string for the classifier class_id: either the corresponding
250+
// unicharset debug_str or the shape_table_ debug str.
251+
std::string ClassIDToDebugStr(const INT_TEMPLATES_STRUCT *templates, int class_id,
252+
int config_id) const;
253+
+#endif
254+
// Converts a classifier class_id index with a config ID to:
255+
// shape_table_ present: a shape_table_ index OR
256+
// No shape_table_: a font ID.
257+
diff --git a/src/classify/intmatcher.cpp b/src/classify/intmatcher.cpp
258+
index d4b81c56..69d9e759 100644
259+
--- a/src/classify/intmatcher.cpp
260+
+++ b/src/classify/intmatcher.cpp
261+
@@ -314,6 +314,8 @@ for (int bit = 0; bit < BITS_PER_WERD/NUM_BITS_PER_CLASS; bit++) {
262+
}
263+
}
264+
265+
+#if 0
266+
+
267+
/** Prints debug info on the class pruner matches for the pruned classes only.
268+
*/
269+
void DebugMatch(const Classify &classify, const INT_TEMPLATES_STRUCT *int_templates,
270+
@@ -364,6 +366,8 @@ for (int bit = 0; bit < BITS_PER_WERD/NUM_BITS_PER_CLASS; bit++) {
271+
}
272+
}
273+
274+
+#endif
275+
+
276+
/// Copies the pruned, sorted classes into the output results and returns
277+
/// the number of classes.
278+
int SetupResults(std::vector<CP_RESULT_STRUCT> *results) const {
279+
@@ -448,6 +452,7 @@ int Classify::PruneClasses(const INT_TEMPLATES_STRUCT *int_templates, int num_fe
280+
pruner.PruneAndSort(classify_class_pruner_threshold, keep_this, shape_table_ == nullptr,
281+
unicharset);
282+
283+
+#if 0
284+
if (classify_debug_level > 2) {
285+
pruner.DebugMatch(*this, int_templates, features);
286+
}
287+
@@ -455,6 +460,7 @@ int Classify::PruneClasses(const INT_TEMPLATES_STRUCT *int_templates, int num_fe
288+
pruner.SummarizeResult(*this, int_templates, expected_num_features,
289+
classify_class_pruner_multiplier, normalization_factors);
290+
}
291+
+#endif
292+
// Convert to the expected output format.
293+
return pruner.SetupResults(results);
294+
}
295+
diff --git a/src/classify/shapeclassifier.cpp b/src/classify/shapeclassifier.cpp
296+
index 5e03eaf6..c1aac090 100644
297+
--- a/src/classify/shapeclassifier.cpp
298+
+++ b/src/classify/shapeclassifier.cpp
299+
@@ -167,6 +167,8 @@ int ShapeClassifier::DisplayClassifyAs(const TrainingSample &/*sample*/,
300+
return index;
301+
}
302+
303+
+#if 0
304+
+
305+
// Prints debug information on the results.
306+
void ShapeClassifier::UnicharPrintResults(const char *context,
307+
const std::vector<UnicharRating> &results) const {
308+
@@ -198,6 +200,8 @@ void ShapeClassifier::PrintResults(const char *context,
309+
}
310+
}
311+
312+
+#endif
313+
+
314+
// Removes any result that has all its unichars covered by a better choice,
315+
// regardless of font.
316+
void ShapeClassifier::FilterDuplicateUnichars(std::vector<ShapeRating> *results) const {
317+
diff --git a/src/classify/shapeclassifier.h b/src/classify/shapeclassifier.h
318+
index 1412765b..2fc7d5a4 100644
319+
--- a/src/classify/shapeclassifier.h
320+
+++ b/src/classify/shapeclassifier.h
321+
@@ -101,11 +101,13 @@ public:
322+
virtual int DisplayClassifyAs(const TrainingSample &sample, Image page_pix, UNICHAR_ID unichar_id,
323+
int index);
324+
325+
+#if 0
326+
// Prints debug information on the results. context is some introductory/title
327+
// message.
328+
virtual void UnicharPrintResults(const char *context,
329+
const std::vector<UnicharRating> &results) const;
330+
virtual void PrintResults(const char *context, const std::vector<ShapeRating> &results) const;
331+
+#endif
332+
333+
protected:
334+
// Removes any result that has all its unichars covered by a better choice,
335+
diff --git a/src/classify/shapetable.cpp b/src/classify/shapetable.cpp
336+
index cf3ec60b..0cc42015 100644
337+
--- a/src/classify/shapetable.cpp
338+
+++ b/src/classify/shapetable.cpp
339+
@@ -292,6 +292,8 @@ void ShapeTable::ReMapClassIds(const std::vector<int> &unicharset_map) {
340+
}
341+
}
342+
343+
+#if 0
344+
+
345+
// Returns a string listing the classes/fonts in a shape.
346+
std::string ShapeTable::DebugStr(unsigned shape_id) const {
347+
if (shape_id >= shape_table_.size()) {
348+
@@ -350,6 +352,8 @@ std::string ShapeTable::SummaryStr() const {
349+
return result;
350+
}
351+
352+
+#endif
353+
+
354+
// Adds a new shape starting with the given unichar_id and font_id.
355+
// Returns the assigned index.
356+
unsigned ShapeTable::AddShape(int unichar_id, int font_id) {
357+
diff --git a/src/classify/shapetable.h b/src/classify/shapetable.h
358+
index 8497b786..4499045a 100644
359+
--- a/src/classify/shapetable.h
360+
+++ b/src/classify/shapetable.h
361+
@@ -263,10 +263,12 @@ public:
362+
// Re-indexes the class_ids in the shapetable according to the given map.
363+
// Useful in conjunction with set_unicharset.
364+
void ReMapClassIds(const std::vector<int> &unicharset_map);
365+
+#if 0
366+
// Returns a string listing the classes/fonts in a shape.
367+
std::string DebugStr(unsigned shape_id) const;
368+
// Returns a debug string summarizing the table.
369+
std::string SummaryStr() const;
370+
+#endif
371+
372+
// Adds a new shape starting with the given unichar_id and font_id.
373+
// Returns the assigned index.

0 commit comments

Comments
 (0)