Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
capi.cpp
Go to the documentation of this file.
1 #ifndef TESS_CAPI_INCLUDE_BASEAPI
2 # define TESS_CAPI_INCLUDE_BASEAPI
3 #endif
4 #include "capi.h"
5 
7 {
8  return TessBaseAPI::Version();
9 }
10 
12 {
13  delete [] text;
14 }
15 
17 {
18  for (char** pos = arr; *pos != NULL; ++pos)
19  delete [] *pos;
20  delete [] arr;
21 }
22 
24 {
25  delete [] arr;
26 }
27 
28 TESS_API void TESS_CALL TessDeleteBlockList(BLOCK_LIST* block_list)
29 {
30  TessBaseAPI::DeleteBlockList(block_list);
31 }
32 
34 {
35  return new TessBaseAPI;
36 }
37 
39 {
40  delete handle;
41 }
42 
43 TESS_API void TESS_CALL TessBaseAPISetInputName(TessBaseAPI* handle, const char* name)
44 {
45  handle->SetInputName(name);
46 }
47 
48 TESS_API void TESS_CALL TessBaseAPISetOutputName(TessBaseAPI* handle, const char* name)
49 {
50  handle->SetOutputName(name);
51 }
52 
53 TESS_API BOOL TESS_CALL TessBaseAPISetVariable(TessBaseAPI* handle, const char* name, const char* value)
54 {
55  return handle->SetVariable(name, value) ? TRUE : FALSE;
56 }
57 
58 TESS_API BOOL TESS_CALL TessBaseAPISetDebugVariable(TessBaseAPI* handle, const char* name, const char* value)
59 {
60  return handle->SetVariable(name, value) ? TRUE : FALSE;
61 }
62 
63 TESS_API BOOL TESS_CALL TessBaseAPIGetIntVariable(const TessBaseAPI* handle, const char* name, int* value)
64 {
65  return handle->GetIntVariable(name, value) ? TRUE : FALSE;
66 }
67 
68 TESS_API BOOL TESS_CALL TessBaseAPIGetBoolVariable(const TessBaseAPI* handle, const char* name, BOOL* value)
69 {
70  bool boolValue;
71  if (handle->GetBoolVariable(name, &boolValue))
72  {
73  *value = boolValue ? TRUE : FALSE;
74  return TRUE;
75  }
76  else
77  {
78  return FALSE;
79  }
80 }
81 
82 TESS_API BOOL TESS_CALL TessBaseAPIGetDoubleVariable(const TessBaseAPI* handle, const char* name, double* value)
83 {
84  return handle->GetDoubleVariable(name, value) ? TRUE : FALSE;
85 }
86 
87 TESS_API const char* TESS_CALL TessBaseAPIGetStringVariable(const TessBaseAPI* handle, const char* name)
88 {
89  return handle->GetStringVariable(name);
90 }
91 
93 {
94  handle->PrintVariables(fp);
95 }
96 
98 {
99  FILE* fp = fopen(filename, "w");
100  if (fp != NULL)
101  {
102  handle->PrintVariables(fp);
103  fclose(fp);
104  return TRUE;
105  }
106  return FALSE;
107 }
108 
110 {
111  return handle->GetVariableAsString(name, val) ? TRUE : FALSE;
112 }
113 
114 TESS_API int TESS_CALL TessBaseAPIInit1(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode oem,
115  char** configs, int configs_size)
116 {
117  return handle->Init(datapath, language, oem, configs, configs_size, NULL, NULL, false);
118 }
119 
120 TESS_API int TESS_CALL TessBaseAPIInit2(TessBaseAPI* handle, const char* datapath, const char* language, TessOcrEngineMode oem)
121 {
122  return handle->Init(datapath, language, oem);
123 }
124 
125 TESS_API int TESS_CALL TessBaseAPIInit3(TessBaseAPI* handle, const char* datapath, const char* language)
126 {
127  return handle->Init(datapath, language);
128 }
129 
131 {
132  return handle->GetInitLanguagesAsString();
133 }
134 
136 {
137  GenericVector<STRING> languages;
138  handle->GetLoadedLanguagesAsVector(&languages);
139  char** arr = new char*[languages.size() + 1];
140  for (int index = 0; index < languages.size(); ++index)
141  arr[index] = languages[index].strdup();
142  arr[languages.size()] = NULL;
143  return arr;
144 }
145 
147 {
148  GenericVector<STRING> languages;
149  handle->GetAvailableLanguagesAsVector(&languages);
150  char** arr = new char*[languages.size() + 1];
151  for (int index = 0; index < languages.size(); ++index)
152  arr[index] = languages[index].strdup();
153  arr[languages.size()] = NULL;
154  return arr;
155 }
156 
157 TESS_API int TESS_CALL TessBaseAPIInitLangMod(TessBaseAPI* handle, const char* datapath, const char* language)
158 {
159  return handle->InitLangMod(datapath, language);
160 }
161 
163 {
164  handle->InitForAnalysePage();
165 }
166 
168 {
169  handle->ReadConfigFile(filename);
170 }
171 
173 {
174  handle->ReadDebugConfigFile(filename);
175 }
176 
178 {
179  handle->SetPageSegMode(mode);
180 }
181 
183 {
184  return handle->GetPageSegMode();
185 }
186 
187 TESS_API char* TESS_CALL TessBaseAPIRect(TessBaseAPI* handle, const unsigned char* imagedata,
188  int bytes_per_pixel, int bytes_per_line,
189  int left, int top, int width, int height)
190 {
191  return handle->TesseractRect(imagedata, bytes_per_pixel, bytes_per_line, left, top, width, height);
192 }
193 
195 {
196  handle->ClearAdaptiveClassifier();
197 }
198 
199 TESS_API void TESS_CALL TessBaseAPISetImage(TessBaseAPI* handle, const unsigned char* imagedata, int width, int height,
200  int bytes_per_pixel, int bytes_per_line)
201 {
202  handle->SetImage(imagedata, width, height, bytes_per_pixel, bytes_per_line);
203 }
204 
205 TESS_API void TESS_CALL TessBaseAPISetImage2(TessBaseAPI* handle, const Pix* pix)
206 {
207  return handle->SetImage(pix);
208 }
209 
211 {
212  handle->SetSourceResolution(ppi);
213 }
214 
215 TESS_API void TESS_CALL TessBaseAPISetRectangle(TessBaseAPI* handle, int left, int top, int width, int height)
216 {
217  handle->SetRectangle(left, top, width, height);
218 }
219 
220 TESS_API void TESS_CALL TessBaseAPISetThresholder(TessBaseAPI* handle, TessImageThresholder* thresholder)
221 {
222  handle->SetThresholder(thresholder);
223 }
224 
226 {
227  return handle->GetThresholdedImage();
228 }
229 
231 {
232  return handle->GetRegions(pixa);
233 }
234 
235 TESS_API Boxa* TESS_CALL TessBaseAPIGetTextlines(TessBaseAPI* handle, Pixa** pixa, int** blockids)
236 {
237  return handle->GetTextlines(pixa, blockids);
238 }
239 
240 TESS_API BOXA* TESS_CALL TessBaseAPIGetStrips(TessBaseAPI* handle, PIXA** pixa, int** blockids)
241 {
242  return handle->GetStrips(pixa, blockids);
243 }
244 
246 {
247  return handle->GetWords(pixa);
248 }
249 
251 {
252  return handle->GetConnectedComponents(cc);
253 }
254 
255 TESS_API Boxa* TESS_CALL TessBaseAPIGetComponentImages(TessBaseAPI* handle, TessPageIteratorLevel level, BOOL text_only, Pixa** pixa, int** blockids)
256 {
257  return handle->GetComponentImages(level, text_only != FALSE, pixa, blockids);
258 }
259 
261 {
262  return handle->GetThresholdedImageScaleFactor();
263 }
264 
266 {
267  handle->DumpPGM(filename);
268 }
269 
271 {
272  return handle->AnalyseLayout();
273 }
274 
276 {
277  return handle->Recognize(monitor);
278 }
279 
281 {
282  return handle->RecognizeForChopTest(monitor);
283 }
284 
285 TESS_API char* TESS_CALL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename, const char* retry_config,
286  int timeout_millisec)
287 {
289  if (handle->ProcessPages(filename, retry_config, timeout_millisec, &text_out))
290  return text_out.strdup();
291  else
292  return NULL;
293 }
294 
295 TESS_API char* TESS_CALL TessBaseAPIProcessPage(TessBaseAPI* handle, Pix* pix, int page_index, const char* filename,
296  const char* retry_config, int timeout_millisec)
297 {
299  if (handle->ProcessPage(pix, page_index, filename, retry_config, timeout_millisec, &text_out))
300  return text_out.strdup();
301  else
302  return NULL;
303 }
304 
306 {
307  return handle->GetIterator();
308 }
309 
311 {
312  return handle->GetMutableIterator();
313 }
314 
316 {
317  return handle->GetUTF8Text();
318 }
319 
320 TESS_API char* TESS_CALL TessBaseAPIGetHOCRText(TessBaseAPI* handle, int page_number)
321 {
322  return handle->GetHOCRText(page_number);
323 }
324 
325 TESS_API char* TESS_CALL TessBaseAPIGetBoxText(TessBaseAPI* handle, int page_number)
326 {
327  return handle->GetBoxText(page_number);
328 }
329 
331 {
332  return handle->GetUNLVText();
333 }
334 
336 {
337  return handle->MeanTextConf();
338 }
339 
341 {
342  return handle->AllWordConfidences();
343 }
344 
346 {
347  return handle->AdaptToWordStr(mode, wordstr) ? TRUE : FALSE;
348 }
349 
351 {
352  handle->Clear();
353 }
354 
356 {
357  handle->End();
358 }
359 
360 TESS_API int TESS_CALL TessBaseAPIIsValidWord(TessBaseAPI* handle, const char *word)
361 {
362  return handle->IsValidWord(word);
363 }
364 
365 TESS_API BOOL TESS_CALL TessBaseAPIGetTextDirection(TessBaseAPI* handle, int* out_offset, float* out_slope)
366 {
367  return handle->GetTextDirection(out_offset, out_slope) ? TRUE : FALSE;
368 }
369 
371 {
372  handle->SetDictFunc(f);
373 }
374 
375 TESS_API void TESS_CALL TessBaseAPISetProbabilityInContextFunc(TessBaseAPI* handle, TessProbabilityInContextFunc f)
376 {
377  handle->SetProbabilityInContextFunc(f);
378 }
379 
381 {
382  return handle->DetectOS(results) ? TRUE : FALSE;
383 }
384 
386  int* num_features, int* FeatureOutlineIndex)
387 {
388  handle->GetFeaturesForBlob(blob, *denorm, int_features, num_features, FeatureOutlineIndex);
389 }
390 
391 TESS_API ROW* TESS_CALL TessFindRowForBox(BLOCK_LIST* blocks, int left, int top, int right, int bottom)
392 {
393  return TessBaseAPI::FindRowForBox(blocks, left, top, right, bottom);
394 }
395 
396 TESS_API void TESS_CALL TessBaseAPIRunAdaptiveClassifier(TessBaseAPI* handle, TBLOB* blob, const DENORM* denorm, int num_max_matches,
397  int* unichar_ids, float* ratings, int* num_matches_returned)
398 {
399  handle->RunAdaptiveClassifier(blob, *denorm, num_max_matches, unichar_ids, ratings, num_matches_returned);
400 }
401 
402 TESS_API const char* TESS_CALL TessBaseAPIGetUnichar(TessBaseAPI* handle, int unichar_id)
403 {
404  return handle->GetUnichar(unichar_id);
405 }
406 
407 TESS_API const TessDawg* TESS_CALL TessBaseAPIGetDawg(const TessBaseAPI* handle, int i)
408 {
409  return handle->GetDawg(i);
410 }
411 
413 {
414  return handle->NumDawgs();
415 }
416 
417 TESS_API ROW* TESS_CALL TessMakeTessOCRRow(float baseline, float xheight, float descender, float ascender)
418 {
419  return TessBaseAPI::MakeTessOCRRow(baseline, xheight, descender, ascender);
420 }
421 
423 {
424  return TessBaseAPI::MakeTBLOB(pix);
425 }
426 
427 TESS_API void TESS_CALL TessNormalizeTBLOB(TBLOB *tblob, ROW *row, BOOL numeric_mode, DENORM *denorm)
428 {
429  TessBaseAPI::NormalizeTBLOB(tblob, row, numeric_mode != FALSE, denorm);
430 }
431 
433 {
434  return handle->oem();
435 }
436 
437 TESS_API void TESS_CALL TessBaseAPIInitTruthCallback(TessBaseAPI* handle, TessTruthCallback *cb)
438 {
439  handle->InitTruthCallback(cb);
440 }
441 
442 TESS_API TessCubeRecoContext* TESS_CALL TessBaseAPIGetCubeRecoContext(const TessBaseAPI* handle)
443 {
444  return handle->GetCubeRecoContext();
445 }
446 
448 {
449  handle->set_min_orientation_margin(margin);
450 }
451 
452 TESS_API void TESS_CALL TessBaseGetBlockTextOrientations(TessBaseAPI* handle, int** block_orientation, bool** vertical_writing)
453 {
454  handle->GetBlockTextOrientations(block_orientation, vertical_writing);
455 }
456 
458 {
459  return handle->FindLinesCreateBlockList();
460 }
461 
463 {
464  delete handle;
465 }
466 
468 {
469  return new TessPageIterator(*handle);
470 }
471 
473 {
474  handle->Begin();
475 }
476 
478 {
479  return handle->Next(level) ? TRUE : FALSE;
480 }
481 
483 {
484  return handle->IsAtBeginningOf(level) ? TRUE : FALSE;
485 }
486 
488  TessPageIteratorLevel element)
489 {
490  return handle->IsAtFinalElement(level, element) ? TRUE : FALSE;
491 }
492 
494  int* left, int* top, int* right, int* bottom)
495 {
496  return handle->BoundingBox(level, left, top, right, bottom) ? TRUE : FALSE;
497 }
498 
500 {
501  return handle->BlockType();
502 }
503 
505 {
506  return handle->GetBinaryImage(level);
507 }
508 
510  int* left, int* top)
511 {
512  return handle->GetImage(level, padding, left, top);
513 }
514 
516  int* x1, int* y1, int* x2, int* y2)
517 {
518  return handle->Baseline(level, x1, y1, x2, y2) ? TRUE : FALSE;
519 }
520 
522  TessWritingDirection *writing_direction, TessTextlineOrder *textline_order,
523  float *deskew_angle)
524 {
525  handle->Orientation(orientation, writing_direction, textline_order, deskew_angle);
526 }
527 
529 {
530  delete handle;
531 }
532 
534 {
535  return static_cast<TessResultIterator*>(new TessPageIterator(*handle));
536 }
537 
539 {
540  return handle;
541 }
542 
544 {
545  return handle;
546 }
547 
549 {
550  return handle->GetUTF8Text(level);
551 }
552 
554 {
555  return handle->Confidence(level);
556 }
557 
558 TESS_API const char* TESS_CALL TessResultIteratorWordFontAttributes(const TessResultIterator* handle, BOOL* is_bold, BOOL* is_italic,
559  BOOL* is_underlined, BOOL* is_monospace, BOOL* is_serif,
560  BOOL* is_smallcaps, int* pointsize, int* font_id)
561 {
562  bool bool_is_bold, bool_is_italic, bool_is_underlined, bool_is_monospace, bool_is_serif, bool_is_smallcaps;
563  const char* ret = handle->WordFontAttributes(&bool_is_bold, &bool_is_italic, &bool_is_underlined, &bool_is_monospace, &bool_is_serif,
564  &bool_is_smallcaps, pointsize, font_id);
565  if (is_bold)
566  *is_bold = bool_is_bold ? TRUE : FALSE;
567  if (is_italic)
568  *is_italic = bool_is_italic ? TRUE : FALSE;
569  if (is_underlined)
570  *is_underlined = bool_is_underlined ? TRUE : FALSE;
571  if (is_monospace)
572  *is_monospace = bool_is_monospace ? TRUE : FALSE;
573  if (is_serif)
574  *is_serif = bool_is_serif ? TRUE : FALSE;
575  if (is_smallcaps)
576  *is_smallcaps = bool_is_smallcaps ? TRUE : FALSE;
577  return ret;
578 }
579 
581 {
582  return handle->WordIsFromDictionary() ? TRUE : FALSE;
583 }
584 
586 {
587  return handle->WordIsNumeric() ? TRUE : FALSE;
588 }
589 
591 {
592  return handle->SymbolIsSuperscript() ? TRUE : FALSE;
593 }
594 
596 {
597  return handle->SymbolIsSubscript() ? TRUE : FALSE;
598 }
599 
601 {
602  return handle->SymbolIsDropcap() ? TRUE : FALSE;
603 }