Skip to content

Commit 4a3caef

Browse files
committed
Add ability to build under android (without cube or scrollview).
1 parent 2eec979 commit 4a3caef

12 files changed

+127
-5
lines changed

android/AndroidManifest.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!--
2+
This file is needed by the android_native_library rule to determine the
3+
project directory for ndk-build.
4+
-->

android/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EXTRA_DIST = AndroidManifest.xml jni/Android.mk jni/Application.mk

android/jni/Android.mk

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
LOCAL_PATH := $(call my-dir)
2+
include $(CLEAR_VARS)
3+
4+
LOCAL_MODULE := tesseract-$(APP_ABI)
5+
6+
LOCAL_STATIC_LIBRARIES := \
7+
mobile_base \
8+
leptonica-$(APP_ABI)
9+
10+
LOCAL_C_INCLUDES := $(APP_C_INCLUDES)
11+
12+
LOCAL_C_INCLUDES += \
13+
$(LOCAL_PATH)/../../api \
14+
$(LOCAL_PATH)/../../ccmain\
15+
$(LOCAL_PATH)/../../ccstruct\
16+
$(LOCAL_PATH)/../../ccutil\
17+
$(LOCAL_PATH)/../../classify\
18+
$(LOCAL_PATH)/../../cutil\
19+
$(LOCAL_PATH)/../../dict\
20+
$(LOCAL_PATH)/../../image\
21+
$(LOCAL_PATH)/../../textord\
22+
$(LOCAL_PATH)/../../third_party\
23+
$(LOCAL_PATH)/../../wordrec\
24+
$(LOCAL_PATH)/../../opencl\
25+
$(LOCAL_PATH)/../../viewer\
26+
$(LOCAL_PATH)/../../../leptonica/include
27+
28+
$(info local c includes=$(LOCAL_C_INCLUDES))
29+
$(info local path=$(LOCAL_PATH))
30+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/../../api/*.cpp $(LOCAL_PATH)/../../ccmain/*.cpp $(LOCAL_PATH)/../../ccstruct/*.cpp $(LOCAL_PATH)/../../ccutil/*.cpp $(LOCAL_PATH)/../../classify/*.cpp $(LOCAL_PATH)/../../cutil/*.cpp $(LOCAL_PATH)/../../dict/*.cpp $(LOCAL_PATH)/../../image/*.cpp $(LOCAL_PATH)/../../textord/*.cpp $(LOCAL_PATH)/../../viewer/*.cpp $(LOCAL_PATH)/../../wordrec/*.cpp)
31+
32+
EXPLICIT_SRC_EXCLUDES := \
33+
$(LOCAL_PATH)/../../ccmain/cubeclassifier.cpp \
34+
$(LOCAL_PATH)/../../ccmain/cubeclassifier.h \
35+
$(LOCAL_PATH)/../../ccmain/cube_control.cpp \
36+
$(LOCAL_PATH)/../../ccmain/cube_reco_context.cpp \
37+
$(LOCAL_PATH)/../../ccmain/cube_reco_context.h \
38+
$(LOCAL_PATH)/../../ccmain/tesseract_cube_combiner.cpp \
39+
$(LOCAL_PATH)/../../ccmain/tesseract_cube_combiner.h \
40+
$(LOCAL_PATH)/../../api/pdfrenderer.cpp \
41+
$(LOCAL_PATH)/../../api/tesseractmain.cpp \
42+
43+
LOCAL_SRC_FILES := $(filter-out $(EXPLICIT_SRC_EXCLUDES), $(LOCAL_SRC_FILES))
44+
45+
LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:$(LOCAL_PATH)/%=%)
46+
47+
$(info local src files = $(LOCAL_SRC_FILES))
48+
49+
LOCAL_LDLIBS := -ldl -llog -ljnigraphics
50+
LOCAL_CFLAGS := -DANDROID_BUILD -DGRAPHICS_DISABLED
51+
52+
include $(BUILD_SHARED_LIBRARY)
53+
54+
$(call import-module,mobile/base)
55+
$(call import-module,mobile/base)
56+
$(call import-module,mobile/util/hash)
57+
$(call import-module,third_party/leptonica/android/jni)

android/jni/Application.mk

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Include common.mk for building google3 native code.
2+
DEPOT_PATH := $(firstword $(subst /google3, ,$(abspath $(call my-dir))))
3+
ifneq ($(wildcard $(DEPOT_PATH)/google3/mobile/build/common.mk),)
4+
include $(DEPOT_PATH)/google3/mobile/build/common.mk
5+
else
6+
include $(DEPOT_PATH)/READONLY/google3/mobile/build/common.mk
7+
endif
8+
9+
# Specify the hash namespace that we're using, based on the APP_STL we're using.
10+
APP_CFLAGS += -Werror -DHASH_NAMESPACE=__gnu_cxx -Wno-error=deprecated-register
11+
APP_PLATFORM := android-16
12+
APP_STL := gnustl_static
13+
NDK_TOOLCHAIN_VERSION := clang

api/baseapi.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ void TessBaseAPI::DumpPGM(const char* filename) {
742742
fclose(fp);
743743
}
744744

745+
#ifndef ANDROID_BUILD
745746
/**
746747
* Placeholder for call to Cube and test that the input data is correct.
747748
* reskew is the direction of baselines in the skewed image in
@@ -786,6 +787,7 @@ int CubeAPITest(Boxa* boxa_blocks, Pixa* pixa_blocks,
786787
ASSERT_HOST(pr_word == word_count);
787788
return 0;
788789
}
790+
#endif
789791

790792
/**
791793
* Runs page layout analysis in the mode set by SetPageSegMode.
@@ -1022,6 +1024,7 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data,
10221024
int timeout_millisec,
10231025
TessResultRenderer* renderer,
10241026
int tessedit_page_number) {
1027+
#ifndef ANDROID_BUILD
10251028
Pix *pix = NULL;
10261029
#ifdef USE_OPENCL
10271030
OpenclDevice od;
@@ -1052,6 +1055,9 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data,
10521055
if (tessedit_page_number >= 0) break;
10531056
}
10541057
return true;
1058+
#else
1059+
return false;
1060+
#endif
10551061
}
10561062

10571063
// Master ProcessPages calls ProcessPagesInternal and then does any post-
@@ -1087,6 +1093,7 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
10871093
const char* retry_config,
10881094
int timeout_millisec,
10891095
TessResultRenderer* renderer) {
1096+
#ifndef ANDROID_BUILD
10901097
PERF_COUNT_START("ProcessPages")
10911098
bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
10921099
if (stdInput) {
@@ -1174,6 +1181,9 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
11741181
}
11751182
PERF_COUNT_END
11761183
return true;
1184+
#else
1185+
return false;
1186+
#endif
11771187
}
11781188

11791189
bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
@@ -1207,8 +1217,10 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
12071217
failed = Recognize(NULL) < 0;
12081218
}
12091219
if (tesseract_->tessedit_write_images) {
1220+
#ifndef ANDROID_BUILD
12101221
Pix* page_pix = GetThresholdedImage();
12111222
pixWrite("tessinput.tif", page_pix, IFF_TIFF_G4);
1223+
#endif
12121224
}
12131225
if (failed && retry_config != NULL && retry_config[0] != '\0') {
12141226
// Save current config variables before switching modes.
@@ -2613,10 +2625,12 @@ int TessBaseAPI::NumDawgs() const {
26132625
return tesseract_ == NULL ? 0 : tesseract_->getDict().NumDawgs();
26142626
}
26152627

2628+
#ifndef ANDROID_BUILD
26162629
/** Return a pointer to underlying CubeRecoContext object if present. */
26172630
CubeRecoContext *TessBaseAPI::GetCubeRecoContext() const {
26182631
return (tesseract_ == NULL) ? NULL : tesseract_->GetCubeRecoContext();
26192632
}
2633+
#endif
26202634

26212635
/** Escape a char string - remove <>&"' with HTML codes. */
26222636
STRING HOcrEscape(const char* text) {

ccmain/control.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,14 @@ bool Tesseract::recog_all_words(PAGE_RES* page_res,
387387
// ****************** Pass 5,6 *******************
388388
rejection_passes(page_res, monitor, target_word_box, word_config);
389389

390+
#ifndef ANDROID_BUILD
390391
// ****************** Pass 7 *******************
391392
// Cube combiner.
392393
// If cube is loaded and its combiner is present, run it.
393394
if (tessedit_ocr_engine_mode == OEM_TESSERACT_CUBE_COMBINED) {
394395
run_cube_combiner(page_res);
395396
}
397+
#endif
396398

397399
// ****************** Pass 8 *******************
398400
font_recognition_pass(page_res);
@@ -986,11 +988,13 @@ void Tesseract::classify_word_pass1(const WordData& word_data,
986988
BLOCK* block = word_data.block;
987989
prev_word_best_choice_ = word_data.prev_word != NULL
988990
? word_data.prev_word->word->best_choice : NULL;
991+
#ifndef ANDROID_BUILD
989992
// If we only intend to run cube - run it and return.
990993
if (tessedit_ocr_engine_mode == OEM_CUBE_ONLY) {
991994
cube_word_pass1(block, row, *in_word);
992995
return;
993996
}
997+
#endif
994998
WERD_RES* word = *in_word;
995999
match_word_pass_n(1, word, row, block);
9961000
if (!word->tess_failed && !word->word->flag(W_REP_CHAR)) {

ccmain/paramsd.h

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

2626
#include "elst.h"
27+
#ifndef ANDROID_BUILD
2728
#include "scrollview.h"
29+
#endif
2830
#include "params.h"
2931
#include "tesseractclass.h"
3032

ccmain/tessedit.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ bool Tesseract::init_tesseract_lang_data(
194194
if (tessdata_manager_debug_level) tprintf("Loaded ambigs\n");
195195
}
196196

197-
// Load Cube objects if necessary.
197+
// The various OcrEngineMode settings (see publictypes.h) determine which
198+
// engine-specific data files need to be loaded. Currently everything needs
199+
// the base tesseract data, which supplies other useful information, but
200+
// alternative engines, such as cube and LSTM are optional.
201+
#ifndef ANDROID_BUILD
198202
if (tessedit_ocr_engine_mode == OEM_CUBE_ONLY) {
199203
ASSERT_HOST(init_cube_objects(false, &tessdata_manager));
200204
if (tessdata_manager_debug_level)
@@ -204,7 +208,7 @@ bool Tesseract::init_tesseract_lang_data(
204208
if (tessdata_manager_debug_level)
205209
tprintf("Loaded Cube with combiner\n");
206210
}
207-
211+
#endif
208212
// Init ParamsModel.
209213
// Load pass1 and pass2 weights (for now these two sets are the same, but in
210214
// the future separate sets of weights can be generated).
@@ -475,5 +479,4 @@ enum CMD_EVENTS
475479
RECOG_PSEUDO,
476480
ACTION_2_CMD_EVENT
477481
};
478-
479482
} // namespace tesseract

ccmain/tesseractclass.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@
3737
#include "tesseractclass.h"
3838

3939
#include "allheaders.h"
40+
#ifndef ANDROID_BUILD
4041
#include "cube_reco_context.h"
42+
#endif
4143
#include "edgblob.h"
4244
#include "equationdetect.h"
4345
#include "globals.h"
46+
#ifndef ANDROID_BUILD
4447
#include "tesseract_cube_combiner.h"
48+
#endif
4549

4650
// Include automatically generated configuration file if running autoconf.
4751
#ifdef HAVE_CONFIG_H
@@ -547,15 +551,18 @@ Tesseract::Tesseract()
547551
reskew_(1.0f, 0.0f),
548552
most_recently_used_(this),
549553
font_table_size_(0),
554+
#ifndef ANDROID_BUILD
550555
cube_cntxt_(NULL),
551556
tess_cube_combiner_(NULL),
557+
#endif
552558
equ_detect_(NULL) {
553559
}
554560

555561
Tesseract::~Tesseract() {
556562
Clear();
557563
end_tesseract();
558564
sub_langs_.delete_data_pointers();
565+
#ifndef ANDROID_BUILD
559566
// Delete cube objects.
560567
if (cube_cntxt_ != NULL) {
561568
delete cube_cntxt_;
@@ -565,6 +572,7 @@ Tesseract::~Tesseract() {
565572
delete tess_cube_combiner_;
566573
tess_cube_combiner_ = NULL;
567574
}
575+
#endif
568576
}
569577

570578
void Tesseract::Clear() {

ccmain/tesseractclass.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ class WERD_RES;
9797
namespace tesseract {
9898

9999
class ColumnFinder;
100+
#ifndef ANDROID_BUILD
100101
class CubeLineObject;
101102
class CubeObject;
102103
class CubeRecoContext;
104+
#endif
103105
class EquationDetect;
104106
class Tesseract;
107+
#ifndef ANDROID_BUILD
105108
class TesseractCubeCombiner;
109+
#endif
106110

107111
// A collection of various variables for statistics and debugging.
108112
struct TesseractStats {
@@ -382,6 +386,7 @@ class Tesseract : public Wordrec {
382386
int *right_ok) const;
383387

384388
//// cube_control.cpp ///////////////////////////////////////////////////
389+
#ifndef ANDROID_BUILD
385390
bool init_cube_objects(bool load_combiner,
386391
TessdataManager *tessdata_manager);
387392
// Iterates through tesseract's results and calls cube on each word,
@@ -407,6 +412,7 @@ class Tesseract : public Wordrec {
407412
Boxa** char_boxes, CharSamp*** char_samples);
408413
bool create_cube_box_word(Boxa *char_boxes, int num_chars,
409414
TBOX word_box, BoxWord* box_word);
415+
#endif
410416
//// output.h //////////////////////////////////////////////////////////
411417

412418
void output_pass(PAGE_RES_IT &page_res_it, const TBOX *target_word_box);
@@ -713,8 +719,8 @@ class Tesseract : public Wordrec {
713719
// Creates a fake best_choice entry in each WERD_RES with the correct text.
714720
void CorrectClassifyWords(PAGE_RES* page_res);
715721
// Call LearnWord to extract features for labelled blobs within each word.
716-
// Features are written to the given filename.
717-
void ApplyBoxTraining(const STRING& filename, PAGE_RES* page_res);
722+
// Features are stored in an internal buffer.
723+
void ApplyBoxTraining(const STRING& fontname, PAGE_RES* page_res);
718724

719725
//// fixxht.cpp ///////////////////////////////////////////////////////
720726
// Returns the number of misfit blob tops in this word.
@@ -1089,7 +1095,9 @@ class Tesseract : public Wordrec {
10891095
PAGE_RES_IT* pr_it,
10901096
FILE *output_file);
10911097

1098+
#ifndef ANDROID_BUILD
10921099
inline CubeRecoContext *GetCubeRecoContext() { return cube_cntxt_; }
1100+
#endif
10931101

10941102
private:
10951103
// The filename of a backup config file. If not null, then we currently
@@ -1129,9 +1137,11 @@ class Tesseract : public Wordrec {
11291137
Tesseract* most_recently_used_;
11301138
// The size of the font table, ie max possible font id + 1.
11311139
int font_table_size_;
1140+
#ifndef ANDROID_BUILD
11321141
// Cube objects.
11331142
CubeRecoContext* cube_cntxt_;
11341143
TesseractCubeCombiner *tess_cube_combiner_;
1144+
#endif
11351145
// Equation detector. Note: this pointer is NOT owned by the class.
11361146
EquationDetect* equ_detect_;
11371147
};

ccstruct/imagedata.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void WordFeature::ComputeSize(const GenericVector<WordFeature>& features,
5151
// Draws the features in the given window.
5252
void WordFeature::Draw(const GenericVector<WordFeature>& features,
5353
ScrollView* window) {
54+
#ifndef GRAPHICS_DISABLED
5455
for (int f = 0; f < features.size(); ++f) {
5556
FCOORD pos(features[f].x_, features[f].y_);
5657
FCOORD dir;
@@ -61,6 +62,7 @@ void WordFeature::Draw(const GenericVector<WordFeature>& features,
6162
window->DrawTo(IntCastRounded(pos.x() + dir.x()),
6263
IntCastRounded(pos.y() + dir.y()));
6364
}
65+
#endif
6466
}
6567

6668
// Writes to the given file. Returns false in case of error.
@@ -244,6 +246,7 @@ int ImageData::MemoryUsed() const {
244246

245247
// Draws the data in a new window.
246248
void ImageData::Display() const {
249+
#ifndef GRAPHICS_DISABLED
247250
const int kTextSize = 64;
248251
// Draw the image.
249252
Pix* pix = GetPix();
@@ -274,6 +277,7 @@ void ImageData::Display() const {
274277
win->Pen(ScrollView::GREEN);
275278
win->Update();
276279
window_wait(win);
280+
#endif
277281
}
278282

279283
// Adds the supplied boxes and transcriptions that correspond to the correct

textord/drawedg.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#ifndef DRAWEDG_H
2121
#define DRAWEDG_H
22+
#ifndef ANDROID_BUILD
2223

2324
#include "scrollview.h"
2425
#include "crakedge.h"
@@ -32,3 +33,4 @@ void draw_raw_edge( //draw the cracks
3233
ScrollView::Color colour //colour to draw in
3334
);
3435
#endif
36+
#endif

0 commit comments

Comments
 (0)