From 91d2265429fbf640be338c0c90b3e6d18af3972d Mon Sep 17 00:00:00 2001 From: "theraysmith@gmail.com" Date: Fri, 10 Jan 2014 01:38:00 +0000 Subject: [PATCH] More minor fixes from issues and cleanup git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@974 d0cd1f9f-072b-0410-8dd7-cf729c803f20 --- api/baseapi.cpp | 1 - api/tesseractmain.cpp | 18 ++++++++---------- ccstruct/otsuthr.cpp | 2 +- ccutil/hashfn.h | 6 +++--- ccutil/unichar.cpp | 2 +- classify/mastertrainer.cpp | 3 ++- cube/cube_line_segmenter.h | 4 ++-- cutil/emalloc.cpp | 4 ++-- cutil/emalloc.h | 4 ++-- tessdata/configs/hocr | 3 ++- textord/linefind.cpp | 9 ++++----- textord/makerow.h | 2 +- wordrec/language_model.cpp | 1 + 13 files changed, 29 insertions(+), 30 deletions(-) diff --git a/api/baseapi.cpp b/api/baseapi.cpp index c7b5e5bde9..38cfa983f2 100644 --- a/api/baseapi.cpp +++ b/api/baseapi.cpp @@ -1004,7 +1004,6 @@ bool TessBaseAPI::ProcessPages(const char* filename, if (npages > 0) { pixDestroy(&pix); for (; page < npages; ++page) { - // only use opencl if compiled w/ OpenCL and selected device is opencl #ifdef USE_OPENCL if ( od.selectedDeviceIsOpenCL() ) { diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index 970eb2631b..44c425c882 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -22,6 +22,12 @@ #include "config_auto.h" #endif +#ifdef _WIN32 +#include +#include +#endif // _WIN32 +#include + #include "allheaders.h" #include "baseapi.h" #include "basedir.h" @@ -30,14 +36,6 @@ #include "tprintf.h" #include "openclwrapper.h" -#include -#include - -#ifdef _WIN32 -#include -#include -#endif // _WIN32 - /********************************************************************** * main() * @@ -128,8 +126,8 @@ int main(int argc, char **argv) { } if (output == NULL && noocr == false) { - fprintf(stderr, "Usage:\n %s imagename|stdin outputbase|stdout [options...] " - "[configfile...]\n\n", argv[0]); + fprintf(stderr, "Usage:\n %s imagename|stdin outputbase|stdout " + "[options...] [configfile...]\n\n", argv[0]); fprintf(stderr, "OCR options:\n"); fprintf(stderr, " --tessdata-dir /path\tspecify location of tessdata" diff --git a/ccstruct/otsuthr.cpp b/ccstruct/otsuthr.cpp index 0423ca4807..5bd7399629 100644 --- a/ccstruct/otsuthr.cpp +++ b/ccstruct/otsuthr.cpp @@ -139,7 +139,7 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height, } #ifdef USE_OPENCL } -#endif // USE_OPENCL +#endif // USE_OPENCL delete[] histogramAllChannels; if (!any_good_hivalue) { diff --git a/ccutil/hashfn.h b/ccutil/hashfn.h index fe4343835b..257e7f29b0 100644 --- a/ccutil/hashfn.h +++ b/ccutil/hashfn.h @@ -33,10 +33,10 @@ using std::unordered_set; #endif #else // _MSC_VER #include -#define std::unique_ptr SmartPtr +#define SmartPtr std::unique_ptr #define HAVE_UNIQUE_PTR #endif // _MSC_VER -#elif (defined(__GNUC__) && (((__GNUC__ == 3) && ( __GNUC_MINOR__ > 0)) || \ +#elif (defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ > 0)) || \ __GNUC__ >= 4)) // gcc // hash_set is deprecated in gcc #include @@ -61,7 +61,7 @@ using __gnu_cxx::hash_set; template class SmartPtr { public: SmartPtr() : ptr_(NULL) {} - SmartPtr(T* ptr) : ptr_(ptr) {} + explicit SmartPtr(T* ptr) : ptr_(ptr) {} ~SmartPtr() { delete ptr_; } diff --git a/ccutil/unichar.cpp b/ccutil/unichar.cpp index 61fb548ef5..7e848116bd 100644 --- a/ccutil/unichar.cpp +++ b/ccutil/unichar.cpp @@ -31,7 +31,7 @@ UNICHAR::UNICHAR(const char* utf8_str, int len) { int total_len = 0; int step = 0; if (len < 0) { - for (len = 0; utf8_str[len] != 0 && len < UNICHAR_LEN; ++len); + for (len = 0; len < UNICHAR_LEN && utf8_str[len] != 0; ++len); } for (total_len = 0; total_len < len; total_len += step) { step = utf8_step(utf8_str + total_len); diff --git a/classify/mastertrainer.cpp b/classify/mastertrainer.cpp index 8a49baf065..67c0e62c08 100644 --- a/classify/mastertrainer.cpp +++ b/classify/mastertrainer.cpp @@ -397,8 +397,9 @@ bool MasterTrainer::LoadXHeights(const char* filename) { int total_xheight = 0; int xheight_count = 0; while (!feof(f)) { - if (fscanf(f, "%1024s %d\n", buffer, &xht) != 2) + if (fscanf(f, "%1023s %d\n", buffer, &xht) != 2) continue; + buffer[1023] = '\0'; fontinfo.name = buffer; if (!fontinfo_table_.contains(fontinfo)) continue; int fontinfo_id = fontinfo_table_.get_index(fontinfo); diff --git a/cube/cube_line_segmenter.h b/cube/cube_line_segmenter.h index 71facdf54b..43d19e57ec 100644 --- a/cube/cube_line_segmenter.h +++ b/cube/cube_line_segmenter.h @@ -45,7 +45,7 @@ class CubeLineSegmenter { } int ColumnCnt() { if (init_ == false && Init() == false) { - return NULL; + return 0; } return columns_->n; } @@ -58,7 +58,7 @@ class CubeLineSegmenter { } int LineCnt() { if (init_ == false && Init() == false) { - return NULL; + return 0; } return line_cnt_; diff --git a/cutil/emalloc.cpp b/cutil/emalloc.cpp index a9679c95b0..c806803aba 100644 --- a/cutil/emalloc.cpp +++ b/cutil/emalloc.cpp @@ -32,7 +32,7 @@ Public Code ----------------------------------------------------------------------------**/ /*---------------------------------------------------------------------------*/ -void *Emalloc(size_t Size) { +void *Emalloc(int Size) { /* ** Parameters: ** Size @@ -67,7 +67,7 @@ void *Emalloc(size_t Size) { /*---------------------------------------------------------------------------*/ -void *Erealloc(void *ptr, size_t size) { +void *Erealloc(void *ptr, int size) { void *Buffer; if (size < 0 || (size == 0 && ptr == NULL)) diff --git a/cutil/emalloc.h b/cutil/emalloc.h index fd32b82bd0..6fda20a596 100644 --- a/cutil/emalloc.h +++ b/cutil/emalloc.h @@ -30,9 +30,9 @@ /**---------------------------------------------------------------------------- Public Function Prototypes ----------------------------------------------------------------------------**/ -void *Emalloc(size_t Size); +void *Emalloc(int Size); -void *Erealloc(void *ptr, size_t size); +void *Erealloc(void *ptr, int size); void Efree(void *ptr); diff --git a/tessdata/configs/hocr b/tessdata/configs/hocr index 72f83e89c8..2bf1d848c4 100644 --- a/tessdata/configs/hocr +++ b/tessdata/configs/hocr @@ -1 +1,2 @@ -tessedit_create_hocr 1 \ No newline at end of file +tessedit_create_hocr 1 +tessedit_pageseg_mode 1 diff --git a/textord/linefind.cpp b/textord/linefind.cpp index e3fc20c75f..ac81566f55 100644 --- a/textord/linefind.cpp +++ b/textord/linefind.cpp @@ -577,7 +577,6 @@ void LineFinder::GetLineMasks(int resolution, Pix* src_pix, Pix** pix_hline, Pix** pix_non_hline, Pix** pix_intersections, Pix** pix_music_mask, Pixa* pixa_display) { - Pix* pix_closed = NULL; Pix* pix_hollow = NULL; @@ -593,7 +592,7 @@ void LineFinder::GetLineMasks(int resolution, Pix* src_pix, // only use opencl if compiled w/ OpenCL and selected device is opencl #ifdef USE_OPENCL if (OpenclDevice::selectedDeviceIsOpenCL()) { - //OpenCL pixGetLines Operation + // OpenCL pixGetLines Operation int clStatus = OpenclDevice::initMorphCLAllocations(pixGetWpl(src_pix), pixGetHeight(src_pix), src_pix); @@ -617,9 +616,9 @@ void LineFinder::GetLineMasks(int resolution, Pix* src_pix, if (pixa_display != NULL) pixaAddPix(pixa_display, pix_solid, L_CLONE); pix_hollow = pixSubtract(NULL, pix_closed, pix_solid); - + pixDestroy(&pix_solid); - + // Now open up in both directions independently to find lines of at least // 1 inch/kMinLineLengthFraction in length. if (pixa_display != NULL) @@ -627,7 +626,7 @@ void LineFinder::GetLineMasks(int resolution, Pix* src_pix, *pix_vline = pixOpenBrick(NULL, pix_hollow, 1, min_line_length); *pix_hline = pixOpenBrick(NULL, pix_hollow, min_line_length, 1); - pixDestroy(&pix_hollow); + pixDestroy(&pix_hollow); #ifdef USE_OPENCL } #endif diff --git a/textord/makerow.h b/textord/makerow.h index ec4acfba01..508ae6f923 100644 --- a/textord/makerow.h +++ b/textord/makerow.h @@ -111,7 +111,7 @@ extern double_VAR_H (textord_xheight_error_margin, 0.1, "Accepted variation"); extern INT_VAR_H (textord_lms_line_trials, 12, "Number of linew fits to do"); extern BOOL_VAR_H (textord_new_initial_xheight, TRUE, "Use test xheight mechanism"); -extern BOOL_VAR_H (textord_debug_blob, FALSE, "Print test blob information"); +extern BOOL_VAR_H(textord_debug_blob, FALSE, "Print test blob information"); inline void get_min_max_xheight(int block_linesize, int *min_height, int *max_height) { diff --git a/wordrec/language_model.cpp b/wordrec/language_model.cpp index 305e71205a..50ae68b722 100644 --- a/wordrec/language_model.cpp +++ b/wordrec/language_model.cpp @@ -624,6 +624,7 @@ bool LanguageModel::AddViterbiStateEntry( tprintf("Language model components early pruned this entry\n"); } delete ngram_info; + delete dawg_info; return false; }