Commit Graph

883 Commits

Author SHA1 Message Date
Stefan Weil
38f348627b training: Add missing static attributes
That fixes several warnings from clang++ like the following one:

    src/training/combine_lang_model.cpp:36:1: warning: no previous extern declaration for non-static variable 'FLAGS_lang_is_rtl' [-Wmissing-variable-declarations]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:29:49 +02:00
Stefan Weil
66e5689167 training: Move declarations from cpp files to h file
That fixes several warnings from clang++ like the following one:

    src/training/commontraining.cpp:95:1: warning: no previous extern declaration for non-static variable 'FLAGS_D' [-Wmissing-variable-declarations]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:29:37 +02:00
Stefan Weil
6dfb049ccf featdefs: Add missing include statement
It is needed for PicoFeatureLength. This fixes a compiler warning.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:29:26 +02:00
Stefan Weil
b4a7f51cd6 Add missing static attributes
This fixes lots of compiler warnings like these ones:

    src/api/baseapi.cpp:113:13: warning: no previous extern declaration for non-static variable 'kInputFile' [-Wmissing-variable-declarations]
    src/api/baseapi.cpp:117:13: warning: no previous extern declaration for non-static variable 'kOldVarsFile' [-Wmissing-variable-declarations]
    src/api/baseapi.cpp:97:10: warning: no previous extern declaration for non-static variable 'stream_filelist' [-Wmissing-variable-declarations]
    src/ccmain/equationdetect.cpp:46:10: warning: no previous extern declaration for non-static variable 'equationdetect_save_bi_image' [-Wmissing-variable-declarations]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:29:15 +02:00
Stefan Weil
7f32cb659b bits16: Modernize code
This also fixes warnings like the following one from clang++:

    src/ccmain/pgedit.cpp:114:15: warning: declaration requires a global constructor [-Wglobal-constructors]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:29:05 +02:00
Stefan Weil
2160ebfd03 unicodes: Optimize code by using constexpr and removing unused globals
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:28:33 +02:00
Stefan Weil
cb6cf802e0 featdefs: Optimize code by using constexpr
This also fixes some warnings from clang++:

    src/classify/featdefs.cpp:47:15: warning: declaration requires a global constructor [-Wglobal-constructors]
    src/classify/featdefs.cpp:57:15: warning: declaration requires a global constructor [-Wglobal-constructors]
    src/classify/featdefs.cpp:66:15: warning: declaration requires a global constructor [-Wglobal-constructors]
    src/classify/featdefs.cpp:75:15: warning: declaration requires a global constructor [-Wglobal-constructors]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:28:23 +02:00
Stefan Weil
a4e1378218 Fix broken build for Leptonica < 1.77
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:28:06 +02:00
Stefan Weil
9e23dc2857 Remove classify/cutoffs.h
It only defined CLASS_CUTOFF_ARRAY and some unused definitions.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:27:57 +02:00
zdenop
8b875c00ad fix '--enable-visibility' build 2019-06-16 18:27:28 +02:00
Stefan Weil
227452f872 Replace Tensorflow by TensorFlow
The name is written in camel case, see https://www.tensorflow.org/.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:27:08 +02:00
Stefan Weil
6c68f08460 Implement check for Tensorflow header file
This looks for one of the header files which are included by Tesseract.
It currently uses a hard coded path which works for Debian / Ubuntu.

Simplify also the rules for linking Tensorflow.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:26:42 +02:00
Stefan Weil
bed089092a Remove "third_party/" in comments and update path names
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:26:28 +02:00
Stefan Weil
b7537e94a0 Support build with Tensorflow
It expects include files in /usr/include/tensorflow.

* Add configure option --with-tensorflow (disabled by default)
* Fix data type tensorflow::int64
* Remove "third_party/" in include statements
* Add dummy implementations for Backward and DebugWeights in TFNetwork
* Add files generated with protoc from tfnetwork.proto
  (so the Tensorflow sources are not needed for the build)
* Update Makefiles

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:26:18 +02:00
Zdenko Podobný
e27a07e0c7 fix missing tiff format 2019-06-16 18:24:24 +02:00
Stefan Weil
0d824a600d lstmtrainer: Set constant kLearningRateDecay at compile time
sqrt(0.5) = 1 / sqrt(2) can be replaced by the macro M_SQRT1_2.

This also fixes a compiler warning:

    src/lstm/lstmtrainer.cpp:51:14: warning: declaration requires a global constructor [-Wglobal-constructors]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:24:12 +02:00
Bharat123rox
40216e5a5e Fix bug in max_max_dist 2019-06-16 18:23:01 +02:00
Bharat123rox
a324c88563 Fix LGTM and revert bugfix for later PR 2019-06-16 18:22:50 +02:00
Bharat123rox
5f084891be Fix syntax error 2019-06-16 18:22:34 +02:00
Stefan Weil
26f05b1197 Remove SavePixForCrash and related code
That debugging code uses very much memory and is no longer useful.

    text	   data	    bss	    dec	    hex	filename
     815	      0	 262144	 262959	  4032f	src/ccutil/globaloc.o

Remove also the function err_exit which was only used in ccmain/reject.cpp.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:22:21 +02:00
Stefan Weil
7b4b330176 tprintf: Make code reentrant and use less memory
Reduce the maximum message size from 64 KiB to 2 KiB which still should
be large enought for trace messages.

Create the smaller message on the stack instead of using a global
array to allow reentrancy and to reduce the memory use of Tesseract.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:22:03 +02:00
Bharat123rox
19274eebbb Some LGTM fixes and potential bugfixes 2019-06-16 18:21:36 +02:00
Stefan Weil
0190f398bd Remove local definition of M_PI
It is defined for all platforms when math.h or cmath is included
after defining the macro _USE_MATH_DEFINES.

Define _USE_MATH_DEFINES before any include statement to make sure
that M_PI gets defined. It is not necessary to define it conditionally
only for Windows.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:21:16 +02:00
Stefan Weil
2b75680e97 Fix compiler warnings
This fixes lots of warnings related to ERRCODE like the following one:

    src/ccutil/errcode.h:81:15: warning:
      declaration requires a global constructor [-Wglobal-constructors]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-06-16 18:20:32 +02:00
James R. Barlow
caee962da8 Fix text2image compilation on C++17 compilers
C++17 drops support for `std::random_shuffle`, breaking C++17 compilers
that run to compile text2image.cpp. std::shuffle is valid on C++11
through C++17, so use std::shuffle instead.

Due to the use `std::random_shuffle`, `text2image --render_ngrams`
would not give consistent results for different compilers or platforms.
With the current change, the same random number generator is used for
all platforms and initialized to the same seed, so training output
should be consistent.
2019-06-14 01:26:28 -07:00
Stefan Weil
3452c8ebee Fix out-of-bounds writes in Classify::ReadNewCutoffs
The function did not correctly read Chinese unichars into the local
Class variable if the locale was set to de_DE.UTF-8 (or other
incompatible locales). That resulted in a wrong ClassId which was
used to write into the Cutoffs array without checking for valid bounds.

On macOS the result was a runtime error in baseapi_test (see GitHub
issue #1250):

    [ RUN      ] TesseractTest.InitConfigOnlyTest
    baseapi_test(21845,0x1134c45c0) malloc: *** error for object 0x927f96c28005e0: pointer being freed was not allocated
    baseapi_test(21845,0x1134c45c0) malloc: *** set a breakpoint in malloc_error_break to debug

Replacing sscanf by std::istringstream fixes that.
Add also an assertion to catch future out-of-bounds writes.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-18 13:59:48 +02:00
Stefan Weil
d81f6a07a1 oldlist: Fix comments
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-17 14:41:11 +02:00
Stefan Weil
d0a43101c3 Remove space at line endings
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-17 14:36:45 +02:00
Nick White
c0c53c785f Add different classes to hocr output depending on BlockType
These classes are taken from the hOCR specification, and seem
to map well onto the BlockType types. There are probably more that
could be added.
2019-05-17 14:34:20 +02:00
Stefan Weil
96f6fc28b8 Remove assertions for unsupported locale settings
The latest code passed all unittests with locale de_DE.UTF-8
and has fixed the locale issues which were reported on GitHub.
Therefore the assertions can be removed.

Any remaining locale issue will be fixed when it is identified.
To help finding such remaining isses, debug code now uses the
user's locale settings instead of the default "C" locale for all
executables which use TessBaseAPI.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:24:02 +02:00
Stefan Weil
fb926243bd Fix UNICHARSET::save_to_string for locale de_DE.UTF-8
That function writes float values which must always use '.' as the
decimal separator, no matter what the current locale setting is.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:23:40 +02:00
Stefan Weil
728f5d937f Fix baseapi_test with locale de_DE.UTF-8
The unittest failed with LANG=de_DE.UTF-8:

    $ unittest/baseapi_test
    Running main() from ../../../../unittest/../googletest/googletest/src/gtest_main.cc
    [==========] Running 12 tests from 2 test suites.
    [----------] Global test environment set-up.
    [----------] 10 tests from TesseractTest
    [ RUN      ] TesseractTest.ArraySizeTest
    [       OK ] TesseractTest.ArraySizeTest (0 ms)
    [ RUN      ] TesseractTest.BasicTesseractTest
    [       OK ] TesseractTest.BasicTesseractTest (1251 ms)
    [ RUN      ] TesseractTest.IteratesParagraphsEvenIfNotDetected
    [       OK ] TesseractTest.IteratesParagraphsEvenIfNotDetected (347 ms)
    [ RUN      ] TesseractTest.HOCRWorksWithoutSetInputName
    [       OK ] TesseractTest.HOCRWorksWithoutSetInputName (403 ms)
    [ RUN      ] TesseractTest.HOCRContainsBaseline
    [       OK ] TesseractTest.HOCRContainsBaseline (389 ms)
    [ RUN      ] TesseractTest.RickSnyderNotFuckSnyder
    [       OK ] TesseractTest.RickSnyderNotFuckSnyder (346 ms)
    [ RUN      ] TesseractTest.AdaptToWordStrTest
    Trying to adapt "136
    " to "1 3 6"
    Trying to adapt "256
    " to "2 5 6"
    Trying to adapt "410
    " to "4 1 0"
    Trying to adapt "432
    " to "4 3 2"
    Trying to adapt "540
    " to "5 4 0"
    Trying to adapt "692
    " to "6 9 2"
    Trying to adapt "779
    " to "7 7 9"
    Trying to adapt "793
    " to "7 9 3"
    Trying to adapt "808
    " to "8 0 8"
    Trying to adapt "815
    " to "8 1 5"
    Trying to adapt "12
    " to "1 2"
    Trying to adapt "12
    " to "1 2"
    [       OK ] TesseractTest.AdaptToWordStrTest (788 ms)
    [ RUN      ] TesseractTest.BasicLSTMTest
    [       OK ] TesseractTest.BasicLSTMTest (4525 ms)
    [ RUN      ] TesseractTest.LSTMGeometryTest
    [       OK ] TesseractTest.LSTMGeometryTest (615 ms)
    [ RUN      ] TesseractTest.InitConfigOnlyTest
    Error: unichar ? in normproto file is not in unichar set.
    Error: unichar 0.232621 in normproto file is not in unichar set.
    Error: unichar 0.000400 in normproto file is not in unichar set.
    Error: unichar 0.231864 in normproto file is not in unichar set.
    [...]
    Error: unichar ? in normproto file is not in unichar set.
    Error: unichar 0.233915 in normproto file is not in unichar set.
    Error: unichar 0.000400 in normproto file is not in unichar set.
    Error: unichar 0.221755 in normproto file is not in unichar set.
    Error: unichar 0.000400 in normproto file is not in unichar set.
    Error: unichar ? in normproto file is not in unichar set.
    baseapi_test(21845,0x1134c45c0) malloc: *** error for object 0x927f96c28005e0: pointer being freed was not allocated
    baseapi_test(21845,0x1134c45c0) malloc: *** set a breakpoint in malloc_error_break to debug
    [INFO]  Lang eng took 327ms in regular init
    [INFO]  Lang chi_tra took 1422ms in regular init
    Abort trap: 6

TesseractTest.InitConfigOnlyTest is fixed by using std::istringstream
instead of sscanf.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:23:24 +02:00
Stefan Weil
c2444e75e4 Fix apiexample_test with locale de_DE.UTF-8
The unittest failed with LANG=de_DE.UTF-8:

    $ unittest/apiexample_test
    Running main() from ../../../../unittest/../googletest/googletest/src/gtest_main.cc
    [==========] Running 4 tests from 2 test suites.
    [----------] Global test environment set-up.
    [----------] 1 test from EuroText
    [ RUN      ] EuroText.FastLatinOCR
    contains_unichar_id(unichar_id):Error:Assert failed:in file ../../../../../src/ccutil/unicharset.h, line 874

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:21:01 +02:00
Stefan Weil
bf74471113 Fix Doxygen comments for void functions
Void functions should not use @return. It causes compiler warnings
like this one:

    src/classify/intproto.cpp:326:5: warning:
      '@return' command used in a comment that is attached to a function
      returning void [-Wdocumentation]

Some non-void functions also were documented with @return none.
Fix those comments, too.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:19:01 +02:00
Stefan Weil
9bc576fafc normmatch: Remove unused private function
PrintNormMatch was unused. Remove it and remove also an unused prototype.
Make the only remaining private function NormEvidenceOf static.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:18:44 +02:00
Stefan Weil
25f2e0cb10 Replace sscanf by std::istringstream
Using std::istringstream allows conversion of string to float
independent of the current locale setting.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:18:06 +02:00
Stefan Weil
8cc751136d Fix reading of parameter from traineddata normproto component
The NonEssential parameter was wrongly derived from linear_token instead
of essential_token and therefore always set to true.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:17:51 +02:00
Stefan Weil
73a08678dc Fix Doxygen comment
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:17:16 +02:00
Stefan Weil
70ffe33976 Fix cast from pointer to integer type
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-16 20:16:56 +02:00
zdenop
57bf215d14 ScrollView: remove custom implementation of GetAddrInfo 2019-05-05 20:03:50 +02:00
zdenop
9cd60b2b90 remove unused include 2019-05-05 20:03:50 +02:00
Stefan Weil
98be949f5d tesscallback: Remove more unused code
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-05 20:03:50 +02:00
Stefan Weil
3ae4069411 tesscallback: Remove unused code
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-05 20:03:50 +02:00
zdenop
c4bb4b933b correct tessdata comment in baseapi.h 2019-05-04 14:35:41 +02:00
Stefan Weil
78ed5ef8b9 universalambigs: Add missing include file
This allows fixing two compiler warnings from clang++:

    src/ccutil/universalambigs.cpp:23:19: warning: no previous extern declaration for non-static variable 'kUniversalAmbigsFile' [-Wmissing-variable-declarations]
    src/ccutil/universalambigs.cpp:19019:18: warning: no previous extern declaration for non-static variable 'ksizeofUniversalAmbigsFile' [-Wmissing-variable-declarations]

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-04 14:35:41 +02:00
Stefan Weil
a8c8a96107 commandlineflags: Replace strtod by std::stringstream
Using std::stringstream allows conversion of double to string
independent of the current locale setting.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-04 14:34:58 +02:00
Stefan Weil
8831cbfead paramsd: Replace strtod by std::stringstream
Using std::stringstream allows conversion of double to string
independent of the current locale setting.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-04 14:34:58 +02:00
Stefan Weil
231da0064a clusttool: Replace strtof by std::stringstream
Using std::stringstream allows conversion of float to string
independent of the current locale setting.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-04 14:34:58 +02:00
Stefan Weil
97f6711ce0 clusttool: Remove unused code and some global functions
* WriteProtoList is unused. Remove it.

* ReadNFloats, WriteNFloats and WriteProtoStyle are only used locally,
  so make them local.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-04 14:34:34 +02:00
Stefan Weil
1d14d15902 Fix some typos (most found and fixed by codespell)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2019-05-04 14:34:34 +02:00