19 #ifndef TESSERACT_API_BASEAPI_H_ 20 #define TESSERACT_API_BASEAPI_H_ 26 #include "tess_version.h" 28 #include "pageiterator.h" 30 #include "publictypes.h" 31 #include "resultiterator.h" 33 #include "tesscallback.h" 34 #include "thresholder.h" 56 class WERD_CHOICE_LIST;
68 class LTRResultIterator;
70 class MutableIterator;
71 class TessResultRenderer;
78 UNICHAR_ID unichar_id,
bool word_end)
const;
82 const char* character,
85 const char *lang,
void *path);
87 const WERD_CHOICE_LIST &best_choices,
109 static const char* Version();
118 static size_t getOpenCLDevice(
void **device);
124 static void CatchSignals();
130 void SetInputName(
const char* name);
138 const char* GetInputName();
140 void SetInputImage(Pix *pix);
141 Pix* GetInputImage();
142 int GetSourceYResolution();
143 const char* GetDatapath();
146 void SetOutputName(
const char* name);
161 bool SetVariable(
const char* name,
const char* value);
162 bool SetDebugVariable(
const char* name,
const char* value);
168 bool GetIntVariable(
const char *name,
int *value)
const;
169 bool GetBoolVariable(
const char *name,
bool *value)
const;
170 bool GetDoubleVariable(
const char *name,
double *value)
const;
176 const char *GetStringVariable(
const char *name)
const;
181 void PrintVariables(FILE *fp)
const;
186 bool GetVariableAsString(
const char *name,
STRING *val);
226 int Init(
const char* datapath,
const char* language,
OcrEngineMode mode,
227 char **configs,
int configs_size,
230 bool set_only_non_debug_params);
232 return Init(datapath, language, oem,
nullptr, 0,
nullptr,
nullptr,
false);
234 int Init(
const char* datapath,
const char* language) {
235 return Init(datapath, language,
OEM_DEFAULT,
nullptr, 0,
nullptr,
nullptr,
false);
239 int Init(
const char* data,
int data_size,
const char* language,
243 bool set_only_non_debug_params,
FileReader reader);
253 const char* GetInitLanguagesAsString()
const;
273 int InitLangMod(
const char* datapath,
const char* language);
279 void InitForAnalysePage();
287 void ReadConfigFile(
const char* filename);
289 void ReadDebugConfigFile(
const char* filename);
318 char* TesseractRect(
const unsigned char* imagedata,
319 int bytes_per_pixel,
int bytes_per_line,
320 int left,
int top,
int width,
int height);
326 void ClearAdaptiveClassifier();
343 void SetImage(
const unsigned char* imagedata,
int width,
int height,
344 int bytes_per_pixel,
int bytes_per_line);
354 void SetImage(Pix* pix);
360 void SetSourceResolution(
int ppi);
367 void SetRectangle(
int left,
int top,
int width,
int height);
378 thresholder_ = thresholder;
387 Pix* GetThresholdedImage();
394 Boxa* GetRegions(Pixa** pixa);
407 Boxa* GetTextlines(
const bool raw_image,
const int raw_padding,
408 Pixa** pixa,
int** blockids,
int** paraids);
413 return GetTextlines(
false, 0, pixa, blockids,
nullptr);
424 Boxa* GetStrips(Pixa** pixa,
int** blockids);
431 Boxa* GetWords(Pixa** pixa);
441 Boxa* GetConnectedComponents(Pixa** cc);
457 const bool text_only,
const bool raw_image,
458 const int raw_padding,
459 Pixa** pixa,
int** blockids,
int** paraids);
462 const bool text_only,
463 Pixa** pixa,
int** blockids) {
464 return GetComponentImages(level, text_only,
false, 0, pixa, blockids,
nullptr);
473 int GetThresholdedImageScaleFactor()
const;
506 #ifndef DISABLED_LEGACY_ENGINE 508 int RecognizeForChopTest(
ETEXT_DESC* monitor);
533 bool ProcessPages(
const char* filename,
const char* retry_config,
536 bool ProcessPagesInternal(
const char* filename,
const char* retry_config,
548 bool ProcessPage(Pix* pix,
int page_index,
const char* filename,
549 const char* retry_config,
int timeout_millisec,
587 char* GetHOCRText(
ETEXT_DESC* monitor,
int page_number);
595 char* GetHOCRText(
int page_number);
602 char* GetTSVText(
int page_number);
611 char* GetBoxText(
int page_number);
629 bool DetectOrientationScript(
int* orient_deg,
float* orient_conf,
630 const char** script_name,
float* script_conf);
637 char* GetOsdText(
int page_number);
647 int* AllWordConfidences();
649 #ifndef DISABLED_LEGACY_ENGINE 660 bool AdaptToWordStr(
PageSegMode mode,
const char* wordstr);
661 #endif // ndef DISABLED_LEGACY_ENGINE 686 static void ClearPersistentCache();
694 int IsValidWord(
const char *word);
696 bool IsValidCharacter(
const char *utf8_character);
699 bool GetTextDirection(
int* out_offset,
float* out_slope);
719 void GetBlockTextOrientations(
int** block_orientation,
720 bool** vertical_writing);
723 #ifndef DISABLED_LEGACY_ENGINE 729 BLOCK_LIST* FindLinesCreateBlockList();
736 static void DeleteBlockList(BLOCK_LIST* block_list);
739 static ROW *MakeTessOCRRow(
float baseline,
float xheight,
740 float descender,
float ascender);
743 static TBLOB *MakeTBLOB(Pix *pix);
750 static void NormalizeTBLOB(
TBLOB *tblob,
ROW *row,
bool numeric_mode);
754 int* num_features,
int* feature_outline_index);
760 static ROW* FindRowForBox(BLOCK_LIST* blocks,
int left,
int top,
761 int right,
int bottom);
767 void RunAdaptiveClassifier(
TBLOB* blob,
771 int* num_matches_returned);
772 #endif // ndef DISABLED_LEGACY_ENGINE 775 const char* GetUnichar(
int unichar_id);
778 const Dawg *GetDawg(
int i)
const;
781 int NumDawgs()
const;
789 void set_min_orientation_margin(
double margin);
795 TESS_LOCAL
bool InternalSetImage();
801 TESS_LOCAL
virtual bool Threshold(Pix** pix);
807 TESS_LOCAL
int FindLines();
825 TESS_LOCAL
int TextLength(
int* blob_count);
830 #ifndef DISABLED_LEGACY_ENGINE 839 TESS_LOCAL
void AdaptToCharacter(
const char *unichar_repr,
847 TESS_LOCAL
PAGE_RES* RecognitionPass1(BLOCK_LIST* block_list);
849 TESS_LOCAL
PAGE_RES* RecognitionPass2(BLOCK_LIST* block_list,
856 TESS_LOCAL
static int TesseractExtractResult(
char** text,
867 #endif // ndef DISABLED_LEGACY_ENGINE 901 bool ProcessPagesFileList(FILE *fp,
903 const char* retry_config,
int timeout_millisec,
905 int tessedit_page_number);
907 bool ProcessPagesMultipageTiff(
const unsigned char *data,
909 const char* filename,
910 const char* retry_config,
911 int timeout_millisec,
913 int tessedit_page_number);
919 const char *unknown_title_ =
"";
926 #endif // TESSERACT_API_BASEAPI_H_ void DetectParagraphs(int debug_level, GenericVector< RowInfo > *row_infos, GenericVector< PARA *> *row_owners, PARA_LIST *paragraphs, GenericVector< ParagraphModel *> *models)
Definition: paragraphs.cpp:2271
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:874
int Init(const char *datapath, const char *language)
Definition: baseapi.h:234
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:870
int rect_top_
Definition: baseapi.h:892
Tesseract * tesseract() const
Definition: baseapi.h:783
Definition: ocrpara.h:114
Definition: wordrec.h:192
int rect_left_
Definition: baseapi.h:891
Definition: resultiterator.h:41
Definition: unicharset.h:146
Definition: osdetect.h:49
STRING HOcrEscape(const char *text)
Definition: baseapi.cpp:2632
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:879
bool(* FileReader)(const STRING &filename, GenericVector< char > *data)
Definition: genericvector.h:360
Definition: baseapi.cpp:94
STRING * language_
Last initialized language.
Definition: baseapi.h:881
int rect_width_
Definition: baseapi.h:893
TruthCallback * truth_cb_
Definition: baseapi.h:884
EquationDetect * equ_detect_
The equation detector.
Definition: baseapi.h:872
STRING * datapath_
Current location of tessdata.
Definition: baseapi.h:880
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:877
Definition: equationdetect.h:39
int Init(const char *datapath, const char *language, OcrEngineMode oem)
Definition: baseapi.h:231
PageIteratorLevel
Definition: publictypes.h:219
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:883
Tesseract * osd_tesseract_
For orientation & script detection.
Definition: baseapi.h:871
void InitTruthCallback(TruthCallback *cb)
Definition: baseapi.h:787
float(Dict::* ParamsModelClassifyFunc)(const char *lang, void *path)
Definition: baseapi.h:84
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:876
void(Wordrec::* FillLatticeFunc)(const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
Definition: baseapi.h:86
Definition: renderer.h:45
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, Pixa **pixa, int **blockids)
Definition: baseapi.h:461
Definition: pageres.h:675
double(Dict::* ProbabilityInContextFunc)(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
Definition: baseapi.h:79
TESS_LOCAL const PAGE_RES * GetPageRes() const
Definition: baseapi.h:865
STRING * input_file_
Name used by training code.
Definition: baseapi.h:878
OcrEngineMode oem() const
Definition: baseapi.h:785
void SetThresholder(ImageThresholder *thresholder)
Definition: baseapi.h:376
Definition: ltrresultiterator.h:48
Definition: mutableiterator.h:44
OcrEngineMode last_oem_requested_
Last ocr language mode requested.
Definition: baseapi.h:882
Definition: normalis.h:50
int(Dict::* DictFunc)(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
Definition: baseapi.h:76
Definition: tesseractclass.h:173
TessCallback4< const UNICHARSET &, int, PageIterator *, Pix * > TruthCallback
Definition: baseapi.h:91
int image_width_
Definition: baseapi.h:895
Definition: intproto.h:132
Definition: ocrclass.h:119
GenericVector< ParagraphModel * > * paragraph_models_
Definition: baseapi.h:875
Boxa * GetTextlines(Pixa **pixa, int **blockids)
Definition: baseapi.h:412
Definition: pageiterator.h:52
OcrEngineMode
Definition: publictypes.h:268
int image_height_
Definition: baseapi.h:896
Definition: publictypes.h:274
Definition: tesscallback.h:1709
FileReader reader_
Reads files from any filesystem.
Definition: baseapi.h:873
Definition: baseapi.h:101
Definition: thresholder.h:36
PageSegMode
Definition: publictypes.h:163
int rect_height_
Definition: baseapi.h:894