Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
capi.h
Go to the documentation of this file.
1 #ifndef TESSERACT_API_CAPI_H__
2 #define TESSERACT_API_CAPI_H__
3
4 #ifdef TESS_CAPI_INCLUDE_BASEAPI
5 # include "baseapi.h"
6 # include "pageiterator.h"
7 # include "resultiterator.h"
8 #else
9 # include "platform.h"
10 # include <stdio.h>
11 #endif
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #ifndef TESS_CALL
18 # if defined(WIN32)
19 # define TESS_CALL __cdecl
20 # else
21 # define TESS_CALL
22 # endif
23 #endif
24
25 #ifndef BOOL
26 # define BOOL int
27 # define TRUE 1
28 # define FALSE 0
29 #endif
30
31 #ifdef TESS_CAPI_INCLUDE_BASEAPI
32 typedef tesseract::TessBaseAPI TessBaseAPI;
33 typedef tesseract::PageIterator TessPageIterator;
34 typedef tesseract::ResultIterator TessResultIterator;
35 typedef tesseract::MutableIterator TessMutableIterator;
36 typedef tesseract::OcrEngineMode TessOcrEngineMode;
37 typedef tesseract::PageSegMode TessPageSegMode;
38 typedef tesseract::ImageThresholder TessImageThresholder;
39 typedef tesseract::PageIteratorLevel TessPageIteratorLevel;
40 typedef tesseract::DictFunc TessDictFunc;
41 typedef tesseract::ProbabilityInContextFunc TessProbabilityInContextFunc;
42 typedef tesseract::FillLatticeFunc TessFillLatticeFunc;
43 typedef tesseract::Dawg TessDawg;
44 typedef tesseract::TruthCallback TessTruthCallback;
45 typedef tesseract::CubeRecoContext TessCubeRecoContext;
46 typedef tesseract::Orientation TessOrientation;
47 typedef tesseract::WritingDirection TessWritingDirection;
48 typedef tesseract::TextlineOrder TessTextlineOrder;
49 typedef PolyBlockType TessPolyBlockType;
50 typedef Pix PIX;
51 typedef Boxa BOXA;
52 typedef Pixa PIXA;
53 #else
54 typedef struct TessBaseAPI TessBaseAPI;
55 typedef struct TessPageIterator TessPageIterator;
56 typedef struct TessResultIterator TessResultIterator;
57 typedef struct TessMutableIterator TessMutableIterator;
58 typedef enum TessOcrEngineMode { OEM_TESSERACT_ONLY, OEM_CUBE_ONLY, OEM_TESSERACT_CUBE_COMBINED, OEM_DEFAULT } TessOcrEngineMode;
59 typedef enum TessPageSegMode { PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO, PSM_SINGLE_COLUMN, PSM_SINGLE_BLOCK_VERT_TEXT,
60 PSM_SINGLE_BLOCK, PSM_SINGLE_LINE, PSM_SINGLE_WORD, PSM_CIRCLE_WORD, PSM_SINGLE_CHAR, PSM_COUNT } TessPageSegMode;
61 typedef enum TessPageIteratorLevel { RIL_BLOCK, RIL_PARA, RIL_TEXTLINE, RIL_WORD, RIL_SYMBOL} TessPageIteratorLevel;
62 typedef enum TessPolyBlockType { PT_UNKNOWN, PT_FLOWING_TEXT, PT_HEADING_TEXT, PT_PULLOUT_TEXT, PT_TABLE, PT_VERTICAL_TEXT,
63 PT_CAPTION_TEXT, PT_FLOWING_IMAGE, PT_HEADING_IMAGE, PT_PULLOUT_IMAGE, PT_HORZ_LINE, PT_VERT_LINE,
64 PT_NOISE, PT_COUNT } TessPolyBlockType;
65 typedef enum TessOrientation { ORIENTATION_PAGE_UP, ORIENTATION_PAGE_RIGHT, ORIENTATION_PAGE_DOWN, ORIENTATION_PAGE_LEFT } TessOrientation;
66 typedef enum TessWritingDirection { WRITING_DIRECTION_LEFT_TO_RIGHT, WRITING_DIRECTION_RIGHT_TO_LEFT, WRITING_DIRECTION_TOP_TO_BOTTOM } TessWritingDirection;
67 typedef enum TessTextlineOrder { TEXTLINE_ORDER_LEFT_TO_RIGHT, TEXTLINE_ORDER_RIGHT_TO_LEFT, TEXTLINE_ORDER_TOP_TO_BOTTOM } TessTextlineOrder;
68 typedef struct ETEXT_DESC ETEXT_DESC;
69 typedef struct Pix PIX;
70 typedef struct Boxa BOXA;
71 typedef struct Pixa PIXA;
72 #endif
73
74 /* General free functions */
75
76 TESS_API const char*
77 TESS_CALL TessVersion();
78 TESS_API void TESS_CALL TessDeleteText(char* text);
79 TESS_API void TESS_CALL TessDeleteTextArray(char** arr);
80 TESS_API void TESS_CALL TessDeleteIntArray(int* arr);
81 #ifdef TESS_CAPI_INCLUDE_BASEAPI
82 TESS_API void TESS_CALL TessDeleteBlockList(BLOCK_LIST* block_list);
83 #endif
84
85 /* Base API */
86
87 TESS_API TessBaseAPI*
88 TESS_CALL TessBaseAPICreate();
89 TESS_API void TESS_CALL TessBaseAPIDelete(TessBaseAPI* handle);
90
91 TESS_API void TESS_CALL TessBaseAPISetInputName( TessBaseAPI* handle, const char* name);
92 TESS_API void TESS_CALL TessBaseAPISetOutputName(TessBaseAPI* handle, const char* name);
93
94 TESS_API BOOL TESS_CALL TessBaseAPISetVariable(TessBaseAPI* handle, const char* name, const char* value);
95 TESS_API BOOL TESS_CALL TessBaseAPISetDebugVariable(TessBaseAPI* handle, const char* name, const char* value);
96
97 TESS_API BOOL TESS_CALL TessBaseAPIGetIntVariable( const TessBaseAPI* handle, const char* name, int* value);
98 TESS_API BOOL TESS_CALL TessBaseAPIGetBoolVariable( const TessBaseAPI* handle, const char* name, BOOL* value);
99 TESS_API BOOL TESS_CALL TessBaseAPIGetDoubleVariable(const TessBaseAPI* handle, const char* name, double* value);
100 TESS_API const char*
101 TESS_CALL TessBaseAPIGetStringVariable(const TessBaseAPI* handle, const char* name);
102
103 TESS_API void TESS_CALL TessBaseAPIPrintVariables( const TessBaseAPI* handle, FILE* fp);
104 TESS_API BOOL TESS_CALL TessBaseAPIPrintVariablesToFile(const TessBaseAPI* handle, const char* filename);
105 #ifdef TESS_CAPI_INCLUDE_BASEAPI
106 TESS_API BOOL TESS_CALL TessBaseAPIGetVariableAsString(TessBaseAPI* handle, const char* name, STRING* val);
107 #endif
108
109 #ifdef TESS_CAPI_INCLUDE_BASEAPI
110 TESS_API int TESS_CALL TessBaseAPIInit(TessBaseAPI* handle, const char* datapath, const char* language,
111 TessOcrEngineMode mode, char** configs, int configs_size,
112 const STRING* vars_vec, size_t vars_vec_size,
113 const STRING* vars_values, size_t vars_values_size, BOOL set_only_init_params);
114 #endif
115 TESS_API int TESS_CALL TessBaseAPIInit1(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode oem,
116 char** configs, int configs_size);
117 TESS_API int TESS_CALL TessBaseAPIInit2(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode oem);
118 TESS_API int TESS_CALL TessBaseAPIInit3(TessBaseAPI* handle, const char* datapath, const char* language);
119
120 TESS_API const char*
121 TESS_CALL TessBaseAPIGetInitLanguagesAsString(const TessBaseAPI* handle);
122 TESS_API char**
123 TESS_CALL TessBaseAPIGetLoadedLanguagesAsVector(const TessBaseAPI* handle);
124 TESS_API char**
125 TESS_CALL TessBaseAPIGetAvailableLanguagesAsVector(const TessBaseAPI* handle);
126
127 TESS_API int TESS_CALL TessBaseAPIInitLangMod(TessBaseAPI* handle, const char* datapath, const char* language);
128 TESS_API void TESS_CALL TessBaseAPIInitForAnalysePage(TessBaseAPI* handle);
129
130 TESS_API void TESS_CALL TessBaseAPIReadConfigFile(TessBaseAPI* handle, const char* filename);
131 TESS_API void TESS_CALL TessBaseAPIReadDebugConfigFile(TessBaseAPI* handle, const char* filename);
132
133 TESS_API void TESS_CALL TessBaseAPISetPageSegMode(TessBaseAPI* handle, TessPageSegMode mode);
134 TESS_API TessPageSegMode
135 TESS_CALL TessBaseAPIGetPageSegMode(const TessBaseAPI* handle);
136
137 TESS_API char* TESS_CALL TessBaseAPIRect(TessBaseAPI* handle, const unsigned char* imagedata,
138 int bytes_per_pixel, int bytes_per_line,
139 int left, int top, int width, int height);
140
141 TESS_API void TESS_CALL TessBaseAPIClearAdaptiveClassifier(TessBaseAPI* handle);
142
143 TESS_API void TESS_CALL TessBaseAPISetImage(TessBaseAPI* handle, const unsigned char* imagedata, int width, int height,
144 int bytes_per_pixel, int bytes_per_line);
145 TESS_API void TESS_CALL TessBaseAPISetImage2(TessBaseAPI* handle, const PIX* pix);
146
147 TESS_API void TESS_CALL TessBaseAPISetSourceResolution(TessBaseAPI* handle, int ppi);
148
149 TESS_API void TESS_CALL TessBaseAPISetRectangle(TessBaseAPI* handle, int left, int top, int width, int height);
150
151 #ifdef TESS_CAPI_INCLUDE_BASEAPI
152 TESS_API void TESS_CALL TessBaseAPISetThresholder(TessBaseAPI* handle, TessImageThresholder* thresholder);
153 #endif
154
155 TESS_API PIX* TESS_CALL TessBaseAPIGetThresholdedImage( TessBaseAPI* handle);
156 TESS_API BOXA* TESS_CALL TessBaseAPIGetRegions( TessBaseAPI* handle, PIXA** pixa);
157 TESS_API BOXA* TESS_CALL TessBaseAPIGetTextlines( TessBaseAPI* handle, PIXA** pixa, int** blockids);
158 TESS_API BOXA* TESS_CALL TessBaseAPIGetStrips( TessBaseAPI* handle, PIXA** pixa, int** blockids);
159 TESS_API BOXA* TESS_CALL TessBaseAPIGetWords( TessBaseAPI* handle, PIXA** pixa);
160 TESS_API BOXA* TESS_CALL TessBaseAPIGetConnectedComponents(TessBaseAPI* handle, PIXA** cc);
161 TESS_API BOXA* TESS_CALL TessBaseAPIGetComponentImages( TessBaseAPI* handle, TessPageIteratorLevel level, BOOL text_only, PIXA** pixa, int** blockids);
162
163 TESS_API int TESS_CALL TessBaseAPIGetThresholdedImageScaleFactor(const TessBaseAPI* handle);
164
165 TESS_API void TESS_CALL TessBaseAPIDumpPGM(TessBaseAPI* handle, const char* filename);
166
167 TESS_API TessPageIterator*
168 TESS_CALL TessBaseAPIAnalyseLayout(TessBaseAPI* handle);
169
170 TESS_API int TESS_CALL TessBaseAPIRecognize(TessBaseAPI* handle, ETEXT_DESC* monitor);
171 TESS_API int TESS_CALL TessBaseAPIRecognizeForChopTest(TessBaseAPI* handle, ETEXT_DESC* monitor);
172 TESS_API char* TESS_CALL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename, const char* retry_config,
173 int timeout_millisec);
174 TESS_API char* TESS_CALL TessBaseAPIProcessPage(TessBaseAPI* handle, PIX* pix, int page_index, const char* filename,
175 const char* retry_config, int timeout_millisec);
176
177 TESS_API TessResultIterator*
178 TESS_CALL TessBaseAPIGetIterator(TessBaseAPI* handle);
179 TESS_API TessMutableIterator*
180 TESS_CALL TessBaseAPIGetMutableIterator(TessBaseAPI* handle);
181
182 TESS_API char* TESS_CALL TessBaseAPIGetUTF8Text(TessBaseAPI* handle);
183 TESS_API char* TESS_CALL TessBaseAPIGetHOCRText(TessBaseAPI* handle, int page_number);
184 TESS_API char* TESS_CALL TessBaseAPIGetBoxText(TessBaseAPI* handle, int page_number);
185 TESS_API char* TESS_CALL TessBaseAPIGetUNLVText(TessBaseAPI* handle);
186 TESS_API int TESS_CALL TessBaseAPIMeanTextConf(TessBaseAPI* handle);
187 TESS_API int* TESS_CALL TessBaseAPIAllWordConfidences(TessBaseAPI* handle);
188 TESS_API BOOL TESS_CALL TessBaseAPIAdaptToWordStr(TessBaseAPI* handle, TessPageSegMode mode, const char* wordstr);
189
190 TESS_API void TESS_CALL TessBaseAPIClear(TessBaseAPI* handle);
191 TESS_API void TESS_CALL TessBaseAPIEnd(TessBaseAPI* handle);
192
193 TESS_API int TESS_CALL TessBaseAPIIsValidWord(TessBaseAPI* handle, const char *word);
194 TESS_API BOOL TESS_CALL TessBaseAPIGetTextDirection(TessBaseAPI* handle, int* out_offset, float* out_slope);
195
196 #ifdef TESS_CAPI_INCLUDE_BASEAPI
197 TESS_API void TESS_CALL TessBaseAPISetDictFunc(TessBaseAPI* handle, TessDictFunc f);
198 TESS_API void TESS_CALL TessBaseAPISetProbabilityInContextFunc(TessBaseAPI* handle, TessProbabilityInContextFunc f);
199 TESS_API void TESS_CALL TessBaseAPISetFillLatticeFunc(TessBaseAPI* handle, TessFillLatticeFunc f);
200 TESS_API BOOL TESS_CALL TessBaseAPIDetectOS(TessBaseAPI* handle, OSResults* results);
201
202 TESS_API void TESS_CALL TessBaseAPIGetFeaturesForBlob(TessBaseAPI* handle, TBLOB* blob, const DENORM* denorm, INT_FEATURE_ARRAY int_features,
203 int* num_features, int* FeatureOutlineIndex);
204
205 TESS_API ROW* TESS_CALL TessFindRowForBox(BLOCK_LIST* blocks, int left, int top, int right, int bottom);
206 TESS_API void TESS_CALL TessBaseAPIRunAdaptiveClassifier(TessBaseAPI* handle, TBLOB* blob, const DENORM* denorm, int num_max_matches,
207 int* unichar_ids, float* ratings, int* num_matches_returned);
208 #endif
209
210 TESS_API const char*
211 TESS_CALL TessBaseAPIGetUnichar(TessBaseAPI* handle, int unichar_id);
212
213 #ifdef TESS_CAPI_INCLUDE_BASEAPI
214 TESS_API const TessDawg*
215 TESS_CALL TessBaseAPIGetDawg(const TessBaseAPI* handle, int i);
216 TESS_API int TESS_CALL TessBaseAPINumDawgs(const TessBaseAPI* handle);
217 #endif
218
219 #ifdef TESS_CAPI_INCLUDE_BASEAPI
220 TESS_API ROW* TESS_CALL TessMakeTessOCRRow(float baseline, float xheight, float descender, float ascender);
221 TESS_API TBLOB*
222 TESS_CALL TessMakeTBLOB(Pix *pix);
223 TESS_API void TESS_CALL TessNormalizeTBLOB(TBLOB *tblob, ROW *row, BOOL numeric_mode, DENORM *denorm);
224
225 TESS_API TessOcrEngineMode
226 TESS_CALL TessBaseAPIOem(const TessBaseAPI* handle);
227 TESS_API void TESS_CALL TessBaseAPIInitTruthCallback(TessBaseAPI* handle, TessTruthCallback *cb);
228
229 TESS_API TessCubeRecoContext*
230 TESS_CALL TessBaseAPIGetCubeRecoContext(const TessBaseAPI* handle);
231 #endif
232
233 TESS_API void TESS_CALL TessBaseAPISetMinOrientationMargin(TessBaseAPI* handle, double margin);
234 #ifdef TESS_CAPI_INCLUDE_BASEAPI
235 TESS_API void TESS_CALL TessBaseGetBlockTextOrientations(TessBaseAPI* handle, int** block_orientation, bool** vertical_writing);
236
237 TESS_API BLOCK_LIST*
238 TESS_CALL TessBaseAPIFindLinesCreateBlockList(TessBaseAPI* handle);
239 #endif
240
241 /* Page iterator */
242
243 TESS_API void TESS_CALL TessPageIteratorDelete(TessPageIterator* handle);
244 TESS_API TessPageIterator*
245 TESS_CALL TessPageIteratorCopy(const TessPageIterator* handle);
246
247 TESS_API void TESS_CALL TessPageIteratorBegin(TessPageIterator* handle);
248 TESS_API BOOL TESS_CALL TessPageIteratorNext(TessPageIterator* handle, TessPageIteratorLevel level);
249 TESS_API BOOL TESS_CALL TessPageIteratorIsAtBeginningOf(const TessPageIterator* handle, TessPageIteratorLevel level);
250 TESS_API BOOL TESS_CALL TessPageIteratorIsAtFinalElement(const TessPageIterator* handle, TessPageIteratorLevel level,
251 TessPageIteratorLevel element);
252
253 TESS_API BOOL TESS_CALL TessPageIteratorBoundingBox(const TessPageIterator* handle, TessPageIteratorLevel level,
254 int* left, int* top, int* right, int* bottom);
255 TESS_API TessPolyBlockType
256 TESS_CALL TessPageIteratorBlockType(const TessPageIterator* handle);
257
258 TESS_API PIX* TESS_CALL TessPageIteratorGetBinaryImage(const TessPageIterator* handle, TessPageIteratorLevel level);
259 TESS_API PIX* TESS_CALL TessPageIteratorGetImage(const TessPageIterator* handle, TessPageIteratorLevel level, int padding,
260 int* left, int* top);
261
262 TESS_API BOOL TESS_CALL TessPageIteratorBaseline(const TessPageIterator* handle, TessPageIteratorLevel level,
263 int* x1, int* y1, int* x2, int* y2);
264
265 TESS_API void TESS_CALL TessPageIteratorOrientation(TessPageIterator* handle, TessOrientation *orientation,
266 TessWritingDirection *writing_direction, TessTextlineOrder *textline_order,
267 float *deskew_angle);
268
269 /* Result iterator */
270
271 TESS_API void TESS_CALL TessResultIteratorDelete(TessResultIterator* handle);
272 TESS_API TessResultIterator*
273 TESS_CALL TessResultIteratorCopy(const TessResultIterator* handle);
274 TESS_API TessPageIterator*
275 TESS_CALL TessResultIteratorGetPageIterator(TessResultIterator* handle);
276 TESS_API const TessPageIterator*
277 TESS_CALL TessResultIteratorGetPageIteratorConst(const TessResultIterator* handle);
278
279 TESS_API char* TESS_CALL TessResultIteratorGetUTF8Text(const TessResultIterator* handle, TessPageIteratorLevel level);
280 TESS_API float TESS_CALL TessResultIteratorConfidence(const TessResultIterator* handle, TessPageIteratorLevel level);
281
282 TESS_API const char*
283 TESS_CALL TessResultIteratorWordFontAttributes(const TessResultIterator* handle, BOOL* is_bold, BOOL* is_italic,
284 BOOL* is_underlined, BOOL* is_monospace, BOOL* is_serif,
285 BOOL* is_smallcaps, int* pointsize, int* font_id);
286
287 TESS_API BOOL TESS_CALL TessResultIteratorWordIsFromDictionary(const TessResultIterator* handle);
288 TESS_API BOOL TESS_CALL TessResultIteratorWordIsNumeric(const TessResultIterator* handle);
289 TESS_API BOOL TESS_CALL TessResultIteratorSymbolIsSuperscript(const TessResultIterator* handle);
290 TESS_API BOOL TESS_CALL TessResultIteratorSymbolIsSubscript(const TessResultIterator* handle);
291 TESS_API BOOL TESS_CALL TessResultIteratorSymbolIsDropcap(const TessResultIterator* handle);
292
293 #ifdef __cplusplus
294 }
295 #endif
296
297 #endif /* TESSERACT_API_CAPI_H__ */