motion-ocr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +10 -0
  4. data/LICENSE +28 -0
  5. data/README.md +22 -0
  6. data/Rakefile +17 -0
  7. data/app/app_delegate.rb +2 -0
  8. data/lib/motion-ocr.rb +26 -0
  9. data/lib/motion-ocr/version.rb +3 -0
  10. data/motion-ocr.gemspec +20 -0
  11. data/resources/tessdata/configs/nodict +3 -0
  12. data/resources/tessdata/eng.traineddata +0 -0
  13. data/spec/motion_ocr_spec.rb +23 -0
  14. data/spec/support/phototest.gif +0 -0
  15. data/vendor/MotionOCR/MotionOCR.bridgesupport +14722 -0
  16. data/vendor/MotionOCR/MotionOCR.xcodeproj/project.pbxproj +390 -0
  17. data/vendor/MotionOCR/MotionOCR.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  18. data/vendor/MotionOCR/MotionOCR.xcodeproj/project.xcworkspace/xcuserdata/fer.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  19. data/vendor/MotionOCR/MotionOCR.xcodeproj/xcuserdata/fer.xcuserdatad/xcschemes/MotionOCR.xcscheme +59 -0
  20. data/vendor/MotionOCR/MotionOCR.xcodeproj/xcuserdata/fer.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
  21. data/vendor/MotionOCR/MotionOCR/MotionOCR-Prefix.pch +7 -0
  22. data/vendor/MotionOCR/MotionOCR/MotionOCR.h +22 -0
  23. data/vendor/MotionOCR/MotionOCR/MotionOCR.mm +89 -0
  24. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/allheaders.h +32 -0
  25. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/alltypes.h +49 -0
  26. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/array.h +125 -0
  27. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/arrayaccess.h +194 -0
  28. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/bbuffer.h +46 -0
  29. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/bmf.h +51 -0
  30. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/bmp.h +74 -0
  31. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/ccbord.h +103 -0
  32. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/dewarp.h +57 -0
  33. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/endianness.h +11 -0
  34. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/environ.h +281 -0
  35. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/freetype.h +23 -0
  36. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/gplot.h +77 -0
  37. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/heap.h +73 -0
  38. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/imageio.h +153 -0
  39. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/jbclass.h +122 -0
  40. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/leptprotos.h +2058 -0
  41. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/leptwin.h +34 -0
  42. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/list.h +76 -0
  43. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/morph.h +218 -0
  44. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/pix.h +945 -0
  45. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/ptra.h +80 -0
  46. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/queue.h +63 -0
  47. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/readbarcode.h +220 -0
  48. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/regutils.h +122 -0
  49. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/stack.h +55 -0
  50. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/sudoku.h +62 -0
  51. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/watershed.h +52 -0
  52. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/apitypes.h +31 -0
  53. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/baseapi.h +664 -0
  54. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/errcode.h +104 -0
  55. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/genericvector.h +763 -0
  56. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/helpers.h +139 -0
  57. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/host.h +180 -0
  58. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/ndminx.h +31 -0
  59. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/ocrclass.h +335 -0
  60. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/platform.h +48 -0
  61. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/publictypes.h +202 -0
  62. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/tesscallback.h +1238 -0
  63. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/thresholder.h +170 -0
  64. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/unichar.h +85 -0
  65. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/lib/liblept.a +0 -0
  66. data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/lib/libtesseract_all.a +0 -0
  67. metadata +113 -0
@@ -0,0 +1,55 @@
1
+ /*====================================================================*
2
+ - Copyright (C) 2001 Leptonica. All rights reserved.
3
+ - This software is distributed in the hope that it will be
4
+ - useful, but with NO WARRANTY OF ANY KIND.
5
+ - No author or distributor accepts responsibility to anyone for the
6
+ - consequences of using this software, or for whether it serves any
7
+ - particular purpose or works at all, unless he or she says so in
8
+ - writing. Everyone is granted permission to copy, modify and
9
+ - redistribute this source code, for commercial or non-commercial
10
+ - purposes, with the following restrictions: (1) the origin of this
11
+ - source code must not be misrepresented; (2) modified versions must
12
+ - be plainly marked as such; and (3) this notice may not be removed
13
+ - or altered from any source or modified source distribution.
14
+ *====================================================================*/
15
+
16
+ #ifndef LEPTONICA_STACK_H
17
+ #define LEPTONICA_STACK_H
18
+
19
+ /*
20
+ * stack.h
21
+ *
22
+ * Expandable pointer stack for arbitrary void* data.
23
+ *
24
+ * The L_Stack is an array of void * ptrs, onto which arbitrary
25
+ * objects can be stored. At any time, the number of
26
+ * stored objects is stack->n. The object at the bottom
27
+ * of the stack is at array[0]; the object at the top of
28
+ * the stack is at array[n-1]. New objects are added
29
+ * to the top of the stack, at the first available location,
30
+ * which is array[n]. Objects are removed from the top of the
31
+ * stack. When an attempt is made to remove an object from an
32
+ * empty stack, the result is null. When the stack becomes
33
+ * filled, so that n = nalloc, the size is doubled.
34
+ *
35
+ * The auxiliary stack can be used to store and remove
36
+ * objects for re-use. It must be created by a separate
37
+ * call to pstackCreate(). [Just imagine the chaos if
38
+ * pstackCreate() created the auxiliary stack!]
39
+ * pstackDestroy() checks for the auxiliary stack and removes it.
40
+ */
41
+
42
+
43
+ /* Note that array[n] is the first null ptr in the array */
44
+ struct L_Stack
45
+ {
46
+ l_int32 nalloc; /* size of ptr array */
47
+ l_int32 n; /* number of stored elements */
48
+ void **array; /* ptr array */
49
+ struct L_Stack *auxstack; /* auxiliary stack */
50
+ };
51
+ typedef struct L_Stack L_STACK;
52
+
53
+
54
+ #endif /* LEPTONICA_STACK_H */
55
+
@@ -0,0 +1,62 @@
1
+ /*====================================================================*
2
+ - Copyright (C) 2001 Leptonica. All rights reserved.
3
+ - This software is distributed in the hope that it will be
4
+ - useful, but with NO WARRANTY OF ANY KIND.
5
+ - No author or distributor accepts responsibility to anyone for the
6
+ - consequences of using this software, or for whether it serves any
7
+ - particular purpose or works at all, unless he or she says so in
8
+ - writing. Everyone is granted permission to copy, modify and
9
+ - redistribute this source code, for commercial or non-commercial
10
+ - purposes, with the following restrictions: (1) the origin of this
11
+ - source code must not be misrepresented; (2) modified versions must
12
+ - be plainly marked as such; and (3) this notice may not be removed
13
+ - or altered from any source or modified source distribution.
14
+ *====================================================================*/
15
+
16
+ #ifndef SUDOKU_H_INCLUDED
17
+ #define SUDOKU_H_INCLUDED
18
+
19
+ /*
20
+ * sudoku.h
21
+ *
22
+ * The L_Sudoku holds all the information of the current state.
23
+ *
24
+ * The input to sudokuCreate() is a file with any number of lines
25
+ * starting with '#', followed by 9 lines consisting of 9 numbers
26
+ * in each line. These have the known values and use 0 for the unknowns.
27
+ * Blank lines are ignored.
28
+ *
29
+ * The @locs array holds the indices of the unknowns, numbered
30
+ * left-to-right and top-to-bottom from 0 to 80. The array size
31
+ * is initialized to @num. @current is the index into the @locs
32
+ * array of the current guess: locs[current].
33
+ *
34
+ * The @state array is used to determine the validity of each guess.
35
+ * It is of size 81, and is initialized by setting the unknowns to 0
36
+ * and the knowns to their input values.
37
+ */
38
+ struct L_Sudoku
39
+ {
40
+ l_int32 num; /* number of unknowns */
41
+ l_int32 *locs; /* location of unknowns */
42
+ l_int32 current; /* index into @locs of current location */
43
+ l_int32 *init; /* initial state, with 0 representing */
44
+ /* the unknowns */
45
+ l_int32 *state; /* present state, including inits and */
46
+ /* guesses of unknowns up to @current */
47
+ l_int32 nguess; /* shows current number of guesses */
48
+ l_int32 finished; /* set to 1 when solved */
49
+ l_int32 failure; /* set to 1 if no solution is possible */
50
+ };
51
+ typedef struct L_Sudoku L_SUDOKU;
52
+
53
+
54
+ /* For printing out array data */
55
+ enum {
56
+ L_SUDOKU_INIT = 0,
57
+ L_SUDOKU_STATE = 1
58
+ };
59
+
60
+ #endif /* SUDOKU_H_INCLUDED */
61
+
62
+
@@ -0,0 +1,52 @@
1
+ /*====================================================================*
2
+ - Copyright (C) 2001 Leptonica. All rights reserved.
3
+ - This software is distributed in the hope that it will be
4
+ - useful, but with NO WARRANTY OF ANY KIND.
5
+ - No author or distributor accepts responsibility to anyone for the
6
+ - consequences of using this software, or for whether it serves any
7
+ - particular purpose or works at all, unless he or she says so in
8
+ - writing. Everyone is granted permission to copy, modify and
9
+ - redistribute this source code, for commercial or non-commercial
10
+ - purposes, with the following restrictions: (1) the origin of this
11
+ - source code must not be misrepresented; (2) modified versions must
12
+ - be plainly marked as such; and (3) this notice may not be removed
13
+ - or altered from any source or modified source distribution.
14
+ *====================================================================*/
15
+
16
+ #ifndef LEPTONICA_WATERSHED_H
17
+ #define LEPTONICA_WATERSHED_H
18
+
19
+ /*
20
+ * watershed.h
21
+ *
22
+ * Simple data structure to hold watershed data.
23
+ * All data here is owned by the L_WShed and must be freed.
24
+ */
25
+
26
+ struct L_WShed
27
+ {
28
+ struct Pix *pixs; /* clone of input 8 bpp pixs */
29
+ struct Pix *pixm; /* clone of input 1 bpp seed (marker) pixm */
30
+ l_int32 mindepth; /* minimum depth allowed for a watershed */
31
+ struct Pix *pixlab; /* 16 bpp label pix */
32
+ struct Pix *pixt; /* scratch pix for computing wshed regions */
33
+ void **lines8; /* line ptrs for pixs */
34
+ void **linem1; /* line ptrs for pixm */
35
+ void **linelab32; /* line ptrs for pixlab */
36
+ void **linet1; /* line ptrs for pixt */
37
+ struct Pixa *pixad; /* result: 1 bpp pixa of watersheds */
38
+ struct Pta *ptas; /* pta of initial seed pixels */
39
+ struct Numa *nasi; /* numa of seed indicators; 0 if completed */
40
+ struct Numa *nash; /* numa of initial seed heights */
41
+ struct Numa *namh; /* numa of initial minima heights */
42
+ struct Numa *nalevels; /* result: numa of watershed levels */
43
+ l_int32 nseeds; /* number of seeds (markers) */
44
+ l_int32 nother; /* number of minima different from seeds */
45
+ l_int32 *lut; /* lut for pixel indices */
46
+ struct Numa **links; /* back-links into lut, for updates */
47
+ l_int32 arraysize; /* size of links array */
48
+ l_int32 debug; /* set to 1 for debug output */
49
+ };
50
+ typedef struct L_WShed L_WSHED;
51
+
52
+ #endif /* LEPTONICA_WATERSHED_H */
@@ -0,0 +1,31 @@
1
+ ///////////////////////////////////////////////////////////////////////
2
+ // File: apitypes.h
3
+ // Description: Types used in both the API and internally
4
+ // Author: Ray Smith
5
+ // Created: Wed Mar 03 09:22:53 PST 2010
6
+ //
7
+ // (C) Copyright 2010, Google Inc.
8
+ // Licensed under the Apache License, Version 2.0 (the "License");
9
+ // you may not use this file except in compliance with the License.
10
+ // You may obtain a copy of the License at
11
+ // http://www.apache.org/licenses/LICENSE-2.0
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ //
18
+ ///////////////////////////////////////////////////////////////////////
19
+
20
+ #ifndef TESSERACT_API_APITYPES_H__
21
+ #define TESSERACT_API_APITYPES_H__
22
+
23
+ #include "publictypes.h"
24
+
25
+ // The types used by the API and Page/ResultIterator can be found in
26
+ // ccstruct/publictypes.h.
27
+ // API interfaces and API users should be sure to include this file, rather
28
+ // than the lower-level one, and lower-level code should be sure to include
29
+ // only the lower-level file.
30
+
31
+ #endif // TESSERACT_API_APITYPES_H__
@@ -0,0 +1,664 @@
1
+ ///////////////////////////////////////////////////////////////////////
2
+ // File: baseapi.h
3
+ // Description: Simple API for calling tesseract.
4
+ // Author: Ray Smith
5
+ // Created: Fri Oct 06 15:35:01 PDT 2006
6
+ //
7
+ // (C) Copyright 2006, Google Inc.
8
+ // Licensed under the Apache License, Version 2.0 (the "License");
9
+ // you may not use this file except in compliance with the License.
10
+ // You may obtain a copy of the License at
11
+ // http://www.apache.org/licenses/LICENSE-2.0
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ //
18
+ ///////////////////////////////////////////////////////////////////////
19
+
20
+ #ifndef TESSERACT_API_BASEAPI_H__
21
+ #define TESSERACT_API_BASEAPI_H__
22
+
23
+ // To avoid collision with other typenames include the ABSOLUTE MINIMUM
24
+ // complexity of includes here. Use forward declarations wherever possible
25
+ // and hide includes of complex types in baseapi.cpp.
26
+ #include "apitypes.h"
27
+ #include "genericvector.h"
28
+ #include "thresholder.h"
29
+ #include "unichar.h"
30
+ #include "tesscallback.h"
31
+
32
+ class PAGE_RES;
33
+ class PAGE_RES_IT;
34
+ class BLOCK_LIST;
35
+ class DENORM;
36
+ class IMAGE;
37
+ class PBLOB;
38
+ class ROW;
39
+ class STRING;
40
+ class WERD;
41
+ struct Pix;
42
+ struct Box;
43
+ struct Pixa;
44
+ struct Boxa;
45
+ class ETEXT_DESC;
46
+ struct OSResults;
47
+ class TBOX;
48
+
49
+ #define MAX_NUM_INT_FEATURES 512
50
+ struct INT_FEATURE_STRUCT;
51
+ typedef INT_FEATURE_STRUCT *INT_FEATURE;
52
+ typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES];
53
+ struct TBLOB;
54
+
55
+ #ifdef TESSDLL_EXPORTS
56
+ #define TESSDLL_API __declspec(dllexport)
57
+ #elif defined(TESSDLL_IMPORTS)
58
+ #define TESSDLL_API __declspec(dllimport)
59
+ #else
60
+ #define TESSDLL_API
61
+ #endif
62
+
63
+
64
+ namespace tesseract {
65
+
66
+ class CubeRecoContext;
67
+ class Dawg;
68
+ class Dict;
69
+ class PageIterator;
70
+ class ResultIterator;
71
+ class Tesseract;
72
+ class Trie;
73
+
74
+ typedef int (Dict::*DictFunc)(void* void_dawg_args,
75
+ UNICHAR_ID unichar_id, bool word_end);
76
+ typedef double (Dict::*ProbabilityInContextFunc)(const char* lang,
77
+ const char* context,
78
+ int context_bytes,
79
+ const char* character,
80
+ int character_bytes);
81
+ typedef TessCallback2<int, PAGE_RES *> TruthCallback;
82
+
83
+ /**
84
+ * Base class for all tesseract APIs.
85
+ * Specific classes can add ability to work on different inputs or produce
86
+ * different outputs.
87
+ * This class is mostly an interface layer on top of the Tesseract instance
88
+ * class to hide the data types so that users of this class don't have to
89
+ * include any other Tesseract headers.
90
+ */
91
+ class TESSDLL_API TessBaseAPI {
92
+ public:
93
+ TessBaseAPI();
94
+ virtual ~TessBaseAPI();
95
+
96
+ /**
97
+ * Returns the version identifier as a static string. Do not delete.
98
+ */
99
+ static const char* Version();
100
+
101
+ /**
102
+ * Set the name of the input file. Needed only for training and
103
+ * reading a UNLV zone file.
104
+ */
105
+ void SetInputName(const char* name);
106
+
107
+ /** Set the name of the bonus output files. Needed only for debugging. */
108
+ void SetOutputName(const char* name);
109
+
110
+ /**
111
+ * Set the value of an internal "parameter."
112
+ * Supply the name of the parameter and the value as a string, just as
113
+ * you would in a config file.
114
+ * Returns false if the name lookup failed.
115
+ * Eg SetVariable("tessedit_char_blacklist", "xyz"); to ignore x, y and z.
116
+ * Or SetVariable("classify_bln_numeric_mode", "1"); to set numeric-only mode.
117
+ * SetVariable may be used before Init, but settings will revert to
118
+ * defaults on End().
119
+ * TODO(rays) Add a command-line option to dump the parameters to stdout
120
+ * and add a pointer to it in the FAQ
121
+ *
122
+ * Note: Must be called after Init(). Only works for non-init variables
123
+ * (init variables should be passed to Init()).
124
+ */
125
+ bool SetVariable(const char* name, const char* value);
126
+
127
+ // Returns true if the parameter was found among Tesseract parameters.
128
+ // Fills in value with the value of the parameter.
129
+ bool GetIntVariable(const char *name, int *value) const;
130
+ bool GetBoolVariable(const char *name, bool *value) const;
131
+ bool GetDoubleVariable(const char *name, double *value) const;
132
+ // Returns the pointer to the string that represents the value of the
133
+ // parameter if it was found among Tesseract parameters.
134
+ const char *GetStringVariable(const char *name) const;
135
+
136
+ // Print Tesseract parameters to the given file.
137
+ void PrintVariables(FILE *fp) const;
138
+ // Get value of named variable as a string, if it exists.
139
+ bool GetVariableAsString(const char *name, STRING *val);
140
+
141
+ /**
142
+ * Instances are now mostly thread-safe and totally independent,
143
+ * but some global parameters remain. Basically it is safe to use multiple
144
+ * TessBaseAPIs in different threads in parallel, UNLESS:
145
+ * you use SetVariable on some of the Params in classify and textord.
146
+ * If you do, then the effect will be to change it for all your instances.
147
+ *
148
+ * Start tesseract. Returns zero on success and -1 on failure.
149
+ * NOTE that the only members that may be called before Init are those
150
+ * listed above here in the class definition.
151
+ *
152
+ * The datapath must be the name of the parent directory of tessdata and
153
+ * must end in / . Any name after the last / will be stripped.
154
+ * The language is (usually) an ISO 639-3 string or NULL will default to eng.
155
+ * It is entirely safe (and eventually will be efficient too) to call
156
+ * Init multiple times on the same instance to change language, or just
157
+ * to reset the classifier.
158
+ * WARNING: On changing languages, all Tesseract parameters are reset
159
+ * back to their default values. (Which may vary between languages.)
160
+ * If you have a rare need to set a Variable that controls
161
+ * initialization for a second call to Init you should explicitly
162
+ * call End() and then use SetVariable before Init. This is only a very
163
+ * rare use case, since there are very few uses that require any parameters
164
+ * to be set before Init.
165
+ */
166
+ int Init(const char* datapath, const char* language, OcrEngineMode mode,
167
+ char **configs, int configs_size,
168
+ const GenericVector<STRING> *vars_vec,
169
+ const GenericVector<STRING> *vars_values,
170
+ bool set_only_init_params);
171
+ int Init(const char* datapath, const char* language, OcrEngineMode oem) {
172
+ return Init(datapath, language, oem, NULL, 0, NULL, NULL, false);
173
+ }
174
+ int Init(const char* datapath, const char* language) {
175
+ return Init(datapath, language, OEM_DEFAULT, NULL, 0, NULL, NULL, false);
176
+ }
177
+
178
+ /**
179
+ * Init only the lang model component of Tesseract. The only functions
180
+ * that work after this init are SetVariable and IsValidWord.
181
+ * WARNING: temporary! This function will be removed from here and placed
182
+ * in a separate API at some future time.
183
+ */
184
+ int InitLangMod(const char* datapath, const char* language);
185
+
186
+ // Init only for page layout analysis. Use only for calls to SetImage and
187
+ // AnalysePage. Calls that attempt recognition will generate an error.
188
+ void InitForAnalysePage();
189
+
190
+ /**
191
+ * Read a "config" file containing a set of variable, value pairs.
192
+ * Searches the standard places: tessdata/configs, tessdata/tessconfigs
193
+ * and also accepts a relative or absolute path name.
194
+ * If init_only is true, only sets the parameters marked with a special
195
+ * INIT flag, which are typically of functional/algorithmic effect
196
+ * rather than debug effect. Used to separate debug settings from
197
+ * working settings.
198
+ */
199
+ void ReadConfigFile(const char* filename, bool init_only);
200
+
201
+ /**
202
+ * Set the current page segmentation mode. Defaults to PSM_SINGLE_BLOCK.
203
+ * The mode is stored as an IntParam so it can also be modified by
204
+ * ReadConfigFile or SetVariable("tessedit_pageseg_mode", mode as string).
205
+ */
206
+ void SetPageSegMode(PageSegMode mode);
207
+
208
+ /** Return the current page segmentation mode. */
209
+ PageSegMode GetPageSegMode() const;
210
+
211
+ /**
212
+ * Recognize a rectangle from an image and return the result as a string.
213
+ * May be called many times for a single Init.
214
+ * Currently has no error checking.
215
+ * Greyscale of 8 and color of 24 or 32 bits per pixel may be given.
216
+ * Palette color images will not work properly and must be converted to
217
+ * 24 bit.
218
+ * Binary images of 1 bit per pixel may also be given but they must be
219
+ * byte packed with the MSB of the first byte being the first pixel, and a
220
+ * 1 represents WHITE. For binary images set bytes_per_pixel=0.
221
+ * The recognized text is returned as a char* which is coded
222
+ * as UTF8 and must be freed with the delete [] operator.
223
+ *
224
+ * Note that TesseractRect is the simplified convenience interface.
225
+ * For advanced uses, use SetImage, (optionally) SetRectangle, Recognize,
226
+ * and one or more of the Get*Text functions below.
227
+ */
228
+ char* TesseractRect(const unsigned char* imagedata,
229
+ int bytes_per_pixel, int bytes_per_line,
230
+ int left, int top, int width, int height);
231
+
232
+ /**
233
+ * Call between pages or documents etc to free up memory and forget
234
+ * adaptive data.
235
+ */
236
+ void ClearAdaptiveClassifier();
237
+
238
+ /**
239
+ * @defgroup AdvancedAPI Advanced API
240
+ * The following methods break TesseractRect into pieces, so you can
241
+ * get hold of the thresholded image, get the text in different formats,
242
+ * get bounding boxes, confidences etc.
243
+ */
244
+ /* @{ */
245
+
246
+ /**
247
+ * Provide an image for Tesseract to recognize. Format is as
248
+ * TesseractRect above. Does not copy the image buffer, or take
249
+ * ownership. The source image may be destroyed after Recognize is called,
250
+ * either explicitly or implicitly via one of the Get*Text functions.
251
+ * SetImage clears all recognition results, and sets the rectangle to the
252
+ * full image, so it may be followed immediately by a GetUTF8Text, and it
253
+ * will automatically perform recognition.
254
+ */
255
+ void SetImage(const unsigned char* imagedata, int width, int height,
256
+ int bytes_per_pixel, int bytes_per_line);
257
+
258
+ /**
259
+ * Provide an image for Tesseract to recognize. As with SetImage above,
260
+ * Tesseract doesn't take a copy or ownership or pixDestroy the image, so
261
+ * it must persist until after Recognize.
262
+ * Pix vs raw, which to use?
263
+ * Use Pix where possible. A future version of Tesseract may choose to use Pix
264
+ * as its internal representation and discard IMAGE altogether.
265
+ * Because of that, an implementation that sources and targets Pix may end up
266
+ * with less copies than an implementation that does not.
267
+ */
268
+ void SetImage(const Pix* pix);
269
+
270
+ /**
271
+ * Restrict recognition to a sub-rectangle of the image. Call after SetImage.
272
+ * Each SetRectangle clears the recogntion results so multiple rectangles
273
+ * can be recognized with the same image.
274
+ */
275
+ void SetRectangle(int left, int top, int width, int height);
276
+
277
+ /**
278
+ * In extreme cases only, usually with a subclass of Thresholder, it
279
+ * is possible to provide a different Thresholder. The Thresholder may
280
+ * be preloaded with an image, settings etc, or they may be set after.
281
+ * Note that Tesseract takes ownership of the Thresholder and will
282
+ * delete it when it it is replaced or the API is destructed.
283
+ */
284
+ void SetThresholder(ImageThresholder* thresholder) {
285
+ if (thresholder_ != NULL)
286
+ delete thresholder_;
287
+ thresholder_ = thresholder;
288
+ ClearResults();
289
+ }
290
+
291
+ /**
292
+ * Get a copy of the internal thresholded image from Tesseract.
293
+ * Caller takes ownership of the Pix and must pixDestroy it.
294
+ * May be called any time after SetImage, or after TesseractRect.
295
+ */
296
+ Pix* GetThresholdedImage();
297
+
298
+ /**
299
+ * Get the result of page layout analysis as a leptonica-style
300
+ * Boxa, Pixa pair, in reading order.
301
+ * Can be called before or after Recognize.
302
+ */
303
+ Boxa* GetRegions(Pixa** pixa);
304
+
305
+ /**
306
+ * Get the textlines as a leptonica-style
307
+ * Boxa, Pixa pair, in reading order.
308
+ * Can be called before or after Recognize.
309
+ * If blockids is not NULL, the block-id of each line is also returned
310
+ * as an array of one element per line. delete [] after use.
311
+ */
312
+ Boxa* GetTextlines(Pixa** pixa, int** blockids);
313
+
314
+ /**
315
+ * Get the words as a leptonica-style
316
+ * Boxa, Pixa pair, in reading order.
317
+ * Can be called before or after Recognize.
318
+ */
319
+ Boxa* GetWords(Pixa** pixa);
320
+
321
+ // Gets the individual connected (text) components (created
322
+ // after pages segmentation step, but before recognition)
323
+ // as a leptonica-style Boxa, Pixa pair, in reading order.
324
+ // Can be called before or after Recognize.
325
+ // Note: the caller is responsible for calling boxaDestroy()
326
+ // on the returned Boxa array and pixaDestroy() on cc array.
327
+ Boxa* GetConnectedComponents(Pixa** cc);
328
+
329
+ // Get the given level kind of components (block, textline, word etc.) as a
330
+ // leptonica-style Boxa, Pixa pair, in reading order.
331
+ // Can be called before or after Recognize.
332
+ // If blockids is not NULL, the block-id of each component is also returned
333
+ // as an array of one element per component. delete [] after use.
334
+ Boxa* GetComponentImages(PageIteratorLevel level,
335
+ Pixa** pixa, int** blockids);
336
+
337
+ /**
338
+ * Dump the internal binary image to a PGM file.
339
+ * @deprecated Use GetThresholdedImage and write the image using pixWrite
340
+ * instead if possible.
341
+ */
342
+ void DumpPGM(const char* filename);
343
+
344
+ // Runs page layout analysis in the mode set by SetPageSegMode.
345
+ // May optionally be called prior to Recognize to get access to just
346
+ // the page layout results. Returns an iterator to the results.
347
+ // Returns NULL on error.
348
+ // The returned iterator must be deleted after use.
349
+ // WARNING! This class points to data held within the TessBaseAPI class, and
350
+ // therefore can only be used while the TessBaseAPI class still exists and
351
+ // has not been subjected to a call of Init, SetImage, Recognize, Clear, End
352
+ // DetectOS, or anything else that changes the internal PAGE_RES.
353
+ PageIterator* AnalyseLayout();
354
+
355
+ /**
356
+ * Recognize the image from SetAndThresholdImage, generating Tesseract
357
+ * internal structures. Returns 0 on success.
358
+ * Optional. The Get*Text functions below will call Recognize if needed.
359
+ * After Recognize, the output is kept internally until the next SetImage.
360
+ */
361
+ int Recognize(ETEXT_DESC* monitor);
362
+
363
+ /**
364
+ * Methods to retrieve information after SetAndThresholdImage(),
365
+ * Recognize() or TesseractRect(). (Recognize is called implicitly if needed.)
366
+ */
367
+
368
+ /** Variant on Recognize used for testing chopper. */
369
+ int RecognizeForChopTest(ETEXT_DESC* monitor);
370
+
371
+ /**
372
+ * Recognizes all the pages in the named file, as a multi-page tiff or
373
+ * list of filenames, or single image, and gets the appropriate kind of text
374
+ * according to parameters: tessedit_create_boxfile,
375
+ * tessedit_make_boxes_from_boxes, tessedit_write_unlv, tessedit_create_hocr.
376
+ * Calls ProcessPage on each page in the input file, which may be a
377
+ * multi-page tiff, single-page other file format, or a plain text list of
378
+ * images to read. If tessedit_page_number is non-negative, processing begins
379
+ * at that page of a multi-page tiff file, or filelist.
380
+ * The text is returned in text_out. Returns false on error.
381
+ * If non-zero timeout_millisec terminates processing after the timeout on
382
+ * a single page.
383
+ * If non-NULL and non-empty, and some page fails for some reason,
384
+ * the page is reprocessed with the retry_config config file. Useful
385
+ * for interactively debugging a bad page.
386
+ */
387
+ bool ProcessPages(const char* filename,
388
+ const char* retry_config, int timeout_millisec,
389
+ STRING* text_out);
390
+
391
+ /**
392
+ * Recognizes a single page for ProcessPages, appending the text to text_out.
393
+ * The pix is the image processed - filename and page_index are metadata
394
+ * used by side-effect processes, such as reading a box file or formatting
395
+ * as hOCR.
396
+ * If non-zero timeout_millisec terminates processing after the timeout.
397
+ * If non-NULL and non-empty, and some page fails for some reason,
398
+ * the page is reprocessed with the retry_config config file. Useful
399
+ * for interactively debugging a bad page.
400
+ * The text is returned in text_out. Returns false on error.
401
+ */
402
+ bool ProcessPage(Pix* pix, int page_index, const char* filename,
403
+ const char* retry_config, int timeout_millisec,
404
+ STRING* text_out);
405
+
406
+ // Get an iterator to the results of LayoutAnalysis and/or Recognize.
407
+ // The returned iterator must be deleted after use.
408
+ // WARNING! This class points to data held within the TessBaseAPI class, and
409
+ // therefore can only be used while the TessBaseAPI class still exists and
410
+ // has not been subjected to a call of Init, SetImage, Recognize, Clear, End
411
+ // DetectOS, or anything else that changes the internal PAGE_RES.
412
+ ResultIterator* GetIterator();
413
+
414
+ /**
415
+ * The recognized text is returned as a char* which is coded
416
+ * as UTF8 and must be freed with the delete [] operator.
417
+ */
418
+ char* GetUTF8Text();
419
+ /**
420
+ * Make a HTML-formatted string with hOCR markup from the internal
421
+ * data structures.
422
+ * page_number is 0-based but will appear in the output as 1-based.
423
+ */
424
+ char* GetHOCRText(int page_number);
425
+ /**
426
+ * The recognized text is returned as a char* which is coded in the same
427
+ * format as a box file used in training. Returned string must be freed with
428
+ * the delete [] operator.
429
+ * Constructs coordinates in the original image - not just the rectangle.
430
+ * page_number is a 0-based page index that will appear in the box file.
431
+ */
432
+ char* GetBoxText(int page_number);
433
+ /**
434
+ * The recognized text is returned as a char* which is coded
435
+ * as UNLV format Latin-1 with specific reject and suspect codes
436
+ * and must be freed with the delete [] operator.
437
+ */
438
+ char* GetUNLVText();
439
+ /** Returns the (average) confidence value between 0 and 100. */
440
+ int MeanTextConf();
441
+ /**
442
+ * Returns all word confidences (between 0 and 100) in an array, terminated
443
+ * by -1. The calling function must delete [] after use.
444
+ * The number of confidences should correspond to the number of space-
445
+ * delimited words in GetUTF8Text.
446
+ */
447
+ int* AllWordConfidences();
448
+
449
+ /**
450
+ * Applies the given word to the adaptive classifier if possible.
451
+ * The word must be SPACE-DELIMITED UTF-8 - l i k e t h i s , so it can
452
+ * tell the boundaries of the graphemes.
453
+ * Assumes that SetImage/SetRectangle have been used to set the image
454
+ * to the given word. The mode arg should be PSM_SINGLE_WORD or
455
+ * PSM_CIRCLE_WORD, as that will be used to control layout analysis.
456
+ * The currently set PageSegMode is preserved.
457
+ * Returns false if adaption was not possible for some reason.
458
+ */
459
+ bool AdaptToWordStr(PageSegMode mode, const char* wordstr);
460
+
461
+ /**
462
+ * Free up recognition results and any stored image data, without actually
463
+ * freeing any recognition data that would be time-consuming to reload.
464
+ * Afterwards, you must call SetImage or TesseractRect before doing
465
+ * any Recognize or Get* operation.
466
+ */
467
+ void Clear();
468
+
469
+ /**
470
+ * Close down tesseract and free up all memory. End() is equivalent to
471
+ * destructing and reconstructing your TessBaseAPI.
472
+ * Once End() has been used, none of the other API functions may be used
473
+ * other than Init and anything declared above it in the class definition.
474
+ */
475
+ void End();
476
+
477
+ /**
478
+ * Check whether a word is valid according to Tesseract's language model
479
+ * @return 0 if the word is invalid, non-zero if valid.
480
+ * @warning temporary! This function will be removed from here and placed
481
+ * in a separate API at some future time.
482
+ */
483
+ int IsValidWord(const char *word);
484
+
485
+ bool GetTextDirection(int* out_offset, float* out_slope);
486
+
487
+ /** Sets Dict::letter_is_okay_ function to point to the given function. */
488
+ void SetDictFunc(DictFunc f);
489
+
490
+ /** Sets Dict::probability_in_context_ function to point to the given
491
+ * function.
492
+ */
493
+ void SetProbabilityInContextFunc(ProbabilityInContextFunc f);
494
+
495
+ /**
496
+ * Estimates the Orientation And Script of the image.
497
+ * @return true if the image was processed successfully.
498
+ */
499
+ bool DetectOS(OSResults*);
500
+
501
+ /** This method returns the features associated with the input image. */
502
+ void GetFeaturesForBlob(TBLOB* blob, const DENORM& denorm,
503
+ INT_FEATURE_ARRAY int_features,
504
+ int* num_features, int* FeatureOutlineIndex);
505
+
506
+ // This method returns the row to which a box of specified dimensions would
507
+ // belong. If no good match is found, it returns NULL.
508
+ static ROW* FindRowForBox(BLOCK_LIST* blocks, int left, int top,
509
+ int right, int bottom);
510
+
511
+ // Method to run adaptive classifier on a blob.
512
+ // It returns at max num_max_matches results.
513
+ void RunAdaptiveClassifier(TBLOB* blob, const DENORM& denorm,
514
+ int num_max_matches,
515
+ int* unichar_ids,
516
+ float* ratings,
517
+ int* num_matches_returned);
518
+
519
+ // This method returns the string form of the specified unichar.
520
+ const char* GetUnichar(int unichar_id);
521
+
522
+ /** Return the pointer to the i-th dawg loaded into tesseract_ object. */
523
+ const Dawg *GetDawg(int i) const;
524
+
525
+ /** Return the number of dawgs loaded into tesseract_ object. */
526
+ int NumDawgs() const;
527
+
528
+ /** Return the language used in the last valid initialization. */
529
+ const char* GetLastInitLanguage() const;
530
+
531
+ // Returns a ROW object created from the input row specification.
532
+ static ROW *MakeTessOCRRow(float baseline, float xheight,
533
+ float descender, float ascender);
534
+
535
+ // Returns a TBLOB corresponding to the entire input image.
536
+ static TBLOB *MakeTBLOB(Pix *pix);
537
+
538
+ // This method baseline normalizes a TBLOB in-place. The input row is used
539
+ // for normalization. The denorm is an optional parameter in which the
540
+ // normalization-antidote is returned.
541
+ static void NormalizeTBLOB(TBLOB *tblob, ROW *row,
542
+ bool numeric_mode, DENORM *denorm);
543
+
544
+ Tesseract* const tesseract() const {
545
+ return tesseract_;
546
+ }
547
+
548
+ void InitTruthCallback(TruthCallback *cb) { truth_cb_ = cb; }
549
+
550
+ // Return a pointer to underlying CubeRecoContext object if present.
551
+ CubeRecoContext *GetCubeRecoContext() const;
552
+
553
+ void set_min_orientation_margin(double margin);
554
+
555
+ // Return text orientation of each block as determined by an earlier run
556
+ // of layout analysis.
557
+ void GetBlockTextOrientations(int** block_orientation,
558
+ bool** vertical_writing);
559
+
560
+ /** Find lines from the image making the BLOCK_LIST. */
561
+ BLOCK_LIST* FindLinesCreateBlockList();
562
+
563
+ /**
564
+ * Delete a block list.
565
+ * This is to keep BLOCK_LIST pointer opaque
566
+ * and let go of including the other headers.
567
+ */
568
+ static void DeleteBlockList(BLOCK_LIST* block_list);
569
+ /* @} */
570
+
571
+ protected:
572
+
573
+ /** Common code for setting the image. Returns true if Init has been called. */
574
+ bool InternalSetImage();
575
+
576
+ /**
577
+ * Run the thresholder to make the thresholded image. If pix is not NULL,
578
+ * the source is thresholded to pix instead of the internal IMAGE.
579
+ */
580
+ virtual void Threshold(Pix** pix);
581
+
582
+ /**
583
+ * Find lines from the image making the BLOCK_LIST.
584
+ * @return 0 on success.
585
+ */
586
+ int FindLines();
587
+
588
+ /** Delete the pageres and block list ready for a new page. */
589
+ void ClearResults();
590
+
591
+ /**
592
+ * Return the length of the output text string, as UTF8, assuming
593
+ * one newline per line and one per block, with a terminator,
594
+ * and assuming a single character reject marker for each rejected character.
595
+ * Also return the number of recognized blobs in blob_count.
596
+ */
597
+ int TextLength(int* blob_count);
598
+
599
+ /** @defgroup ocropusAddOns ocropus add-ons */
600
+ /* @{ */
601
+
602
+ /**
603
+ * Adapt to recognize the current image as the given character.
604
+ * The image must be preloaded and be just an image of a single character.
605
+ */
606
+ void AdaptToCharacter(const char *unichar_repr,
607
+ int length,
608
+ float baseline,
609
+ float xheight,
610
+ float descender,
611
+ float ascender);
612
+
613
+ /** Recognize text doing one pass only, using settings for a given pass. */
614
+ PAGE_RES* RecognitionPass1(BLOCK_LIST* block_list);
615
+ PAGE_RES* RecognitionPass2(BLOCK_LIST* block_list, PAGE_RES* pass1_result);
616
+
617
+ /**
618
+ * Extract the OCR results, costs (penalty points for uncertainty),
619
+ * and the bounding boxes of the characters.
620
+ */
621
+ static int TesseractExtractResult(char** text,
622
+ int** lengths,
623
+ float** costs,
624
+ int** x0,
625
+ int** y0,
626
+ int** x1,
627
+ int** y1,
628
+ PAGE_RES* page_res);
629
+
630
+ const PAGE_RES* GetPageRes() const {
631
+ return page_res_;
632
+ };
633
+
634
+ protected:
635
+ Tesseract* tesseract_; ///< The underlying data object.
636
+ Tesseract* osd_tesseract_; ///< For orientation & script detection.
637
+ ImageThresholder* thresholder_; ///< Image thresholding module.
638
+ BLOCK_LIST* block_list_; ///< The page layout.
639
+ PAGE_RES* page_res_; ///< The page-level data.
640
+ STRING* input_file_; ///< Name used by training code.
641
+ STRING* output_file_; ///< Name used by debug code.
642
+ STRING* datapath_; ///< Current location of tessdata.
643
+ STRING* language_; ///< Last initialized language.
644
+ OcrEngineMode last_oem_requested_; ///< Last ocr language mode requested.
645
+ bool recognition_done_; ///< page_res_ contains recognition data.
646
+ TruthCallback *truth_cb_; /// fxn for setting truth_* in WERD_RES
647
+
648
+ /**
649
+ * @defgroup ThresholderParams
650
+ * Parameters saved from the Thresholder. Needed to rebuild coordinates.
651
+ */
652
+ /* @{ */
653
+ int rect_left_;
654
+ int rect_top_;
655
+ int rect_width_;
656
+ int rect_height_;
657
+ int image_width_;
658
+ int image_height_;
659
+ /* @} */
660
+ };
661
+
662
+ } // namespace tesseract.
663
+
664
+ #endif // TESSERACT_API_BASEAPI_H__