Skip to content

Commit 41478fd

Browse files
committed
implement build without cube (-DNO_CUBE_BUILD)
1 parent 4085f91 commit 41478fd

17 files changed

+103
-58
lines changed

Makefile.am

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ endif
1616

1717
.PHONY: install-langs ScrollView.jar install-jars $(TRAINING_SUBDIR)
1818

19-
SUBDIRS = ccutil viewer cutil opencl ccstruct dict classify wordrec neural_networks/runtime textord cube ccmain api . tessdata doc
19+
SUBDIRS = ccutil viewer cutil opencl ccstruct dict classify wordrec textord
20+
if !NO_CUBE_BUILD
21+
SUBDIRS += neural_networks/runtime cube
22+
endif
23+
SUBDIRS += ccmain api . tessdata doc
2024

2125
EXTRA_DIST = ReleaseNotes \
2226
aclocal.m4 config configure.ac autogen.sh contrib \

android/jni/Android.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:$(LOCAL_PATH)/%=%)
4747
$(info local src files = $(LOCAL_SRC_FILES))
4848

4949
LOCAL_LDLIBS := -ldl -llog -ljnigraphics
50-
LOCAL_CFLAGS := -DANDROID_BUILD -DGRAPHICS_DISABLED
50+
LOCAL_CFLAGS := -DNO_CUBE_BUILD -DGRAPHICS_DISABLED
5151

5252
include $(BUILD_SHARED_LIBRARY)
5353

api/Makefile.am

+11-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ lib_LTLIBRARIES += libtesseract_api.la
2323
libtesseract_api_la_LDFLAGS = -version-info $(GENERIC_LIBRARY_VERSION)
2424
libtesseract_api_la_LIBADD = \
2525
../ccmain/libtesseract_main.la \
26-
../cube/libtesseract_cube.la \
27-
../neural_networks/runtime/libtesseract_neural.la \
2826
../textord/libtesseract_textord.la \
2927
../wordrec/libtesseract_wordrec.la \
3028
../classify/libtesseract_classify.la \
@@ -34,13 +32,17 @@ libtesseract_api_la_LIBADD = \
3432
../viewer/libtesseract_viewer.la \
3533
../ccutil/libtesseract_ccutil.la \
3634
../opencl/libtesseract_opencl.la
37-
35+
if !NO_CUBE_BUILD
36+
libtesseract_api_la_LIBADD += ../cube/libtesseract_cube.la \
37+
../neural_networks/runtime/libtesseract_neural.la \
38+
endif
3839
endif
40+
3941
libtesseract_api_la_CPPFLAGS = $(AM_CPPFLAGS)
4042
if VISIBILITY
4143
libtesseract_api_la_CPPFLAGS += -DTESS_EXPORTS
4244
endif
43-
libtesseract_api_la_SOURCES = baseapi.cpp capi.cpp pdfrenderer.cpp renderer.cpp
45+
libtesseract_api_la_SOURCES = baseapi.cpp capi.cpp renderer.cpp
4446

4547
lib_LTLIBRARIES += libtesseract.la
4648
libtesseract_la_LDFLAGS =
@@ -51,8 +53,6 @@ nodist_EXTRA_libtesseract_la_SOURCES = dummy.cxx
5153
libtesseract_la_LIBADD = \
5254
libtesseract_api.la \
5355
../ccmain/libtesseract_main.la \
54-
../cube/libtesseract_cube.la \
55-
../neural_networks/runtime/libtesseract_neural.la \
5656
../textord/libtesseract_textord.la \
5757
../wordrec/libtesseract_wordrec.la \
5858
../classify/libtesseract_classify.la \
@@ -62,6 +62,11 @@ libtesseract_la_LIBADD = \
6262
../viewer/libtesseract_viewer.la \
6363
../ccutil/libtesseract_ccutil.la \
6464
../opencl/libtesseract_opencl.la
65+
if !NO_CUBE_BUILD
66+
libtesseract_api_la_SOURCES += pdfrenderer.cpp
67+
libtesseract_la_LIBADD += ../cube/libtesseract_cube.la \
68+
../neural_networks/runtime/libtesseract_neural.la
69+
endif
6570

6671
libtesseract_la_LDFLAGS += -version-info $(GENERIC_LIBRARY_VERSION)
6772

api/baseapi.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ void TessBaseAPI::DumpPGM(const char* filename) {
747747
fclose(fp);
748748
}
749749

750-
#ifndef ANDROID_BUILD
750+
#ifndef NO_CUBE_BUILD
751751
/**
752752
* Placeholder for call to Cube and test that the input data is correct.
753753
* reskew is the direction of baselines in the skewed image in
@@ -1029,7 +1029,7 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data,
10291029
int timeout_millisec,
10301030
TessResultRenderer* renderer,
10311031
int tessedit_page_number) {
1032-
#ifndef ANDROID_BUILD
1032+
#ifndef NO_CUBE_BUILD
10331033
Pix *pix = NULL;
10341034
#ifdef USE_OPENCL
10351035
OpenclDevice od;
@@ -1098,7 +1098,7 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
10981098
const char* retry_config,
10991099
int timeout_millisec,
11001100
TessResultRenderer* renderer) {
1101-
#ifndef ANDROID_BUILD
1101+
#ifndef NO_CUBE_BUILD
11021102
PERF_COUNT_START("ProcessPages")
11031103
bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
11041104
if (stdInput) {
@@ -1222,7 +1222,7 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
12221222
failed = Recognize(NULL) < 0;
12231223
}
12241224
if (tesseract_->tessedit_write_images) {
1225-
#ifndef ANDROID_BUILD
1225+
#ifndef NO_CUBE_BUILD
12261226
Pix* page_pix = GetThresholdedImage();
12271227
pixWrite("tessinput.tif", page_pix, IFF_TIFF_G4);
12281228
#endif
@@ -2633,7 +2633,7 @@ int TessBaseAPI::NumDawgs() const {
26332633
return tesseract_ == NULL ? 0 : tesseract_->getDict().NumDawgs();
26342634
}
26352635

2636-
#ifndef ANDROID_BUILD
2636+
#ifndef NO_CUBE_BUILD
26372637
/** Return a pointer to underlying CubeRecoContext object if present. */
26382638
CubeRecoContext *TessBaseAPI::GetCubeRecoContext() const {
26392639
return (tesseract_ == NULL) ? NULL : tesseract_->GetCubeRecoContext();

api/capi.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ TESS_API TessResultRenderer* TESS_CALL TessHOcrRendererCreate2(const char* outpu
4747
return new TessHOcrRenderer(outputbase, font_info);
4848
}
4949

50+
#ifndef NO_CUBE_BUILD
5051
TESS_API TessResultRenderer* TESS_CALL TessPDFRendererCreate(const char* outputbase, const char* datadir)
5152
{
5253
return new TessPDFRenderer(outputbase, datadir);
5354
}
55+
#endif
5456

5557
TESS_API TessResultRenderer* TESS_CALL TessUnlvRendererCreate(const char* outputbase)
5658
{
@@ -581,10 +583,12 @@ TESS_API void TESS_CALL TessBaseAPIInitTruthCallback(TessBaseAPI* handle, TessTr
581583
handle->InitTruthCallback(cb);
582584
}
583585

586+
#ifndef NO_CUBE_BUILD
584587
TESS_API TessCubeRecoContext* TESS_CALL TessBaseAPIGetCubeRecoContext(const TessBaseAPI* handle)
585588
{
586589
return handle->GetCubeRecoContext();
587590
}
591+
#endif // NO_CUBE_BUILD
588592

589593
TESS_API void TESS_CALL TessBaseAPISetMinOrientationMargin(TessBaseAPI* handle, double margin)
590594
{

api/capi.h

+6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ extern "C" {
3333
typedef tesseract::TessResultRenderer TessResultRenderer;
3434
typedef tesseract::TessTextRenderer TessTextRenderer;
3535
typedef tesseract::TessHOcrRenderer TessHOcrRenderer;
36+
#ifndef NO_CUBE_BUILD
3637
typedef tesseract::TessPDFRenderer TessPDFRenderer;
38+
#endif // NO_CUBE_BUILD
3739
typedef tesseract::TessUnlvRenderer TessUnlvRenderer;
3840
typedef tesseract::TessBoxTextRenderer TessBoxTextRenderer;
3941
typedef tesseract::TessBaseAPI TessBaseAPI;
@@ -51,7 +53,9 @@ typedef tesseract::ProbabilityInContextFunc TessProbabilityInContextFunc;
5153
typedef tesseract::FillLatticeFunc TessFillLatticeFunc;
5254
typedef tesseract::Dawg TessDawg;
5355
typedef tesseract::TruthCallback TessTruthCallback;
56+
#ifndef NO_CUBE_BUILD
5457
typedef tesseract::CubeRecoContext TessCubeRecoContext;
58+
#endif // NO_CUBE_BUILD
5559
typedef tesseract::Orientation TessOrientation;
5660
typedef tesseract::ParagraphJustification TessParagraphJustification;
5761
typedef tesseract::WritingDirection TessWritingDirection;
@@ -295,8 +299,10 @@ TESS_API TessOcrEngineMode
295299
TESS_CALL TessBaseAPIOem(const TessBaseAPI* handle);
296300
TESS_API void TESS_CALL TessBaseAPIInitTruthCallback(TessBaseAPI* handle, TessTruthCallback* cb);
297301

302+
#ifndef NO_CUBE_BUILD
298303
TESS_API TessCubeRecoContext*
299304
TESS_CALL TessBaseAPIGetCubeRecoContext(const TessBaseAPI* handle);
305+
#endif // NO_CUBE_BUILD
300306
#endif
301307

302308
TESS_API void TESS_CALL TessBaseAPISetMinOrientationMargin(TessBaseAPI* handle, double margin);

api/renderer.h

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class TESS_API TessHOcrRenderer : public TessResultRenderer {
162162
bool font_info_; // whether to print font information
163163
};
164164

165+
#ifndef NO_CUBE_BUILD
165166
/**
166167
* Renders tesseract output into searchable PDF
167168
*/
@@ -197,6 +198,7 @@ class TESS_API TessPDFRenderer : public TessResultRenderer {
197198
static bool imageToPDFObj(Pix *pix, char *filename, long int objnum,
198199
char **pdf_object, long int *pdf_object_size);
199200
};
201+
#endif // NO_CUBE_BUILD
200202

201203

202204
/**

api/tesseractmain.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,13 @@ int main(int argc, char **argv) {
295295
api.GetBoolVariable("hocr_font_info", &font_info);
296296
renderers.push_back(new tesseract::TessHOcrRenderer(outputbase, font_info));
297297
}
298+
#ifndef NO_CUBE_BUILD
298299
api.GetBoolVariable("tessedit_create_pdf", &b);
299300
if (b) {
300301
renderers.push_back(new tesseract::TessPDFRenderer(outputbase,
301302
api.GetDatapath()));
302303
}
304+
#endif
303305
api.GetBoolVariable("tessedit_write_unlv", &b);
304306
if (b) renderers.push_back(new tesseract::TessUnlvRenderer(outputbase));
305307
api.GetBoolVariable("tessedit_create_boxfile", &b);

ccmain/Makefile.am

+26-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ AM_CPPFLAGS += \
44
-I$(top_srcdir)/viewer \
55
-I$(top_srcdir)/classify -I$(top_srcdir)/dict \
66
-I$(top_srcdir)/wordrec -I$(top_srcdir)/cutil \
7-
-I$(top_srcdir)/neural_networks/runtime -I$(top_srcdir)/cube \
87
-I$(top_srcdir)/textord -I$(top_srcdir)/opencl
98
if USE_OPENCL
109
AM_CPPFLAGS += -I$(OPENCL_HDR_PATH)
@@ -15,43 +14,50 @@ AM_CPPFLAGS += -DTESS_EXPORTS \
1514
endif
1615

1716
include_HEADERS = \
18-
thresholder.h ltrresultiterator.h pageiterator.h resultiterator.h \
19-
osdetect.h
17+
thresholder.h ltrresultiterator.h pageiterator.h resultiterator.h \
18+
osdetect.h
2019
noinst_HEADERS = \
21-
control.h cube_reco_context.h cubeclassifier.h docqual.h \
22-
equationdetect.h fixspace.h mutableiterator.h \
20+
control.h docqual.h equationdetect.h fixspace.h mutableiterator.h \
2321
output.h paragraphs.h paragraphs_internal.h paramsd.h pgedit.h \
24-
reject.h tessbox.h tessedit.h tesseractclass.h \
25-
tesseract_cube_combiner.h tessvars.h werdit.h
22+
reject.h tessbox.h tessedit.h tesseractclass.h tessvars.h werdit.h
2623

2724
if !USING_MULTIPLELIBS
2825
noinst_LTLIBRARIES = libtesseract_main.la
2926
else
3027
lib_LTLIBRARIES = libtesseract_main.la
3128
libtesseract_main_la_LDFLAGS = -version-info $(GENERIC_LIBRARY_VERSION)
3229
libtesseract_main_la_LIBADD = \
33-
../wordrec/libtesseract_wordrec.la \
34-
../textord/libtesseract_textord.la \
30+
../wordrec/libtesseract_wordrec.la \
31+
../textord/libtesseract_textord.la \
3532
../ccutil/libtesseract_ccutil.la \
36-
../ccstruct/libtesseract_ccstruct.la \
37-
../viewer/libtesseract_viewer.la \
38-
../dict/libtesseract_dict.la \
39-
../classify/libtesseract_classify.la \
40-
../cutil/libtesseract_cutil.la \
41-
../cube/libtesseract_cube.la \
42-
../opencl/libtesseract_opencl.la
43-
33+
../ccstruct/libtesseract_ccstruct.la \
34+
../viewer/libtesseract_viewer.la \
35+
../dict/libtesseract_dict.la \
36+
../classify/libtesseract_classify.la \
37+
../cutil/libtesseract_cutil.la \
38+
../opencl/libtesseract_opencl.la
39+
if !NO_CUBE_BUILD
40+
libtesseract_main_la_LIBADD += ../cube/libtesseract_cube.la
41+
endif
4442
endif
4543

4644
libtesseract_main_la_SOURCES = \
47-
adaptions.cpp applybox.cpp \
48-
control.cpp cube_control.cpp cube_reco_context.cpp cubeclassifier.cpp \
45+
adaptions.cpp applybox.cpp control.cpp \
4946
docqual.cpp equationdetect.cpp fixspace.cpp fixxht.cpp \
5047
ltrresultiterator.cpp \
5148
osdetect.cpp output.cpp pageiterator.cpp pagesegmain.cpp \
5249
pagewalk.cpp par_control.cpp paragraphs.cpp paramsd.cpp pgedit.cpp recogtraining.cpp \
5350
reject.cpp resultiterator.cpp superscript.cpp \
54-
tesseract_cube_combiner.cpp \
5551
tessbox.cpp tessedit.cpp tesseractclass.cpp tessvars.cpp \
5652
tfacepp.cpp thresholder.cpp \
5753
werdit.cpp
54+
55+
if !NO_CUBE_BUILD
56+
AM_CPPFLAGS += \
57+
-I$(top_srcdir)/neural_networks/runtime -I$(top_srcdir)/cube
58+
noinst_HEADERS += \
59+
cube_reco_context.h cubeclassifier.h tesseract_cube_combiner.h
60+
libtesseract_main_la_SOURCES += \
61+
cube_control.cpp cube_reco_context.cpp cubeclassifier.cpp \
62+
tesseract_cube_combiner.cpp
63+
endif

ccmain/control.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*
1919
**********************************************************************/
2020

21+
// Include automatically generated configuration file if running autoconf.
22+
#ifdef HAVE_CONFIG_H
23+
#include "config_auto.h"
24+
#endif
25+
2126
#include <string.h>
2227
#include <math.h>
2328
#ifdef __UNIX__
@@ -42,11 +47,6 @@
4247
#include "sorthelper.h"
4348
#include "tesseractclass.h"
4449

45-
// Include automatically generated configuration file if running autoconf.
46-
#ifdef HAVE_CONFIG_H
47-
#include "config_auto.h"
48-
#endif
49-
5050
#define MIN_FONT_ROW_COUNT 8
5151
#define MAX_XHEIGHT_DIFF 3
5252

@@ -393,7 +393,7 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res,
393393
// ****************** Pass 5,6 *******************
394394
rejection_passes(page_res, monitor, target_word_box, word_config);
395395

396-
#ifndef ANDROID_BUILD
396+
#ifndef NO_CUBE_BUILD
397397
// ****************** Pass 7 *******************
398398
// Cube combiner.
399399
// If cube is loaded and its combiner is present, run it.
@@ -1348,7 +1348,7 @@ void Tesseract::classify_word_pass1(const WordData& word_data,
13481348
BLOCK* block = word_data.block;
13491349
prev_word_best_choice_ = word_data.prev_word != NULL
13501350
? word_data.prev_word->word->best_choice : NULL;
1351-
#ifndef ANDROID_BUILD
1351+
#ifndef NO_CUBE_BUILD
13521352
// If we only intend to run cube - run it and return.
13531353
if (tessedit_ocr_engine_mode == OEM_CUBE_ONLY) {
13541354
cube_word_pass1(block, row, *in_word);

ccmain/paramsd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define VARABLED_H
2525

2626
#include "elst.h"
27-
#ifndef ANDROID_BUILD
27+
#ifndef NO_CUBE_BUILD
2828
#include "scrollview.h"
2929
#endif
3030
#include "params.h"

ccmain/tessedit.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
*
2020
**********************************************************************/
2121

22+
// Include automatically generated configuration file if running autoconf.
23+
#ifdef HAVE_CONFIG_H
24+
#include "config_auto.h"
25+
#endif
26+
2227
#include "stderr.h"
2328
#include "basedir.h"
2429
#include "tessvars.h"
@@ -200,7 +205,7 @@ bool Tesseract::init_tesseract_lang_data(
200205
// engine-specific data files need to be loaded. Currently everything needs
201206
// the base tesseract data, which supplies other useful information, but
202207
// alternative engines, such as cube and LSTM are optional.
203-
#ifndef ANDROID_BUILD
208+
#ifndef NO_CUBE_BUILD
204209
if (tessedit_ocr_engine_mode == OEM_CUBE_ONLY) {
205210
ASSERT_HOST(init_cube_objects(false, &tessdata_manager));
206211
if (tessdata_manager_debug_level)

0 commit comments

Comments
 (0)