forked from sirfz/tesserocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tesseract.pxd
469 lines (432 loc) · 20.2 KB
/
tesseract.pxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
from libcpp cimport bool
from libcpp.pair cimport pair
from libcpp.vector cimport vector
ctypedef const char cchar_t
ctypedef const char * cchar_tp
ctypedef const unsigned char cuchar_t
cdef extern from "leptonica/allheaders.h" nogil:
struct Pix:
int informat
int d
struct Box:
int x
int y
int w
int h
struct Boxa:
int n # number of box in ptr array
Box **box # box ptr array
struct Pixa:
int n # number of Pix in ptr array
Pix **pix # the array of ptrs to pix
Boxa *boxa # array of boxes
struct Pta:
int n # actual number of pts
float *x
float *y # arrays of floats
char *getImagelibVersions()
char *getLeptonicaVersion()
Pix *pixRead(cchar_t *)
Pix *pixReadMem(cuchar_t *, size_t)
Pix *pixReadMemBmp(cuchar_t *, size_t)
int pixWriteMemJpeg(unsigned char **, size_t *, Pix *, int, int)
int pixWriteMem(unsigned char **, size_t *, Pix *, int)
Pix *pixConvertTo8(Pix *, int)
void pixDestroy(Pix **)
void ptaDestroy(Pta **)
int setMsgSeverity(int)
void pixaDestroy(Pixa **)
void boxaDestroy(Boxa **)
cdef enum:
L_SEVERITY_EXTERNAL = 0 # Get the severity from the environment
L_SEVERITY_ALL = 1 # Lowest severity: print all messages
L_SEVERITY_DEBUG = 2 # Print debugging and higher messages
L_SEVERITY_INFO = 3 # Print informational and higher messages
L_SEVERITY_WARNING = 4 # Print warning and higher messages
L_SEVERITY_ERROR = 5 # Print error and higher messages
L_SEVERITY_NONE = 6 # Highest severity: print no messages
cdef extern from "tesseract/publictypes.h" nogil:
cdef enum PolyBlockType:
PT_UNKNOWN # Type is not yet known. Keep as the first element.
PT_FLOWING_TEXT # Text that lives inside a column.
PT_HEADING_TEXT # Text that spans more than one column.
PT_PULLOUT_TEXT # Text that is in a cross-column pull-out region.
PT_EQUATION # Partition belonging to an equation region.
PT_INLINE_EQUATION # Partition has inline equation.
PT_TABLE # Partition belonging to a table region.
PT_VERTICAL_TEXT # Text-line runs vertically.
PT_CAPTION_TEXT # Text that belongs to an image.
PT_FLOWING_IMAGE # Image that lives inside a column.
PT_HEADING_IMAGE # Image that spans more than one column.
PT_PULLOUT_IMAGE # Image that is in a cross-column pull-out region.
PT_HORZ_LINE # Horizontal Line.
PT_VERT_LINE # Vertical Line.
PT_NOISE # Lies outside of any column.
PT_COUNT
cdef extern from "tesseract/publictypes.h" namespace "tesseract" nogil:
cdef enum TessOrientation "tesseract::Orientation":
ORIENTATION_PAGE_UP
ORIENTATION_PAGE_RIGHT
ORIENTATION_PAGE_DOWN
ORIENTATION_PAGE_LEFT
cdef enum TessWritingDirection "tesseract::WritingDirection":
WRITING_DIRECTION_LEFT_TO_RIGHT
WRITING_DIRECTION_RIGHT_TO_LEFT
WRITING_DIRECTION_TOP_TO_BOTTOM
cdef enum TessTextlineOrder "tesseract::TextlineOrder":
TEXTLINE_ORDER_LEFT_TO_RIGHT
TEXTLINE_ORDER_RIGHT_TO_LEFT
TEXTLINE_ORDER_TOP_TO_BOTTOM
cdef enum TessParagraphJustification "tesseract::ParagraphJustification":
JUSTIFICATION_UNKNOWN
JUSTIFICATION_LEFT
JUSTIFICATION_CENTER
JUSTIFICATION_RIGHT
cdef extern from "tesseract/unichar.h" nogil:
cdef enum StrongScriptDirection:
DIR_NEUTRAL # Text contains only neutral characters.
DIR_LEFT_TO_RIGHT # Text contains no Right-to-Left characters.
DIR_RIGHT_TO_LEFT # Text contains no Left-to-Right characters.
DIR_MIX # Text contains a mixture of left-to-right
# and right-to-left characters.
cdef extern from "tesseract/genericvector.h" nogil:
cdef cppclass GenericVector[T]:
int size() const
int push_back(T)
bool empty() const
T &operator[](int) const
cdef extern from "tesseract/strngs.h" nogil:
cdef cppclass STRING:
cchar_t *c_str() const
STRING &operator=(cchar_t *)
cdef extern from "tesseract/ocrclass.h" nogil:
ctypedef bool (*CANCEL_FUNC)(void *, int)
cdef cppclass ETEXT_DESC:
ETEXT_DESC() except +
CANCEL_FUNC cancel # returns true to cancel
void *cancel_this # this or other data for cancel
void set_deadline_msecs(int)
cdef extern from "tesseract/pageiterator.h" namespace "tesseract" nogil:
cdef cppclass PageIterator:
void Begin()
void RestartParagraph()
bool IsWithinFirstTextlineOfParagraph() const
void RestartRow()
bool Next(PageIteratorLevel)
bool IsAtBeginningOf(PageIteratorLevel) const
bool IsAtFinalElement(PageIteratorLevel, PageIteratorLevel) const
void SetBoundingBoxComponents(bool, bool)
bool BoundingBox(PageIteratorLevel, const int, int *, int *, int *, int *) const
bool BoundingBoxInternal(PageIteratorLevel, int *, int *, int *, int *) const
bool Empty(PageIteratorLevel) const
PolyBlockType BlockType() const
Pta *BlockPolygon() const
Pix *GetBinaryImage(PageIteratorLevel) const
Pix *GetImage(PageIteratorLevel, int, Pix *, int *, int *) const
bool Baseline(PageIteratorLevel, int *, int *, int *, int *) const
void Orientation(TessOrientation *, TessWritingDirection *, TessTextlineOrder *, float *) const
void ParagraphInfo(TessParagraphJustification *, bool *, bool *, int *) const
cdef extern from "tesseract/ltrresultiterator.h" namespace "tesseract" nogil:
IF TESSERACT_VERSION >= 0x4000000:
cdef cppclass LTRResultIterator(PageIterator):
char *GetUTF8Text(PageIteratorLevel) const
void SetLineSeparator(cchar_t *)
void SetParagraphSeparator(cchar_t *)
float Confidence(PageIteratorLevel) const
void RowAttributes(float *, float *, float *) const
cchar_t *WordFontAttributes(bool *, bool *, bool *, bool *, bool *, bool *, int *, int *) const
cchar_t *WordRecognitionLanguage() const
StrongScriptDirection WordDirection() const
bool WordIsFromDictionary() const
int BlanksBeforeWord() const
bool WordIsNumeric() const
bool HasBlamerInfo() const
cchar_t *GetBlamerDebug() const
cchar_t *GetBlamerMisadaptionDebug() const
bool HasTruthString() const
bool EquivalentToTruth(cchar_t *) const
char *WordTruthUTF8Text() const
char *WordNormedUTF8Text() const
cchar_t *WordLattice(int *) const
bool SymbolIsSuperscript() const
bool SymbolIsSubscript() const
bool SymbolIsDropcap() const
ELIF TESSERACT_VERSION >= 0x3040100:
cdef cppclass LTRResultIterator(PageIterator):
char *GetUTF8Text(PageIteratorLevel) const
void SetLineSeparator(cchar_t *)
void SetParagraphSeparator(cchar_t *)
float Confidence(PageIteratorLevel) const
void RowAttributes(float *, float *, float *) const
cchar_t *WordFontAttributes(bool *, bool *, bool *, bool *, bool *, bool *, int *, int *) const
cchar_t *WordRecognitionLanguage() const
StrongScriptDirection WordDirection() const
bool WordIsFromDictionary() const
bool WordIsNumeric() const
bool HasBlamerInfo() const
cchar_t *GetBlamerDebug() const
cchar_t *GetBlamerMisadaptionDebug() const
bool HasTruthString() const
bool EquivalentToTruth(cchar_t *) const
char *WordTruthUTF8Text() const
char *WordNormedUTF8Text() const
cchar_t *WordLattice(int *) const
bool SymbolIsSuperscript() const
bool SymbolIsSubscript() const
bool SymbolIsDropcap() const
ELSE:
cdef cppclass LTRResultIterator(PageIterator):
char *GetUTF8Text(PageIteratorLevel) const
void SetLineSeparator(cchar_t *)
void SetParagraphSeparator(cchar_t *)
float Confidence(PageIteratorLevel) const
cchar_t *WordFontAttributes(bool *, bool *, bool *, bool *, bool *, bool *, int *, int *) const
cchar_t *WordRecognitionLanguage() const
StrongScriptDirection WordDirection() const
bool WordIsFromDictionary() const
bool WordIsNumeric() const
bool HasBlamerInfo() const
cchar_t *GetBlamerDebug() const
cchar_t *GetBlamerMisadaptionDebug() const
bool HasTruthString() const
bool EquivalentToTruth(cchar_t *) const
char *WordTruthUTF8Text() const
char *WordNormedUTF8Text() const
cchar_t *WordLattice(int *) const
bool SymbolIsSuperscript() const
bool SymbolIsSubscript() const
bool SymbolIsDropcap() const
cdef cppclass ChoiceIterator:
ChoiceIterator(const LTRResultIterator &) except +
bool Next()
cchar_t *GetUTF8Text() const
float Confidence() const
cdef extern from "tesseract/resultiterator.h" namespace "tesseract" nogil:
IF TESSERACT_VERSION >= 0x4000000:
cdef cppclass ResultIterator(LTRResultIterator):
bool ParagraphIsLtr() const
vector[vector[pair[cchar_tp, float]]] *GetBestLSTMSymbolChoices() const
ELSE:
cdef cppclass ResultIterator(LTRResultIterator):
bool ParagraphIsLtr() const
cdef extern from "tesseract/renderer.h" namespace "tesseract" nogil:
cdef cppclass TessResultRenderer:
void insert(TessResultRenderer *)
cdef cppclass TessTextRenderer(TessResultRenderer):
TessTextRenderer(cchar_t *) except +
IF TESSERACT_VERSION >= 0x3999800:
cdef cppclass TessAltoRenderer(TessResultRenderer):
TessAltoRenderer(cchar_t *) except +
cdef cppclass TessHOcrRenderer(TessResultRenderer):
TessHOcrRenderer(cchar_t *, bool) except +
IF TESSERACT_VERSION >= 0x3999800:
cdef cppclass TessPDFRenderer(TessResultRenderer):
TessPDFRenderer(cchar_t *, cchar_t *, bool) except +
ELSE:
cdef cppclass TessPDFRenderer(TessResultRenderer):
TessPDFRenderer(cchar_t *, cchar_t *) except +
cdef cppclass TessUnlvRenderer(TessResultRenderer):
TessUnlvRenderer(cchar_t *) except +
cdef cppclass TessBoxTextRenderer(TessResultRenderer):
TessBoxTextRenderer(cchar_t *) except +
IF TESSERACT_VERSION >= 0x3040100:
cdef cppclass TessOsdRenderer(TessResultRenderer):
TessOsdRenderer(cchar_t *) except +
cdef extern from "tesseract/osdetect.h" nogil:
struct OSBestResult:
int orientation_id
int script_id
float sconfidence
float oconfidence
ctypedef int (*get_best_script)(int)
struct OSResults:
get_best_script get_best_script
OSBestResult best_result
cdef extern from "tesseract/baseapi.h" namespace "tesseract" nogil:
IF TESSERACT_VERSION >= 0x3999800:
cdef enum OcrEngineMode:
OEM_TESSERACT_ONLY
OEM_LSTM_ONLY
OEM_TESSERACT_LSTM_COMBINED
OEM_DEFAULT
ELSE:
cdef enum OcrEngineMode:
OEM_TESSERACT_ONLY
OEM_CUBE_ONLY
OEM_TESSERACT_CUBE_COMBINED
OEM_DEFAULT
cdef enum PageSegMode:
PSM_OSD_ONLY, # Orientation and script detection only.
PSM_AUTO_OSD, # Automatic page segmentation with orientation and
# script detection. (OSD)
PSM_AUTO_ONLY, # Automatic page segmentation, but no OSD, or OCR.
PSM_AUTO, # Fully automatic page segmentation, but no OSD.
PSM_SINGLE_COLUMN, # Assume a single column of text of variable sizes.
PSM_SINGLE_BLOCK_VERT_TEXT, # Assume a single uniform block of vertically
# aligned text.
PSM_SINGLE_BLOCK, # Assume a single uniform block of text. (Default.)
PSM_SINGLE_LINE, # Treat the image as a single text line.
PSM_SINGLE_WORD, # Treat the image as a single word.
PSM_CIRCLE_WORD, # Treat the image as a single word in a circle.
PSM_SINGLE_CHAR, # Treat the image as a single character.
PSM_SPARSE_TEXT, # Find as much text as possible in no particular order.
PSM_SPARSE_TEXT_OSD, # Sparse text with orientation and script det.
PSM_RAW_LINE, # Treat the image as a single text line, bypassing
# hacks that are Tesseract-specific.
PSM_COUNT # Number of enum entries.
cdef enum PageIteratorLevel:
RIL_BLOCK, # of text/image/separator line.
RIL_PARA, # within a block.
RIL_TEXTLINE, # within a paragraph.
RIL_WORD, # within a textline.
RIL_SYMBOL # character within a word.
IF TESSERACT_VERSION >= 0x3999800:
cdef cppclass TessBaseAPI:
TessBaseAPI() except +
@staticmethod
cchar_t *Version()
@staticmethod
void ClearPersistentCache()
void SetInputName(cchar_t *)
cchar_t *GetInputName()
void SetInputImage(Pix *)
Pix *GetInputImage()
int GetSourceYResolution()
cchar_t *GetDatapath()
void SetOutputName(cchar_t *)
bool SetVariable(cchar_t *, cchar_t *)
bool SetDebugVariable(cchar_t *, cchar_t *)
bool GetIntVariable(cchar_t *, int *) const
bool GetBoolVariable(cchar_t *, bool *) const
bool GetDoubleVariable(cchar_t *, double *) const
cchar_t *GetStringVariable(cchar_t *) const
bool GetVariableAsString(cchar_t *, STRING *)
int Init(cchar_t *, cchar_t *, OcrEngineMode mode,
char **, int,
const GenericVector[STRING] *,
const GenericVector[STRING] *,
bool)
int Init(cchar_t *, cchar_t *, OcrEngineMode)
int Init(cchar_t *, cchar_t *)
cchar_t *GetInitLanguagesAsString() const
void GetLoadedLanguagesAsVector(GenericVector[STRING] *) const
void GetAvailableLanguagesAsVector(GenericVector[STRING] *) const
void InitForAnalysePage()
void ReadConfigFile(cchar_t *)
void SetPageSegMode(PageSegMode)
PageSegMode GetPageSegMode() const
char *TesseractRect(cuchar_t *, int, int, int, int, int, int)
void ClearAdaptiveClassifier()
void SetImage(cuchar_t *, int, int, int, int)
void SetImage(Pix *)
void SetSourceResolution(int)
void SetRectangle(int, int, int, int)
Pix *GetThresholdedImage()
Boxa *GetRegions(Pixa **)
Boxa *GetTextlines(const bool, const int, Pixa **, int **, int **)
Boxa *GetStrips(Pixa **, int **)
Boxa *GetWords(Pixa **)
Boxa *GetConnectedComponents(Pixa **)
Boxa *GetComponentImages(const PageIteratorLevel,
const bool, const bool,
const int,
Pixa **, int **, int **)
int GetThresholdedImageScaleFactor() const
PageIterator *AnalyseLayout(bool)
int Recognize(ETEXT_DESC *)
int RecognizeForChopTest(ETEXT_DESC *)
bool ProcessPages(cchar_t *, cchar_t *, int, TessResultRenderer *)
bool ProcessPage(Pix *, int, cchar_t *, cchar_t *, int, TessResultRenderer *)
ResultIterator *GetIterator()
char *GetUTF8Text()
char *GetHOCRText(int)
char *GetTSVText(int)
char *GetBoxText(int)
char *GetUNLVText()
bool DetectOrientationScript(int *, float *, cchar_t **, float *)
int MeanTextConf()
int *AllWordConfidences()
bool AdaptToWordStr(PageSegMode, cchar_t *)
void Clear()
void End()
int IsValidWord(cchar_t *)
bool IsValidCharacter(cchar_t *)
bool GetTextDirection(int *, float *)
bool DetectOS(OSResults *);
cchar_t *GetUnichar(int)
const OcrEngineMode oem() const
void set_min_orientation_margin(double)
ELSE:
cdef cppclass TessBaseAPI:
TessBaseAPI() except +
@staticmethod
cchar_t *Version()
@staticmethod
void ClearPersistentCache()
void SetInputName(cchar_t *)
cchar_t *GetInputName()
void SetInputImage(Pix *)
Pix *GetInputImage()
int GetSourceYResolution()
cchar_t *GetDatapath()
void SetOutputName(cchar_t *)
bool SetVariable(cchar_t *, cchar_t *)
bool SetDebugVariable(cchar_t *, cchar_t *)
bool GetIntVariable(cchar_t *, int *) const
bool GetBoolVariable(cchar_t *, bool *) const
bool GetDoubleVariable(cchar_t *, double *) const
cchar_t *GetStringVariable(cchar_t *) const
bool GetVariableAsString(cchar_t *, STRING *)
int Init(cchar_t *, cchar_t *, OcrEngineMode mode,
char **, int,
const GenericVector[STRING] *,
const GenericVector[STRING] *,
bool)
int Init(cchar_t *, cchar_t *, OcrEngineMode)
int Init(cchar_t *, cchar_t *)
cchar_t *GetInitLanguagesAsString() const
void GetLoadedLanguagesAsVector(GenericVector[STRING] *) const
void GetAvailableLanguagesAsVector(GenericVector[STRING] *) const
void InitForAnalysePage()
void ReadConfigFile(cchar_t *)
void SetPageSegMode(PageSegMode)
PageSegMode GetPageSegMode() const
char *TesseractRect(cuchar_t *, int, int, int, int, int, int)
void ClearAdaptiveClassifier()
void SetImage(cuchar_t *, int, int, int, int)
void SetImage(Pix *)
void SetSourceResolution(int)
void SetRectangle(int, int, int, int)
Pix *GetThresholdedImage()
Boxa *GetRegions(Pixa **)
Boxa *GetTextlines(const bool, const int, Pixa **, int **, int **)
Boxa *GetStrips(Pixa **, int **)
Boxa *GetWords(Pixa **)
Boxa *GetConnectedComponents(Pixa **)
Boxa *GetComponentImages(const PageIteratorLevel,
const bool, const bool,
const int,
Pixa **, int **, int **)
int GetThresholdedImageScaleFactor() const
PageIterator *AnalyseLayout(bool)
int Recognize(ETEXT_DESC *)
int RecognizeForChopTest(ETEXT_DESC *)
bool ProcessPages(cchar_t *, cchar_t *, int, TessResultRenderer *)
bool ProcessPage(Pix *, int, cchar_t *, cchar_t *, int, TessResultRenderer *)
ResultIterator *GetIterator()
char *GetUTF8Text()
char *GetHOCRText(int)
char *GetBoxText(int)
char *GetUNLVText()
int MeanTextConf()
int *AllWordConfidences()
bool AdaptToWordStr(PageSegMode, cchar_t *)
void Clear()
void End()
int IsValidWord(cchar_t *)
bool IsValidCharacter(cchar_t *)
bool GetTextDirection(int *, float *)
bool DetectOS(OSResults *);
cchar_t *GetUnichar(int)
const OcrEngineMode oem() const
void set_min_orientation_margin(double)