From 0611c892b6f586fe0c02fc4b35440601d8e97478 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 2 Apr 2021 16:43:00 +0200 Subject: [PATCH] Disable more code with GRAPHICS_DISABLED Signed-off-by: Stefan Weil --- Makefile.am | 13 ++++++++++++- src/classify/classify.cpp | 2 ++ src/classify/classify.h | 4 ++++ src/classify/intproto.cpp | 2 ++ src/classify/shapeclassifier.cpp | 2 ++ src/textord/colfind.cpp | 3 ++- src/textord/colfind.h | 8 +++++--- src/textord/strokewidth.cpp | 11 ++--------- src/textord/strokewidth.h | 19 +++++++++++-------- src/training/common/mastertrainer.cpp | 2 ++ src/training/unicharset/lstmtrainer.cpp | 4 ++++ src/training/unicharset/lstmtrainer.h | 2 ++ src/viewer/svmnode.cpp | 6 +++--- 13 files changed, 53 insertions(+), 25 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0773b7f6c..d8fe25bfe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,10 @@ SUBDIRS = . tessdata EXTRA_DIST = README.md LICENSE EXTRA_DIST += aclocal.m4 config configure.ac autogen.sh -EXTRA_DIST += tesseract.pc.in java doc +EXTRA_DIST += tesseract.pc.in doc +if !GRAPHICS_DISABLED +EXTRA_DIST += java +endif EXTRA_DIST += CMakeLists.txt tesseract.pc.cmake cmake VERSION DIST_SUBDIRS = $(SUBDIRS) @@ -30,11 +33,13 @@ dist-hook: rm -f `find $(distdir) -name '*~'` rm -rf $(distdir)/doc/html/* $(distdir)/doc/*.log +if !GRAPHICS_DISABLED ScrollView.jar: @cd "$(top_builddir)/java" && $(MAKE) $@ install-jars: @cd "$(top_builddir)/java" && $(MAKE) $@ +endif doc: -srcdir="$(top_srcdir)" builddir="$(top_builddir)" \ @@ -210,8 +215,10 @@ libtesseract_la_SOURCES += src/ccmain/pageiterator.cpp libtesseract_la_SOURCES += src/ccmain/pagesegmain.cpp libtesseract_la_SOURCES += src/ccmain/pagewalk.cpp libtesseract_la_SOURCES += src/ccmain/paragraphs.cpp +if !GRAPHICS_DISABLED libtesseract_la_SOURCES += src/ccmain/paramsd.cpp libtesseract_la_SOURCES += src/ccmain/pgedit.cpp +endif libtesseract_la_SOURCES += src/ccmain/reject.cpp libtesseract_la_SOURCES += src/ccmain/resultiterator.cpp libtesseract_la_SOURCES += src/ccmain/tessedit.cpp @@ -648,6 +655,7 @@ endif # Rules for src/viewer. +if !GRAPHICS_DISABLED noinst_HEADERS += src/viewer/scrollview.h noinst_HEADERS += src/viewer/svmnode.h noinst_HEADERS += src/viewer/svutil.h @@ -655,6 +663,7 @@ noinst_HEADERS += src/viewer/svutil.h libtesseract_la_SOURCES += src/viewer/scrollview.cpp libtesseract_la_SOURCES += src/viewer/svmnode.cpp libtesseract_la_SOURCES += src/viewer/svutil.cpp +endif # TODO: Add rule to generate svpaint from svpaint.cpp. @@ -692,7 +701,9 @@ libtesseract_la_SOURCES += src/wordrec/lm_state.cpp libtesseract_la_SOURCES += src/wordrec/outlines.cpp libtesseract_la_SOURCES += src/wordrec/params_model.cpp libtesseract_la_SOURCES += src/wordrec/pieces.cpp +if !GRAPHICS_DISABLED libtesseract_la_SOURCES += src/wordrec/plotedges.cpp +endif libtesseract_la_SOURCES += src/wordrec/render.cpp libtesseract_la_SOURCES += src/wordrec/segsearch.cpp libtesseract_la_SOURCES += src/wordrec/wordclass.cpp diff --git a/src/classify/classify.cpp b/src/classify/classify.cpp index 05387f390..72c37bc1e 100644 --- a/src/classify/classify.cpp +++ b/src/classify/classify.cpp @@ -151,9 +151,11 @@ Classify::Classify() Classify::~Classify() { EndAdaptiveClassifier(); +#ifndef GRAPHICS_DISABLED delete learn_debug_win_; delete learn_fragmented_word_debug_win_; delete learn_fragments_debug_win_; +#endif } // Takes ownership of the given classifier, and uses it for future calls diff --git a/src/classify/classify.h b/src/classify/classify.h index f2aae7a8d..b399f053b 100644 --- a/src/classify/classify.h +++ b/src/classify/classify.h @@ -273,7 +273,9 @@ public: return AdaptedTemplates->NumPermClasses == 0; } bool LooksLikeGarbage(TBLOB *blob); +#ifndef GRAPHICS_DISABLED void RefreshDebugWindow(ScrollView **win, const char *msg, int y_offset, const TBOX &wbox); +#endif // intfx.cpp // Computes the DENORMS for bl(baseline) and cn(character) normalization // during feature extraction. The input denorm describes the current state @@ -471,9 +473,11 @@ protected: private: // The currently active static classifier. ShapeClassifier *static_classifier_ = nullptr; +#ifndef GRAPHICS_DISABLED ScrollView *learn_debug_win_ = nullptr; ScrollView *learn_fragmented_word_debug_win_ = nullptr; ScrollView *learn_fragments_debug_win_ = nullptr; +#endif // Training data gathered here for all the images in a document. std::string tr_file_data_; diff --git a/src/classify/intproto.cpp b/src/classify/intproto.cpp index 1aacd115a..e249aee33 100644 --- a/src/classify/intproto.cpp +++ b/src/classify/intproto.cpp @@ -33,7 +33,9 @@ #include "picofeat.h" #include "points.h" #include "shapetable.h" +#ifndef GRAPHICS_DISABLED #include "svmnode.h" +#endif #include "helpers.h" diff --git a/src/classify/shapeclassifier.cpp b/src/classify/shapeclassifier.cpp index 0683de357..eb247de3f 100644 --- a/src/classify/shapeclassifier.cpp +++ b/src/classify/shapeclassifier.cpp @@ -27,7 +27,9 @@ #include "scrollview.h" #include "shapetable.h" +#ifndef GRAPHICS_DISABLED #include "svmnode.h" +#endif #include "tprintf.h" #include "trainingsample.h" diff --git a/src/textord/colfind.cpp b/src/textord/colfind.cpp index 556204ece..c40bf132a 100644 --- a/src/textord/colfind.cpp +++ b/src/textord/colfind.cpp @@ -95,7 +95,6 @@ ColumnFinder::ColumnFinder(int gridsize, const ICOORD &bleft, const ICOORD &trig , nontext_map_(nullptr) , projection_(resolution) , denorm_(nullptr) - , input_blobs_win_(nullptr) , equation_detect_(nullptr) { TabVector_IT h_it(&horizontal_lines_); h_it.add_list_after(hlines); @@ -107,7 +106,9 @@ ColumnFinder::~ColumnFinder() { } delete[] best_columns_; delete stroke_width_; +#ifndef GRAPHICS_DISABLED delete input_blobs_win_; +#endif nontext_map_.destroy(); while (denorm_ != nullptr) { DENORM *dead_denorm = denorm_; diff --git a/src/textord/colfind.h b/src/textord/colfind.h index 044b52163..ed75b8a47 100644 --- a/src/textord/colfind.h +++ b/src/textord/colfind.h @@ -337,17 +337,19 @@ private: // coordinate space. The destructor must delete all the DENORMs in the chain. DENORM *denorm_; - // Various debug windows that automatically go away on completion. - ScrollView *input_blobs_win_; - // The equation region detector pointer. Note: This pointer is passed in by // member function SetEquationDetect, and releasing it is NOT owned by this // class. EquationDetectBase *equation_detect_; +#ifndef GRAPHICS_DISABLED + // Various debug windows that automatically go away on completion. + ScrollView *input_blobs_win_ = nullptr; + // Allow a subsequent instance to reuse the blocks window. // Not thread-safe, but multiple threads shouldn't be using windows anyway. static ScrollView *blocks_win_; +#endif }; } // namespace tesseract. diff --git a/src/textord/strokewidth.cpp b/src/textord/strokewidth.cpp index 58eab1de2..2829756d9 100644 --- a/src/textord/strokewidth.cpp +++ b/src/textord/strokewidth.cpp @@ -118,20 +118,12 @@ StrokeWidth::StrokeWidth(int gridsize, const ICOORD &bleft, const ICOORD &tright , denorm_(nullptr) , grid_box_(bleft, tright) , rerotation_(1.0f, 0.0f) { - leaders_win_ = nullptr; - widths_win_ = nullptr; - initial_widths_win_ = nullptr; - chains_win_ = nullptr; - diacritics_win_ = nullptr; - textlines_win_ = nullptr; - smoothed_win_ = nullptr; } StrokeWidth::~StrokeWidth() { - if (widths_win_ != nullptr) { #ifndef GRAPHICS_DISABLED + if (widths_win_ != nullptr) { delete widths_win_->AwaitEvent(SVET_DESTROY); -#endif // !GRAPHICS_DISABLED if (textord_tabfind_only_strokewidths) { exit(0); } @@ -143,6 +135,7 @@ StrokeWidth::~StrokeWidth() { delete textlines_win_; delete smoothed_win_; delete diacritics_win_; +#endif } // Sets the neighbours member of the medium-sized blobs in the block. diff --git a/src/textord/strokewidth.h b/src/textord/strokewidth.h index a69ce1efa..1a542f99a 100644 --- a/src/textord/strokewidth.h +++ b/src/textord/strokewidth.h @@ -2,7 +2,6 @@ // File: strokewidth.h // Description: Subclass of BBGrid to find uniformity of strokewidth. // Author: Ray Smith -// Created: Mon Mar 31 16:17:01 PST 2008 // // (C) Copyright 2008, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -297,12 +296,14 @@ private: // Returns true if there is no significant noise in between the boxes. bool NoNoiseInBetween(const TBOX &box1, const TBOX &box2) const; +#ifndef GRAPHICS_DISABLED // Displays the blobs colored according to the number of good neighbours // and the vertical/horizontal flow. ScrollView *DisplayGoodBlobs(const char *window_name, int x, int y); // Displays blobs colored according to whether or not they are diacritics. ScrollView *DisplayDiacritics(const char *window_name, int x, int y, TO_BLOCK *block); +#endif private: // Image map of photo/noise areas on the page. Borrowed pointer (not owned.) @@ -315,14 +316,16 @@ private: TBOX grid_box_; // Rerotation to get back to the original image. FCOORD rerotation_; +#ifndef GRAPHICS_DISABLED // Windows for debug display. - ScrollView *leaders_win_; - ScrollView *initial_widths_win_; - ScrollView *widths_win_; - ScrollView *chains_win_; - ScrollView *diacritics_win_; - ScrollView *textlines_win_; - ScrollView *smoothed_win_; + ScrollView *leaders_win_ = nullptr; + ScrollView *initial_widths_win_ = nullptr; + ScrollView *widths_win_ = nullptr; + ScrollView *chains_win_ = nullptr; + ScrollView *diacritics_win_ = nullptr; + ScrollView *textlines_win_ = nullptr; + ScrollView *smoothed_win_ = nullptr; +#endif }; } // namespace tesseract. diff --git a/src/training/common/mastertrainer.cpp b/src/training/common/mastertrainer.cpp index 3e6efc3a2..43eaf2773 100644 --- a/src/training/common/mastertrainer.cpp +++ b/src/training/common/mastertrainer.cpp @@ -32,7 +32,9 @@ #include "sampleiterator.h" #include "shapeclassifier.h" #include "shapetable.h" +#ifndef GRAPHICS_DISABLED #include "svmnode.h" +#endif #include "scanutils.h" diff --git a/src/training/unicharset/lstmtrainer.cpp b/src/training/unicharset/lstmtrainer.cpp index 646184ee0..8ec0f6e48 100644 --- a/src/training/unicharset/lstmtrainer.cpp +++ b/src/training/unicharset/lstmtrainer.cpp @@ -84,10 +84,12 @@ LSTMTrainer::LSTMTrainer(const char *model_base, const char *checkpoint_name, in } LSTMTrainer::~LSTMTrainer() { +#ifndef GRAPHICS_DISABLED delete align_win_; delete target_win_; delete ctc_win_; delete recon_win_; +#endif } // Tries to deserialize a trainer from the given file and silently returns @@ -1077,10 +1079,12 @@ void LSTMTrainer::SetNullChar() { // Factored sub-constructor sets up reasonable default values. void LSTMTrainer::EmptyConstructor() { +#ifndef GRAPHICS_DISABLED align_win_ = nullptr; target_win_ = nullptr; ctc_win_ = nullptr; recon_win_ = nullptr; +#endif checkpoint_iteration_ = 0; training_stage_ = 0; num_training_stages_ = 2; diff --git a/src/training/unicharset/lstmtrainer.h b/src/training/unicharset/lstmtrainer.h index 9ce862a86..a57c81908 100644 --- a/src/training/unicharset/lstmtrainer.h +++ b/src/training/unicharset/lstmtrainer.h @@ -381,6 +381,7 @@ protected: TestCallback tester); protected: +#ifndef GRAPHICS_DISABLED // Alignment display window. ScrollView *align_win_; // CTC target display window. @@ -389,6 +390,7 @@ protected: ScrollView *ctc_win_; // Reconstructed image window. ScrollView *recon_win_; +#endif // How often to display a debug image. int debug_interval_; // Iteration at which the last checkpoint was dumped. diff --git a/src/viewer/svmnode.cpp b/src/viewer/svmnode.cpp index 0077947b6..f914c7fc8 100644 --- a/src/viewer/svmnode.cpp +++ b/src/viewer/svmnode.cpp @@ -30,14 +30,14 @@ # include "config_auto.h" #endif +#ifndef GRAPHICS_DISABLED + #include "svmnode.h" #include #include -#ifndef GRAPHICS_DISABLED - -# include "scrollview.h" +#include "scrollview.h" namespace tesseract {