Skip to content

Commit

Permalink
Merge conflict: going with Ray's version
Browse files Browse the repository at this point in the history
  • Loading branch information
jimregan committed May 13, 2015
2 parents d508751 + 03f3c9d commit b13691f
Show file tree
Hide file tree
Showing 139 changed files with 7,146 additions and 6,431 deletions.
4 changes: 4 additions & 0 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!--
This file is needed by the android_native_library rule to determine the
project directory for ndk-build.
-->
1 change: 1 addition & 0 deletions android/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXTRA_DIST = AndroidManifest.xml jni/Android.mk jni/Application.mk
57 changes: 57 additions & 0 deletions android/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := tesseract-$(APP_ABI)

LOCAL_STATIC_LIBRARIES := \
mobile_base \
leptonica-$(APP_ABI)

LOCAL_C_INCLUDES := $(APP_C_INCLUDES)

LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/../../api \
$(LOCAL_PATH)/../../ccmain\
$(LOCAL_PATH)/../../ccstruct\
$(LOCAL_PATH)/../../ccutil\
$(LOCAL_PATH)/../../classify\
$(LOCAL_PATH)/../../cutil\
$(LOCAL_PATH)/../../dict\
$(LOCAL_PATH)/../../image\
$(LOCAL_PATH)/../../textord\
$(LOCAL_PATH)/../../third_party\
$(LOCAL_PATH)/../../wordrec\
$(LOCAL_PATH)/../../opencl\
$(LOCAL_PATH)/../../viewer\
$(LOCAL_PATH)/../../../leptonica/include

$(info local c includes=$(LOCAL_C_INCLUDES))
$(info local path=$(LOCAL_PATH))
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)

EXPLICIT_SRC_EXCLUDES := \
$(LOCAL_PATH)/../../ccmain/cubeclassifier.cpp \
$(LOCAL_PATH)/../../ccmain/cubeclassifier.h \
$(LOCAL_PATH)/../../ccmain/cube_control.cpp \
$(LOCAL_PATH)/../../ccmain/cube_reco_context.cpp \
$(LOCAL_PATH)/../../ccmain/cube_reco_context.h \
$(LOCAL_PATH)/../../ccmain/tesseract_cube_combiner.cpp \
$(LOCAL_PATH)/../../ccmain/tesseract_cube_combiner.h \
$(LOCAL_PATH)/../../api/pdfrenderer.cpp \
$(LOCAL_PATH)/../../api/tesseractmain.cpp \

LOCAL_SRC_FILES := $(filter-out $(EXPLICIT_SRC_EXCLUDES), $(LOCAL_SRC_FILES))

LOCAL_SRC_FILES := $(LOCAL_SRC_FILES:$(LOCAL_PATH)/%=%)

$(info local src files = $(LOCAL_SRC_FILES))

LOCAL_LDLIBS := -ldl -llog -ljnigraphics
LOCAL_CFLAGS := -DANDROID_BUILD -DGRAPHICS_DISABLED

include $(BUILD_SHARED_LIBRARY)

$(call import-module,mobile/base)
$(call import-module,mobile/base)
$(call import-module,mobile/util/hash)
$(call import-module,third_party/leptonica/android/jni)
13 changes: 13 additions & 0 deletions android/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Include common.mk for building google3 native code.
DEPOT_PATH := $(firstword $(subst /google3, ,$(abspath $(call my-dir))))
ifneq ($(wildcard $(DEPOT_PATH)/google3/mobile/build/common.mk),)
include $(DEPOT_PATH)/google3/mobile/build/common.mk
else
include $(DEPOT_PATH)/READONLY/google3/mobile/build/common.mk
endif

# Specify the hash namespace that we're using, based on the APP_STL we're using.
APP_CFLAGS += -Werror -DHASH_NAMESPACE=__gnu_cxx -Wno-error=deprecated-register
APP_PLATFORM := android-16
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := clang
43 changes: 39 additions & 4 deletions api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "allheaders.h"

#include "baseapi.h"
#include "blobclass.h"
#include "resultiterator.h"
#include "mutableiterator.h"
#include "thresholder.h"
Expand Down Expand Up @@ -745,6 +746,7 @@ void TessBaseAPI::DumpPGM(const char* filename) {
fclose(fp);
}

#ifndef ANDROID_BUILD
/**
* Placeholder for call to Cube and test that the input data is correct.
* reskew is the direction of baselines in the skewed image in
Expand Down Expand Up @@ -789,6 +791,7 @@ int CubeAPITest(Boxa* boxa_blocks, Pixa* pixa_blocks,
ASSERT_HOST(pr_word == word_count);
return 0;
}
#endif

/**
* Runs page layout analysis in the mode set by SetPageSegMode.
Expand Down Expand Up @@ -874,7 +877,9 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {
page_res_ = NULL;
return -1;
} else if (tesseract_->tessedit_train_from_boxes) {
tesseract_->ApplyBoxTraining(*output_file_, page_res_);
STRING fontname;
ExtractFontName(*output_file_, &fontname);
tesseract_->ApplyBoxTraining(fontname, page_res_);
} else if (tesseract_->tessedit_ambigs_training) {
FILE *training_output_file = tesseract_->init_recog_training(*input_file_);
// OCR the page segmented into words by tesseract.
Expand Down Expand Up @@ -1023,6 +1028,7 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data,
int timeout_millisec,
TessResultRenderer* renderer,
int tessedit_page_number) {
#ifndef ANDROID_BUILD
Pix *pix = NULL;
#ifdef USE_OPENCL
OpenclDevice od;
Expand Down Expand Up @@ -1053,6 +1059,26 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data,
if (tessedit_page_number >= 0) break;
}
return true;
#else
return false;
#endif
}

// Master ProcessPages calls ProcessPagesInternal and then does any post-
// processing required due to being in a training mode.
bool TessBaseAPI::ProcessPages(const char* filename, const char* retry_config,
int timeout_millisec,
TessResultRenderer* renderer) {
bool result =
ProcessPagesInternal(filename, retry_config, timeout_millisec, renderer);
if (result) {
if (tesseract_->tessedit_train_from_boxes &&
!tesseract_->WriteTRFile(*output_file_)) {
tprintf("Write of TR file failed: %s\n", output_file_->string());
return false;
}
}
return result;
}

// In the ideal scenario, Tesseract will start working on data as soon
Expand All @@ -1067,9 +1093,11 @@ bool TessBaseAPI::ProcessPagesMultipageTiff(const l_uint8 *data,
// identify the scenario that really matters: filelists on
// stdin. We'll still do our best if the user likes pipes. That means
// piling up any data coming into stdin into a memory buffer.
bool TessBaseAPI::ProcessPages(const char* filename,
const char* retry_config, int timeout_millisec,
TessResultRenderer* renderer) {
bool TessBaseAPI::ProcessPagesInternal(const char* filename,
const char* retry_config,
int timeout_millisec,
TessResultRenderer* renderer) {
#ifndef ANDROID_BUILD
PERF_COUNT_START("ProcessPages")
bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
if (stdInput) {
Expand Down Expand Up @@ -1157,6 +1185,9 @@ bool TessBaseAPI::ProcessPages(const char* filename,
}
PERF_COUNT_END
return true;
#else
return false;
#endif
}

bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
Expand Down Expand Up @@ -1190,8 +1221,10 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
failed = Recognize(NULL) < 0;
}
if (tesseract_->tessedit_write_images) {
#ifndef ANDROID_BUILD
Pix* page_pix = GetThresholdedImage();
pixWrite("tessinput.tif", page_pix, IFF_TIFF_G4);
#endif
}
if (failed && retry_config != NULL && retry_config[0] != '\0') {
// Save current config variables before switching modes.
Expand Down Expand Up @@ -2596,10 +2629,12 @@ int TessBaseAPI::NumDawgs() const {
return tesseract_ == NULL ? 0 : tesseract_->getDict().NumDawgs();
}

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

/** Escape a char string - remove <>&"' with HTML codes. */
STRING HOcrEscape(const char* text) {
Expand Down
8 changes: 5 additions & 3 deletions api/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,11 @@ class TESS_API TessBaseAPI {
*
* Returns true if successful, false on error.
*/
bool ProcessPages(const char* filename,
const char* retry_config, int timeout_millisec,
TessResultRenderer* renderer);
bool ProcessPages(const char* filename, const char* retry_config,
int timeout_millisec, TessResultRenderer* renderer);
// Does the real work of ProcessPages.
bool ProcessPagesInternal(const char* filename, const char* retry_config,
int timeout_millisec, TessResultRenderer* renderer);

/**
* Turn a single image into symbolic text.
Expand Down
Loading

0 comments on commit b13691f

Please sign in to comment.