tesseract  3.05.02
Advanced API

Functions

void tesseract::TessBaseAPI::SetImage (const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
 
void tesseract::TessBaseAPI::SetImage (Pix *pix)
 
void tesseract::TessBaseAPI::SetSourceResolution (int ppi)
 
void tesseract::TessBaseAPI::SetRectangle (int left, int top, int width, int height)
 
void tesseract::TessBaseAPI::SetThresholder (ImageThresholder *thresholder)
 
Pix * tesseract::TessBaseAPI::GetThresholdedImage ()
 
Boxa * tesseract::TessBaseAPI::GetRegions (Pixa **pixa)
 
Boxa * tesseract::TessBaseAPI::GetTextlines (const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
 
Boxa * tesseract::TessBaseAPI::GetTextlines (Pixa **pixa, int **blockids)
 
Boxa * tesseract::TessBaseAPI::GetStrips (Pixa **pixa, int **blockids)
 
Boxa * tesseract::TessBaseAPI::GetWords (Pixa **pixa)
 
Boxa * tesseract::TessBaseAPI::GetConnectedComponents (Pixa **cc)
 
Boxa * tesseract::TessBaseAPI::GetComponentImages (const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
 
Boxa * tesseract::TessBaseAPI::GetComponentImages (const PageIteratorLevel level, const bool text_only, Pixa **pixa, int **blockids)
 
int tesseract::TessBaseAPI::GetThresholdedImageScaleFactor () const
 
void tesseract::TessBaseAPI::DumpPGM (const char *filename)
 
PageIteratortesseract::TessBaseAPI::AnalyseLayout ()
 
PageIteratortesseract::TessBaseAPI::AnalyseLayout (bool merge_similar_words)
 
int tesseract::TessBaseAPI::Recognize (ETEXT_DESC *monitor)
 
int tesseract::TessBaseAPI::RecognizeForChopTest (ETEXT_DESC *monitor)
 
bool tesseract::TessBaseAPI::ProcessPages (const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
 
bool tesseract::TessBaseAPI::ProcessPagesInternal (const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
 
bool tesseract::TessBaseAPI::ProcessPage (Pix *pix, int page_index, const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
 
ResultIteratortesseract::TessBaseAPI::GetIterator ()
 
MutableIteratortesseract::TessBaseAPI::GetMutableIterator ()
 
char * tesseract::TessBaseAPI::GetUTF8Text ()
 
char * tesseract::TessBaseAPI::GetHOCRText (ETEXT_DESC *monitor, int page_number)
 
char * tesseract::TessBaseAPI::GetHOCRText (int page_number)
 
char * tesseract::TessBaseAPI::GetTSVText (int page_number)
 
char * tesseract::TessBaseAPI::GetBoxText (int page_number)
 
char * tesseract::TessBaseAPI::GetUNLVText ()
 
bool tesseract::TessBaseAPI::DetectOrientationScript (int *orient_deg, float *orient_conf, const char **script_name, float *script_conf)
 
char * tesseract::TessBaseAPI::GetOsdText (int page_number)
 
int tesseract::TessBaseAPI::MeanTextConf ()
 
int * tesseract::TessBaseAPI::AllWordConfidences ()
 
bool tesseract::TessBaseAPI::AdaptToWordStr (PageSegMode mode, const char *wordstr)
 
void tesseract::TessBaseAPI::Clear ()
 
void tesseract::TessBaseAPI::End ()
 
static void tesseract::TessBaseAPI::ClearPersistentCache ()
 
int tesseract::TessBaseAPI::IsValidWord (const char *word)
 
bool tesseract::TessBaseAPI::IsValidCharacter (const char *utf8_character)
 
bool tesseract::TessBaseAPI::GetTextDirection (int *out_offset, float *out_slope)
 
void tesseract::TessBaseAPI::SetDictFunc (DictFunc f)
 
void tesseract::TessBaseAPI::SetProbabilityInContextFunc (ProbabilityInContextFunc f)
 
void tesseract::TessBaseAPI::SetFillLatticeFunc (FillLatticeFunc f)
 
bool tesseract::TessBaseAPI::DetectOS (OSResults *)
 
void tesseract::TessBaseAPI::GetFeaturesForBlob (TBLOB *blob, INT_FEATURE_STRUCT *int_features, int *num_features, int *feature_outline_index)
 
static ROWtesseract::TessBaseAPI::FindRowForBox (BLOCK_LIST *blocks, int left, int top, int right, int bottom)
 
void tesseract::TessBaseAPI::RunAdaptiveClassifier (TBLOB *blob, int num_max_matches, int *unichar_ids, float *ratings, int *num_matches_returned)
 
const char * tesseract::TessBaseAPI::GetUnichar (int unichar_id)
 
const Dawgtesseract::TessBaseAPI::GetDawg (int i) const
 
int tesseract::TessBaseAPI::NumDawgs () const
 
static ROWtesseract::TessBaseAPI::MakeTessOCRRow (float baseline, float xheight, float descender, float ascender)
 
static TBLOBtesseract::TessBaseAPI::MakeTBLOB (Pix *pix)
 
static void tesseract::TessBaseAPI::NormalizeTBLOB (TBLOB *tblob, ROW *row, bool numeric_mode)
 
Tesseracttesseract::TessBaseAPI::tesseract () const
 
OcrEngineMode tesseract::TessBaseAPI::oem () const
 
void tesseract::TessBaseAPI::InitTruthCallback (TruthCallback *cb)
 
CubeRecoContexttesseract::TessBaseAPI::GetCubeRecoContext () const
 
void tesseract::TessBaseAPI::set_min_orientation_margin (double margin)
 
void tesseract::TessBaseAPI::GetBlockTextOrientations (int **block_orientation, bool **vertical_writing)
 
BLOCK_LIST * tesseract::TessBaseAPI::FindLinesCreateBlockList ()
 
static void tesseract::TessBaseAPI::DeleteBlockList (BLOCK_LIST *block_list)
 

Detailed Description

The following methods break TesseractRect into pieces, so you can get hold of the thresholded image, get the text in different formats, get bounding boxes, confidences etc.

Function Documentation

◆ AdaptToWordStr()

bool tesseract::TessBaseAPI::AdaptToWordStr ( PageSegMode  mode,
const char *  wordstr 
)

Applies the given word to the adaptive classifier if possible. The word must be SPACE-DELIMITED UTF-8 - l i k e t h i s , so it can tell the boundaries of the graphemes. Assumes that SetImage/SetRectangle have been used to set the image to the given word. The mode arg should be PSM_SINGLE_WORD or PSM_CIRCLE_WORD, as that will be used to control layout analysis. The currently set PageSegMode is preserved. Returns false if adaption was not possible for some reason.

Definition at line 2002 of file baseapi.cpp.

2002  {
2003  int debug = 0;
2004  GetIntVariable("applybox_debug", &debug);
2005  bool success = true;
2006  PageSegMode current_psm = GetPageSegMode();
2008  SetVariable("classify_enable_learning", "0");
2009  char* text = GetUTF8Text();
2010  if (debug) {
2011  tprintf("Trying to adapt \"%s\" to \"%s\"\n", text, wordstr);
2012  }
2013  if (text != NULL) {
2014  PAGE_RES_IT it(page_res_);
2015  WERD_RES* word_res = it.word();
2016  if (word_res != NULL) {
2017  word_res->word->set_text(wordstr);
2018  } else {
2019  success = false;
2020  }
2021  // Check to see if text matches wordstr.
2022  int w = 0;
2023  int t = 0;
2024  for (t = 0; text[t] != '\0'; ++t) {
2025  if (text[t] == '\n' || text[t] == ' ')
2026  continue;
2027  while (wordstr[w] != '\0' && wordstr[w] == ' ')
2028  ++w;
2029  if (text[t] != wordstr[w])
2030  break;
2031  ++w;
2032  }
2033  if (text[t] != '\0' || wordstr[w] != '\0') {
2034  // No match.
2035  delete page_res_;
2036  GenericVector<TBOX> boxes;
2040  PAGE_RES_IT pr_it(page_res_);
2041  if (pr_it.word() == NULL)
2042  success = false;
2043  else
2044  word_res = pr_it.word();
2045  } else {
2046  word_res->BestChoiceToCorrectText();
2047  }
2048  if (success) {
2049  tesseract_->EnableLearning = true;
2050  tesseract_->LearnWord(NULL, word_res);
2051  }
2052  delete [] text;
2053  } else {
2054  success = false;
2055  }
2056  SetPageSegMode(current_psm);
2057  return success;
2058 }
PAGE_RES * SetupApplyBoxes(const GenericVector< TBOX > &boxes, BLOCK_LIST *block_list)
PageSegMode GetPageSegMode() const
Definition: baseapi.cpp:465
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
void LearnWord(const char *fontname, WERD_RES *word)
Definition: adaptmatch.cpp:244
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:214
CMD_EVENTS mode
Definition: pgedit.cpp:116
bool GetIntVariable(const char *name, int *value) const
Definition: baseapi.cpp:226
void TidyUp(PAGE_RES *page_res)
#define tprintf(...)
Definition: tprintf.h:31
void ReSegmentByClassification(PAGE_RES *page_res)
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
WERD * word
Definition: pageres.h:175
void SetPageSegMode(PageSegMode mode)
Definition: baseapi.cpp:458
void BestChoiceToCorrectText()
Definition: pageres.cpp:917
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870
void set_text(const char *new_text)
Definition: werd.h:126

◆ AllWordConfidences()

int * tesseract::TessBaseAPI::AllWordConfidences ( )

Returns all word confidences (between 0 and 100) in an array, terminated by -1. The calling function must delete [] after use. The number of confidences should correspond to the number of space- delimited words in GetUTF8Text.

Returns an array of all word confidences, terminated by -1.

Definition at line 1968 of file baseapi.cpp.

1968  {
1969  if (tesseract_ == NULL ||
1970  (!recognition_done_ && Recognize(NULL) < 0))
1971  return NULL;
1972  int n_word = 0;
1973  PAGE_RES_IT res_it(page_res_);
1974  for (res_it.restart_page(); res_it.word() != NULL; res_it.forward())
1975  n_word++;
1976 
1977  int* conf = new int[n_word+1];
1978  n_word = 0;
1979  for (res_it.restart_page(); res_it.word() != NULL; res_it.forward()) {
1980  WERD_RES *word = res_it.word();
1981  WERD_CHOICE* choice = word->best_choice;
1982  int w_conf = static_cast<int>(100 + 5 * choice->certainty());
1983  // This is the eq for converting Tesseract confidence to 1..100
1984  if (w_conf < 0) w_conf = 0;
1985  if (w_conf > 100) w_conf = 100;
1986  conf[n_word++] = w_conf;
1987  }
1988  conf[n_word] = -1;
1989  return conf;
1990 }
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
float certainty() const
Definition: ratngs.h:328
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
WERD_CHOICE * best_choice
Definition: pageres.h:219
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:877
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
WERD * word
Definition: pageres.h:175

◆ AnalyseLayout() [1/2]

PageIterator * tesseract::TessBaseAPI::AnalyseLayout ( )

Runs page layout analysis in the mode set by SetPageSegMode. May optionally be called prior to Recognize to get access to just the page layout results. Returns an iterator to the results. If merge_similar_words is true, words are combined where suitable for use with a line recognizer. Use if you want to use AnalyseLayout to find the textlines, and then want to process textline fragments with an external line recognizer. Returns NULL on error or an empty page. The returned iterator must be deleted after use. WARNING! This class points to data held within the TessBaseAPI class, and therefore can only be used while the TessBaseAPI class still exists and has not been subjected to a call of Init, SetImage, Recognize, Clear, End DetectOS, or anything else that changes the internal PAGE_RES.

Definition at line 809 of file baseapi.cpp.

809 { return AnalyseLayout(false); }
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:809

◆ AnalyseLayout() [2/2]

PageIterator * tesseract::TessBaseAPI::AnalyseLayout ( bool  merge_similar_words)

Definition at line 811 of file baseapi.cpp.

811  {
812  if (FindLines() == 0) {
813  if (block_list_->empty())
814  return NULL; // The page was empty.
815  page_res_ = new PAGE_RES(merge_similar_words, block_list_, NULL);
816  DetectParagraphs(false);
817  return new PageIterator(
821  }
822  return NULL;
823 }
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
int GetScaledYResolution() const
Definition: thresholder.h:93
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2260
TESS_LOCAL void DetectParagraphs(bool after_text_recognition)
Definition: baseapi.cpp:2604
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870

◆ Clear()

void tesseract::TessBaseAPI::Clear ( )

Free up recognition results and any stored image data, without actually freeing any recognition data that would be time-consuming to reload. Afterwards, you must call SetImage or TesseractRect before doing any Recognize or Get* operation.

Definition at line 2066 of file baseapi.cpp.

2066  {
2067  if (thresholder_ != NULL)
2068  thresholder_->Clear();
2069  ClearResults();
2070  if (tesseract_ != NULL) SetInputImage(NULL);
2071 }
void SetInputImage(Pix *pix)
Definition: baseapi.cpp:938
virtual void Clear()
Destroy the Pix if there is one, freeing memory.
Definition: thresholder.cpp:45
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ ClearPersistentCache()

void tesseract::TessBaseAPI::ClearPersistentCache ( )
static

Clear any library-level memory caches. There are a variety of expensive-to-load constant data structures (mostly language dictionaries) that are cached globally – surviving the Init() and End() of individual TessBaseAPI's. This function allows the clearing of these caches.

Definition at line 2115 of file baseapi.cpp.

2115  {
2117 }
void DeleteUnusedDawgs()
Definition: dawg_cache.h:46
static DawgCache * GlobalDawgCache()
Definition: dict.cpp:198

◆ DeleteBlockList()

void tesseract::TessBaseAPI::DeleteBlockList ( BLOCK_LIST *  block_list)
static

Delete a block list. This is to keep BLOCK_LIST pointer opaque and let go of including the other headers.

Definition at line 2470 of file baseapi.cpp.

2470  {
2471  delete block_list;
2472 }

◆ DetectOrientationScript()

bool tesseract::TessBaseAPI::DetectOrientationScript ( int *  orient_deg,
float *  orient_conf,
const char **  script_name,
float *  script_conf 
)

Detect the orientation of the input image and apparent script (alphabet). orient_deg is the detected clockwise rotation of the input image in degrees (0, 90, 180, 270) orient_conf is the confidence (15.0 is reasonably confident) script_name is an ASCII string, the name of the script, e.g. "Latin" script_conf is confidence level in the script Returns true on success and writes values to each parameter as an output

Definition at line 1895 of file baseapi.cpp.

1895  {
1896  OSResults osr;
1897 
1898  bool osd = DetectOS(&osr);
1899  if (!osd) {
1900  return false;
1901  }
1902 
1903  int orient_id = osr.best_result.orientation_id;
1904  int script_id = osr.get_best_script(orient_id);
1905  if (orient_conf)
1906  *orient_conf = osr.best_result.oconfidence;
1907  if (orient_deg)
1908  *orient_deg = orient_id * 90; // convert quadrant to degrees
1909 
1910  if (script_name) {
1911  const char* script =
1912  osr.unicharset->get_script_from_script_id(script_id);
1913 
1914  *script_name = script;
1915  }
1916 
1917  if (script_conf)
1918  *script_conf = osr.best_result.sconfidence;
1919 
1920  return true;
1921 }
TESS_API int get_best_script(int orientation_id) const
Definition: osdetect.cpp:114
float oconfidence
Definition: osdetect.h:44
UNICHARSET * unicharset
Definition: osdetect.h:78
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:802
bool DetectOS(OSResults *)
Definition: baseapi.cpp:2381
float sconfidence
Definition: osdetect.h:43
int orientation_id
Definition: osdetect.h:41
OSBestResult best_result
Definition: osdetect.h:79

◆ DetectOS()

bool tesseract::TessBaseAPI::DetectOS ( OSResults osr)

Estimates the Orientation And Script of the image.

Returns
true if the image was processed successfully.

Estimates the Orientation And Script of the image. Returns true if the image was processed successfully.

Definition at line 2381 of file baseapi.cpp.

2381  {
2382  if (tesseract_ == NULL)
2383  return false;
2384  ClearResults();
2385  if (tesseract_->pix_binary() == NULL)
2387  if (input_file_ == NULL)
2388  input_file_ = new STRING(kInputFile);
2390 }
virtual TESS_LOCAL void Threshold(Pix **pix)
Definition: baseapi.cpp:2217
int orientation_and_script_detection(STRING &filename, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:191
Pix * pix_binary() const
Definition: strngs.h:44
const char * kInputFile
Definition: baseapi.cpp:95
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
STRING * input_file_
Name used by training code.
Definition: baseapi.h:872

◆ DumpPGM()

void tesseract::TessBaseAPI::DumpPGM ( const char *  filename)

Dump the internal binary image to a PGM file.

Deprecated:
Use GetThresholdedImage and write the image using pixWrite instead if possible.

Dump the internal binary image to a PGM file.

Definition at line 729 of file baseapi.cpp.

729  {
730  if (tesseract_ == NULL)
731  return;
732  FILE *fp = fopen(filename, "wb");
733  Pix* pix = tesseract_->pix_binary();
734  int width = pixGetWidth(pix);
735  int height = pixGetHeight(pix);
736  l_uint32* data = pixGetData(pix);
737  fprintf(fp, "P5 %d %d 255\n", width, height);
738  for (int y = 0; y < height; ++y, data += pixGetWpl(pix)) {
739  for (int x = 0; x < width; ++x) {
740  uinT8 b = GET_DATA_BIT(data, x) ? 0 : 255;
741  fwrite(&b, 1, 1, fp);
742  }
743  }
744  fclose(fp);
745 }
unsigned char uinT8
Definition: host.h:32
Pix * pix_binary() const
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ End()

void tesseract::TessBaseAPI::End ( )

Close down tesseract and free up all memory. End() is equivalent to destructing and reconstructing your TessBaseAPI. Once End() has been used, none of the other API functions may be used other than Init and anything declared above it in the class definition.

Definition at line 2079 of file baseapi.cpp.

2079  {
2080  Clear();
2081  delete thresholder_;
2082  thresholder_ = NULL;
2083  delete page_res_;
2084  page_res_ = NULL;
2085  delete block_list_;
2086  block_list_ = NULL;
2087  if (paragraph_models_ != NULL) {
2089  delete paragraph_models_;
2090  paragraph_models_ = NULL;
2091  }
2092  if (osd_tesseract_ == tesseract_)
2093  osd_tesseract_ = NULL;
2094  delete tesseract_;
2095  tesseract_ = NULL;
2096  delete osd_tesseract_;
2097  osd_tesseract_ = NULL;
2098  delete equ_detect_;
2099  equ_detect_ = NULL;
2100  delete input_file_;
2101  input_file_ = NULL;
2102  delete output_file_;
2103  output_file_ = NULL;
2104  delete datapath_;
2105  datapath_ = NULL;
2106  delete language_;
2107  language_ = NULL;
2108 }
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:873
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
Tesseract * osd_tesseract_
For orientation & script detection.
Definition: baseapi.h:866
GenericVector< ParagraphModel * > * paragraph_models_
Definition: baseapi.h:869
EquationDetect * equ_detect_
The equation detector.
Definition: baseapi.h:867
void delete_data_pointers()
STRING * language_
Last initialized language.
Definition: baseapi.h:875
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
STRING * input_file_
Name used by training code.
Definition: baseapi.h:872
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870
STRING * datapath_
Current location of tessdata.
Definition: baseapi.h:874

◆ FindLinesCreateBlockList()

BLOCK_LIST * tesseract::TessBaseAPI::FindLinesCreateBlockList ( )

Find lines from the image making the BLOCK_LIST.

Definition at line 2458 of file baseapi.cpp.

2458  {
2459  FindLines();
2460  BLOCK_LIST* result = block_list_;
2461  block_list_ = NULL;
2462  return result;
2463 }
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2260
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870

◆ FindRowForBox()

ROW * tesseract::TessBaseAPI::FindRowForBox ( BLOCK_LIST *  blocks,
int  left,
int  top,
int  right,
int  bottom 
)
static

This method returns the row to which a box of specified dimensions would belong. If no good match is found, it returns NULL.

Definition at line 2770 of file baseapi.cpp.

2771  {
2772  TBOX box(left, bottom, right, top);
2773  BLOCK_IT b_it(blocks);
2774  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
2775  BLOCK* block = b_it.data();
2776  if (!box.major_overlap(block->bounding_box()))
2777  continue;
2778  ROW_IT r_it(block->row_list());
2779  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
2780  ROW* row = r_it.data();
2781  if (!box.major_overlap(row->bounding_box()))
2782  continue;
2783  WERD_IT w_it(row->word_list());
2784  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
2785  WERD* word = w_it.data();
2786  if (box.major_overlap(word->bounding_box()))
2787  return row;
2788  }
2789  }
2790  }
2791  return NULL;
2792 }
TBOX bounding_box() const
Definition: ocrrow.h:85
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
Definition: werd.h:60
Definition: ocrrow.h:32
Definition: ocrblock.h:30
Definition: rect.h:30
WERD_LIST * word_list()
Definition: ocrrow.h:52
TBOX bounding_box() const
Definition: werd.cpp:160
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59

◆ GetBlockTextOrientations()

void tesseract::TessBaseAPI::GetBlockTextOrientations ( int **  block_orientation,
bool **  vertical_writing 
)

Return text orientation of each block as determined by an earlier run of layout analysis.

Return text orientation of each block as determined in an earlier page layout analysis operation. Orientation is returned as the number of ccw 90-degree rotations (in [0..3]) required to make the text in the block upright (readable). Note that this may not necessary be the block orientation preferred for recognition (such as the case of vertical CJK text).

Also returns whether the text in the block is believed to have vertical writing direction (when in an upright page orientation).

The returned array is of length equal to the number of text blocks, which may be less than the total number of blocks. The ordering is intended to be consistent with GetTextLines().

Definition at line 2410 of file baseapi.cpp.

2411  {
2412  delete[] *block_orientation;
2413  *block_orientation = NULL;
2414  delete[] *vertical_writing;
2415  *vertical_writing = NULL;
2416  BLOCK_IT block_it(block_list_);
2417 
2418  block_it.move_to_first();
2419  int num_blocks = 0;
2420  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
2421  if (!block_it.data()->poly_block()->IsText()) {
2422  continue;
2423  }
2424  ++num_blocks;
2425  }
2426  if (!num_blocks) {
2427  tprintf("WARNING: Found no blocks\n");
2428  return;
2429  }
2430  *block_orientation = new int[num_blocks];
2431  *vertical_writing = new bool[num_blocks];
2432  block_it.move_to_first();
2433  int i = 0;
2434  for (block_it.mark_cycle_pt(); !block_it.cycled_list();
2435  block_it.forward()) {
2436  if (!block_it.data()->poly_block()->IsText()) {
2437  continue;
2438  }
2439  FCOORD re_rotation = block_it.data()->re_rotation();
2440  float re_theta = re_rotation.angle();
2441  FCOORD classify_rotation = block_it.data()->classify_rotation();
2442  float classify_theta = classify_rotation.angle();
2443  double rot_theta = - (re_theta - classify_theta) * 2.0 / PI;
2444  if (rot_theta < 0) rot_theta += 4;
2445  int num_rotations = static_cast<int>(rot_theta + 0.5);
2446  (*block_orientation)[i] = num_rotations;
2447  // The classify_rotation is non-zero only if the text has vertical
2448  // writing direction.
2449  (*vertical_writing)[i] = classify_rotation.y() != 0.0f;
2450  ++i;
2451  }
2452 }
#define PI
Definition: const.h:19
float y() const
Definition: points.h:212
#define tprintf(...)
Definition: tprintf.h:31
Definition: points.h:189
float angle() const
find angle
Definition: points.h:249
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870

◆ GetBoxText()

char * tesseract::TessBaseAPI::GetBoxText ( int  page_number)

The recognized text is returned as a char* which is coded in the same format as a box file used in training. Returned string must be freed with the delete [] operator. Constructs coordinates in the original image - not just the rectangle. page_number is a 0-based page index that will appear in the box file.

The recognized text is returned as a char* which is coded as a UTF8 box file and must be freed with the delete [] operator. page_number is a 0-base page index that will appear in the box file.

Definition at line 1731 of file baseapi.cpp.

1731  {
1732  if (tesseract_ == NULL ||
1733  (!recognition_done_ && Recognize(NULL) < 0))
1734  return NULL;
1735  int blob_count;
1736  int utf8_length = TextLength(&blob_count);
1737  int total_length = blob_count * kBytesPerBoxFileLine + utf8_length +
1739  char* result = new char[total_length];
1740  result[0] = '\0';
1741  int output_length = 0;
1742  LTRResultIterator* it = GetLTRIterator();
1743  do {
1744  int left, top, right, bottom;
1745  if (it->BoundingBox(RIL_SYMBOL, &left, &top, &right, &bottom)) {
1746  char* text = it->GetUTF8Text(RIL_SYMBOL);
1747  // Tesseract uses space for recognition failure. Fix to a reject
1748  // character, kTesseractReject so we don't create illegal box files.
1749  for (int i = 0; text[i] != '\0'; ++i) {
1750  if (text[i] == ' ')
1751  text[i] = kTesseractReject;
1752  }
1753  snprintf(result + output_length, total_length - output_length,
1754  "%s %d %d %d %d %d\n",
1755  text, left, image_height_ - bottom,
1756  right, image_height_ - top, page_number);
1757  output_length += strlen(result + output_length);
1758  delete [] text;
1759  // Just in case...
1760  if (output_length + kMaxBytesPerLine > total_length)
1761  break;
1762  }
1763  } while (it->Next(RIL_SYMBOL));
1764  delete it;
1765  return result;
1766 }
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
const char kTesseractReject
Definition: baseapi.cpp:86
const int kMaxBytesPerLine
Definition: baseapi.cpp:1723
TESS_LOCAL LTRResultIterator * GetLTRIterator()
Definition: baseapi.cpp:1237
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:877
TESS_LOCAL int TextLength(int *blob_count)
Definition: baseapi.cpp:2351
const int kBytesPerBoxFileLine
Definition: baseapi.cpp:1714
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetComponentImages() [1/2]

Boxa * tesseract::TessBaseAPI::GetComponentImages ( const PageIteratorLevel  level,
const bool  text_only,
const bool  raw_image,
const int  raw_padding,
Pixa **  pixa,
int **  blockids,
int **  paraids 
)

Get the given level kind of components (block, textline, word etc.) as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize. If blockids is not NULL, the block-id of each component is also returned as an array of one element per component. delete [] after use. If blockids is not NULL, the paragraph-id of each component with its block is also returned as an array of one element per component. delete [] after use. If raw_image is true, then portions of the original image are extracted instead of the thresholded image and padded with raw_padding. If text_only is true, then only text components are returned.

Get the given level kind of components (block, textline, word etc.) as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize. If blockids is not NULL, the block-id of each component is also returned as an array of one element per component. delete [] after use. If text_only is true, then only text components are returned.

Definition at line 639 of file baseapi.cpp.

643  {
644  PageIterator* page_it = GetIterator();
645  if (page_it == NULL)
646  page_it = AnalyseLayout();
647  if (page_it == NULL)
648  return NULL; // Failed.
649 
650  // Count the components to get a size for the arrays.
651  int component_count = 0;
652  int left, top, right, bottom;
653 
654  TessResultCallback<bool>* get_bbox = NULL;
655  if (raw_image) {
656  // Get bounding box in original raw image with padding.
658  level, raw_padding,
659  &left, &top, &right, &bottom);
660  } else {
661  // Get bounding box from binarized imaged. Note that this could be
662  // differently scaled from the original image.
663  get_bbox = NewPermanentTessCallback(page_it,
665  level, &left, &top, &right, &bottom);
666  }
667  do {
668  if (get_bbox->Run() &&
669  (!text_only || PTIsTextType(page_it->BlockType())))
670  ++component_count;
671  } while (page_it->Next(level));
672 
673  Boxa* boxa = boxaCreate(component_count);
674  if (pixa != NULL)
675  *pixa = pixaCreate(component_count);
676  if (blockids != NULL)
677  *blockids = new int[component_count];
678  if (paraids != NULL)
679  *paraids = new int[component_count];
680 
681  int blockid = 0;
682  int paraid = 0;
683  int component_index = 0;
684  page_it->Begin();
685  do {
686  if (get_bbox->Run() &&
687  (!text_only || PTIsTextType(page_it->BlockType()))) {
688  Box* lbox = boxCreate(left, top, right - left, bottom - top);
689  boxaAddBox(boxa, lbox, L_INSERT);
690  if (pixa != NULL) {
691  Pix* pix = NULL;
692  if (raw_image) {
693  pix = page_it->GetImage(level, raw_padding, GetInputImage(), &left,
694  &top);
695  } else {
696  pix = page_it->GetBinaryImage(level);
697  }
698  pixaAddPix(*pixa, pix, L_INSERT);
699  pixaAddBox(*pixa, lbox, L_CLONE);
700  }
701  if (paraids != NULL) {
702  (*paraids)[component_index] = paraid;
703  if (page_it->IsAtFinalElement(RIL_PARA, level))
704  ++paraid;
705  }
706  if (blockids != NULL) {
707  (*blockids)[component_index] = blockid;
708  if (page_it->IsAtFinalElement(RIL_BLOCK, level)) {
709  ++blockid;
710  paraid = 0;
711  }
712  }
713  ++component_index;
714  }
715  } while (page_it->Next(level));
716  delete page_it;
717  delete get_bbox;
718  return boxa;
719 }
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
ResultIterator * GetIterator()
Definition: baseapi.cpp:1254
bool BoundingBox(PageIteratorLevel level, int *left, int *top, int *right, int *bottom) const
bool BoundingBoxInternal(PageIteratorLevel level, int *left, int *top, int *right, int *bottom) const
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:809
virtual R Run()=0

◆ GetComponentImages() [2/2]

Boxa* tesseract::TessBaseAPI::GetComponentImages ( const PageIteratorLevel  level,
const bool  text_only,
Pixa **  pixa,
int **  blockids 
)
inline

Definition at line 460 of file baseapi.h.

462  {
463  return GetComponentImages(level, text_only, false, 0, pixa, blockids, NULL);
464  }
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:639

◆ GetConnectedComponents()

Boxa * tesseract::TessBaseAPI::GetConnectedComponents ( Pixa **  pixa)

Gets the individual connected (text) components (created after pages segmentation step, but before recognition) as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize. Note: the caller is responsible for calling boxaDestroy() on the returned Boxa array and pixaDestroy() on cc array.

Gets the individual connected (text) components (created after pages segmentation step, but before recognition) as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize.

Definition at line 627 of file baseapi.cpp.

627  {
628  return GetComponentImages(RIL_SYMBOL, true, pixa, NULL);
629 }
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:639

◆ GetCubeRecoContext()

CubeRecoContext * tesseract::TessBaseAPI::GetCubeRecoContext ( ) const

Return a pointer to underlying CubeRecoContext object if present.

Definition at line 2835 of file baseapi.cpp.

2835  {
2836  return (tesseract_ == NULL) ? NULL : tesseract_->GetCubeRecoContext();
2837 }
CubeRecoContext * GetCubeRecoContext()
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetDawg()

const Dawg * tesseract::TessBaseAPI::GetDawg ( int  i) const

Return the pointer to the i-th dawg loaded into tesseract_ object.

Definition at line 2823 of file baseapi.cpp.

2823  {
2824  if (tesseract_ == NULL || i >= NumDawgs()) return NULL;
2825  return tesseract_->getDict().GetDawg(i);
2826 }
int NumDawgs() const
Definition: baseapi.cpp:2829
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
Definition: dict.h:412
Dict & getDict()
Definition: classify.h:65
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetFeaturesForBlob()

void tesseract::TessBaseAPI::GetFeaturesForBlob ( TBLOB blob,
INT_FEATURE_STRUCT int_features,
int *  num_features,
int *  feature_outline_index 
)

This method returns the features associated with the input image.

This method returns the features associated with the input blob.

Definition at line 2742 of file baseapi.cpp.

2745  {
2746  GenericVector<int> outline_counts;
2749  INT_FX_RESULT_STRUCT fx_info;
2750  tesseract_->ExtractFeatures(*blob, false, &bl_features,
2751  &cn_features, &fx_info, &outline_counts);
2752  if (cn_features.empty() || cn_features.size() > MAX_NUM_INT_FEATURES) {
2753  *num_features = 0;
2754  return; // Feature extraction failed.
2755  }
2756  *num_features = cn_features.size();
2757  memcpy(int_features, &cn_features[0], *num_features * sizeof(cn_features[0]));
2758  // TODO(rays) Pass outline_counts back and simplify the calling code.
2759  if (feature_outline_index != NULL) {
2760  int f = 0;
2761  for (int i = 0; i < outline_counts.size(); ++i) {
2762  while (f < outline_counts[i])
2763  feature_outline_index[f++] = i;
2764  }
2765  }
2766 }
#define MAX_NUM_INT_FEATURES
Definition: intproto.h:132
int size() const
Definition: genericvector.h:72
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
static void ExtractFeatures(const TBLOB &blob, bool nonlinear_norm, GenericVector< INT_FEATURE_STRUCT > *bl_features, GenericVector< INT_FEATURE_STRUCT > *cn_features, INT_FX_RESULT_STRUCT *results, GenericVector< int > *outline_cn_counts)
Definition: intfx.cpp:445
bool empty() const
Definition: genericvector.h:84

◆ GetHOCRText() [1/2]

char * tesseract::TessBaseAPI::GetHOCRText ( ETEXT_DESC monitor,
int  page_number 
)

Make a HTML-formatted string with hOCR markup from the internal data structures. page_number is 0-based but will appear in the output as 1-based. monitor can be used to cancel the recognition receive progress callbacks

Make a HTML-formatted string with hOCR markup from the internal data structures. page_number is 0-based but will appear in the output as 1-based. Image name/input_file_ can be set by SetInputName before calling GetHOCRText STL removed from original patch submission and refactored by rays.

Definition at line 1428 of file baseapi.cpp.

1428  {
1429  if (tesseract_ == NULL || (page_res_ == NULL && Recognize(monitor) < 0))
1430  return NULL;
1431 
1432  int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
1433  int page_id = page_number + 1; // hOCR uses 1-based page numbers.
1434  bool para_is_ltr = true; // Default direction is LTR
1435  const char* paragraph_lang = NULL;
1436  bool font_info = false;
1437  GetBoolVariable("hocr_font_info", &font_info);
1438 
1439  STRING hocr_str("");
1440 
1441  if (input_file_ == NULL)
1442  SetInputName(NULL);
1443 
1444 #ifdef _WIN32
1445  // convert input name from ANSI encoding to utf-8
1446  int str16_len =
1447  MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1, NULL, 0);
1448  wchar_t *uni16_str = new WCHAR[str16_len];
1449  str16_len = MultiByteToWideChar(CP_ACP, 0, input_file_->string(), -1,
1450  uni16_str, str16_len);
1451  int utf8_len = WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, NULL, 0,
1452  NULL, NULL);
1453  char *utf8_str = new char[utf8_len];
1454  WideCharToMultiByte(CP_UTF8, 0, uni16_str, str16_len, utf8_str,
1455  utf8_len, NULL, NULL);
1456  *input_file_ = utf8_str;
1457  delete[] uni16_str;
1458  delete[] utf8_str;
1459 #endif
1460 
1461  hocr_str += " <div class='ocr_page'";
1462  AddIdTohOCR(&hocr_str, "page", page_id, -1);
1463  hocr_str += " title='image \"";
1464  if (input_file_) {
1465  hocr_str += HOcrEscape(input_file_->string());
1466  } else {
1467  hocr_str += "unknown";
1468  }
1469  hocr_str.add_str_int("\"; bbox ", rect_left_);
1470  hocr_str.add_str_int(" ", rect_top_);
1471  hocr_str.add_str_int(" ", rect_width_);
1472  hocr_str.add_str_int(" ", rect_height_);
1473  hocr_str.add_str_int("; ppageno ", page_number);
1474  hocr_str += "'>\n";
1475 
1476  ResultIterator *res_it = GetIterator();
1477  while (!res_it->Empty(RIL_BLOCK)) {
1478  if (res_it->Empty(RIL_WORD)) {
1479  res_it->Next(RIL_WORD);
1480  continue;
1481  }
1482 
1483  // Open any new block/paragraph/textline.
1484  if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
1485  para_is_ltr = true; // reset to default direction
1486  hocr_str += " <div class='ocr_carea'";
1487  AddIdTohOCR(&hocr_str, "block", page_id, bcnt);
1488  AddBoxTohOCR(res_it, RIL_BLOCK, &hocr_str);
1489  }
1490  if (res_it->IsAtBeginningOf(RIL_PARA)) {
1491  hocr_str += "\n <p class='ocr_par'";
1492  para_is_ltr = res_it->ParagraphIsLtr();
1493  if (!para_is_ltr) {
1494  hocr_str += " dir='rtl'";
1495  }
1496  AddIdTohOCR(&hocr_str, "par", page_id, pcnt);
1497  paragraph_lang = res_it->WordRecognitionLanguage();
1498  if (paragraph_lang) {
1499  hocr_str += " lang='";
1500  hocr_str += paragraph_lang;
1501  hocr_str += "'";
1502  }
1503  AddBoxTohOCR(res_it, RIL_PARA, &hocr_str);
1504  }
1505  if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
1506  hocr_str += "\n <span class='ocr_line'";
1507  AddIdTohOCR(&hocr_str, "line", page_id, lcnt);
1508  AddBoxTohOCR(res_it, RIL_TEXTLINE, &hocr_str);
1509  }
1510 
1511  // Now, process the word...
1512  hocr_str += "<span class='ocrx_word'";
1513  AddIdTohOCR(&hocr_str, "word", page_id, wcnt);
1514  int left, top, right, bottom;
1515  bool bold, italic, underlined, monospace, serif, smallcaps;
1516  int pointsize, font_id;
1517  const char *font_name;
1518  res_it->BoundingBox(RIL_WORD, &left, &top, &right, &bottom);
1519  font_name = res_it->WordFontAttributes(&bold, &italic, &underlined,
1520  &monospace, &serif, &smallcaps,
1521  &pointsize, &font_id);
1522  hocr_str.add_str_int(" title='bbox ", left);
1523  hocr_str.add_str_int(" ", top);
1524  hocr_str.add_str_int(" ", right);
1525  hocr_str.add_str_int(" ", bottom);
1526  hocr_str.add_str_int("; x_wconf ", res_it->Confidence(RIL_WORD));
1527  if (font_info) {
1528  if (font_name) {
1529  hocr_str += "; x_font ";
1530  hocr_str += HOcrEscape(font_name);
1531  }
1532  hocr_str.add_str_int("; x_fsize ", pointsize);
1533  }
1534  hocr_str += "'";
1535  const char* lang = res_it->WordRecognitionLanguage();
1536  if (lang && (!paragraph_lang || strcmp(lang, paragraph_lang))) {
1537  hocr_str += " lang='";
1538  hocr_str += lang;
1539  hocr_str += "'";
1540  }
1541  switch (res_it->WordDirection()) {
1542  // Only emit direction if different from current paragraph direction
1543  case DIR_LEFT_TO_RIGHT:
1544  if (!para_is_ltr) hocr_str += " dir='ltr'";
1545  break;
1546  case DIR_RIGHT_TO_LEFT:
1547  if (para_is_ltr) hocr_str += " dir='rtl'";
1548  break;
1549  case DIR_MIX:
1550  case DIR_NEUTRAL:
1551  default: // Do nothing.
1552  break;
1553  }
1554  hocr_str += ">";
1555  bool last_word_in_line = res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD);
1556  bool last_word_in_para = res_it->IsAtFinalElement(RIL_PARA, RIL_WORD);
1557  bool last_word_in_block = res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD);
1558  if (bold) hocr_str += "<strong>";
1559  if (italic) hocr_str += "<em>";
1560  do {
1561  const char *grapheme = res_it->GetUTF8Text(RIL_SYMBOL);
1562  if (grapheme && grapheme[0] != 0) {
1563  hocr_str += HOcrEscape(grapheme);
1564  }
1565  delete []grapheme;
1566  res_it->Next(RIL_SYMBOL);
1567  } while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
1568  if (italic) hocr_str += "</em>";
1569  if (bold) hocr_str += "</strong>";
1570  hocr_str += "</span> ";
1571  wcnt++;
1572  // Close any ending block/paragraph/textline.
1573  if (last_word_in_line) {
1574  hocr_str += "\n </span>";
1575  lcnt++;
1576  }
1577  if (last_word_in_para) {
1578  hocr_str += "\n </p>\n";
1579  pcnt++;
1580  para_is_ltr = true; // back to default direction
1581  }
1582  if (last_word_in_block) {
1583  hocr_str += " </div>\n";
1584  bcnt++;
1585  }
1586  }
1587  hocr_str += " </div>\n";
1588 
1589  char *ret = new char[hocr_str.length() + 1];
1590  strcpy(ret, hocr_str.string());
1591  delete res_it;
1592  return ret;
1593 }
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
ResultIterator * GetIterator()
Definition: baseapi.cpp:1254
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
bool GetBoolVariable(const char *name, bool *value) const
Definition: baseapi.cpp:234
void add_str_int(const char *str, int number)
Definition: strngs.cpp:384
const char * string() const
Definition: strngs.cpp:201
Definition: strngs.h:44
void SetInputName(const char *name)
Definition: baseapi.cpp:199
STRING HOcrEscape(const char *text)
Definition: baseapi.cpp:2841
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
STRING * input_file_
Name used by training code.
Definition: baseapi.h:872

◆ GetHOCRText() [2/2]

char * tesseract::TessBaseAPI::GetHOCRText ( int  page_number)

Make a HTML-formatted string with hOCR markup from the internal data structures. page_number is 0-based but will appear in the output as 1-based.

Make a HTML-formatted string with hOCR markup from the internal data structures. page_number is 0-based but will appear in the output as 1-based. Image name/input_file_ can be set by SetInputName before calling GetHOCRText STL removed from original patch submission and refactored by rays.

Definition at line 1416 of file baseapi.cpp.

1416  {
1417  return GetHOCRText(NULL, page_number);
1418 }
char * GetHOCRText(ETEXT_DESC *monitor, int page_number)
Definition: baseapi.cpp:1428

◆ GetIterator()

ResultIterator * tesseract::TessBaseAPI::GetIterator ( )

Get a reading-order iterator to the results of LayoutAnalysis and/or Recognize. The returned iterator must be deleted after use. WARNING! This class points to data held within the TessBaseAPI class, and therefore can only be used while the TessBaseAPI class still exists and has not been subjected to a call of Init, SetImage, Recognize, Clear, End DetectOS, or anything else that changes the internal PAGE_RES.

Definition at line 1254 of file baseapi.cpp.

1254  {
1255  if (tesseract_ == NULL || page_res_ == NULL)
1256  return NULL;
1257  return ResultIterator::StartOfParagraph(LTRResultIterator(
1261 }
static ResultIterator * StartOfParagraph(const LTRResultIterator &resit)
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
int GetScaledYResolution() const
Definition: thresholder.h:93
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetMutableIterator()

MutableIterator * tesseract::TessBaseAPI::GetMutableIterator ( )

Get a mutable iterator to the results of LayoutAnalysis and/or Recognize. The returned iterator must be deleted after use. WARNING! This class points to data held within the TessBaseAPI class, and therefore can only be used while the TessBaseAPI class still exists and has not been subjected to a call of Init, SetImage, Recognize, Clear, End DetectOS, or anything else that changes the internal PAGE_RES.

Definition at line 1271 of file baseapi.cpp.

1271  {
1272  if (tesseract_ == NULL || page_res_ == NULL)
1273  return NULL;
1274  return new MutableIterator(page_res_, tesseract_,
1278 }
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
int GetScaledYResolution() const
Definition: thresholder.h:93
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetOsdText()

char * tesseract::TessBaseAPI::GetOsdText ( int  page_number)

The recognized text is returned as a char* which is coded as UTF8 and must be freed with the delete [] operator. page_number is a 0-based page index that will appear in the osd file.

Definition at line 1928 of file baseapi.cpp.

1928  {
1929  int orient_deg;
1930  float orient_conf;
1931  const char* script_name;
1932  float script_conf;
1933 
1934  if (!DetectOrientationScript(&orient_deg, &orient_conf, &script_name, &script_conf))
1935  return NULL;
1936 
1937  // clockwise rotation needed to make the page upright
1938  int rotate = OrientationIdToValue(orient_deg / 90);
1939 
1940  const int kOsdBufsize = 255;
1941  char* osd_buf = new char[kOsdBufsize];
1942  snprintf(osd_buf, kOsdBufsize,
1943  "Page number: %d\n"
1944  "Orientation in degrees: %d\n"
1945  "Rotate: %d\n"
1946  "Orientation confidence: %.2f\n"
1947  "Script: %s\n"
1948  "Script confidence: %.2f\n",
1949  page_number, orient_deg, rotate, orient_conf, script_name,
1950  script_conf);
1951 
1952  return osd_buf;
1953 }
int OrientationIdToValue(const int &id)
Definition: osdetect.cpp:565
bool DetectOrientationScript(int *orient_deg, float *orient_conf, const char **script_name, float *script_conf)
Definition: baseapi.cpp:1895

◆ GetRegions()

Boxa * tesseract::TessBaseAPI::GetRegions ( Pixa **  pixa)

Get the result of page layout analysis as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize.

Definition at line 582 of file baseapi.cpp.

582  {
583  return GetComponentImages(RIL_BLOCK, false, pixa, NULL);
584 }
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:639

◆ GetStrips()

Boxa * tesseract::TessBaseAPI::GetStrips ( Pixa **  pixa,
int **  blockids 
)

Get textlines and strips of image regions as a leptonica-style Boxa, Pixa pair, in reading order. Enables downstream handling of non-rectangular regions. Can be called before or after Recognize. If blockids is not NULL, the block-id of each line is also returned as an array of one element per line. delete [] after use.

Definition at line 608 of file baseapi.cpp.

608  {
609  return GetComponentImages(RIL_TEXTLINE, false, pixa, blockids);
610 }
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:639

◆ GetTextDirection()

bool tesseract::TessBaseAPI::GetTextDirection ( int *  out_offset,
float *  out_slope 
)

Definition at line 2134 of file baseapi.cpp.

2134  {
2135  PageIterator* it = AnalyseLayout();
2136  if (it == NULL) {
2137  return false;
2138  }
2139  int x1, x2, y1, y2;
2140  it->Baseline(RIL_TEXTLINE, &x1, &y1, &x2, &y2);
2141  // Calculate offset and slope (NOTE: Kind of ugly)
2142  if (x2 <= x1) x2 = x1 + 1;
2143  // Convert the point pair to slope/offset of the baseline (in image coords.)
2144  *out_slope = static_cast<float>(y2 - y1) / (x2 - x1);
2145  *out_offset = static_cast<int>(y1 - *out_slope * x1);
2146  // Get the y-coord of the baseline at the left and right edges of the
2147  // textline's bounding box.
2148  int left, top, right, bottom;
2149  if (!it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom)) {
2150  delete it;
2151  return false;
2152  }
2153  int left_y = IntCastRounded(*out_slope * left + *out_offset);
2154  int right_y = IntCastRounded(*out_slope * right + *out_offset);
2155  // Shift the baseline down so it passes through the nearest bottom-corner
2156  // of the textline's bounding box. This is the difference between the y
2157  // at the lowest (max) edge of the box and the actual box bottom.
2158  *out_offset += bottom - MAX(left_y, right_y);
2159  // Switch back to bottom-up tesseract coordinates. Requires negation of
2160  // the slope and height - offset for the offset.
2161  *out_slope = -*out_slope;
2162  *out_offset = rect_height_ - *out_offset;
2163  delete it;
2164 
2165  return true;
2166 }
int IntCastRounded(double x)
Definition: helpers.h:172
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:809
#define MAX(x, y)
Definition: ndminx.h:24

◆ GetTextlines() [1/2]

Boxa * tesseract::TessBaseAPI::GetTextlines ( const bool  raw_image,
const int  raw_padding,
Pixa **  pixa,
int **  blockids,
int **  paraids 
)

Get the textlines as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize. If raw_image is true, then extract from the original image instead of the thresholded image and pad by raw_padding pixels. If blockids is not NULL, the block-id of each line is also returned as an array of one element per line. delete [] after use. If paraids is not NULL, the paragraph-id of each line within its block is also returned as an array of one element per line. delete [] after use.

Get the textlines as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize. If blockids is not NULL, the block-id of each line is also returned as an array of one element per line. delete [] after use. If paraids is not NULL, the paragraph-id of each line within its block is also returned as an array of one element per line. delete [] after use.

Definition at line 594 of file baseapi.cpp.

595  {
596  return GetComponentImages(RIL_TEXTLINE, true, raw_image, raw_padding,
597  pixa, blockids, paraids);
598 }
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:639

◆ GetTextlines() [2/2]

Boxa* tesseract::TessBaseAPI::GetTextlines ( Pixa **  pixa,
int **  blockids 
)
inline

Definition at line 411 of file baseapi.h.

411  {
412  return GetTextlines(false, 0, pixa, blockids, NULL);
413  }
Boxa * GetTextlines(const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:594

◆ GetThresholdedImage()

Pix * tesseract::TessBaseAPI::GetThresholdedImage ( )

Get a copy of the internal thresholded image from Tesseract. Caller takes ownership of the Pix and must pixDestroy it. May be called any time after SetImage, or after TesseractRect.

ONLY available after SetImage if you have Leptonica installed. Get a copy of the internal thresholded image from Tesseract.

Definition at line 569 of file baseapi.cpp.

569  {
570  if (tesseract_ == NULL || thresholder_ == NULL)
571  return NULL;
572  if (tesseract_->pix_binary() == NULL)
574  return pixClone(tesseract_->pix_binary());
575 }
virtual TESS_LOCAL void Threshold(Pix **pix)
Definition: baseapi.cpp:2217
Pix * pix_binary() const
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetThresholdedImageScaleFactor()

int tesseract::TessBaseAPI::GetThresholdedImageScaleFactor ( ) const

Returns the scale factor of the thresholded image that would be returned by GetThresholdedImage() and the various GetX() methods that call GetComponentImages(). Returns 0 if no thresholder has been set.

Definition at line 721 of file baseapi.cpp.

721  {
722  if (thresholder_ == NULL) {
723  return 0;
724  }
725  return thresholder_->GetScaleFactor();
726 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868

◆ GetTSVText()

char * tesseract::TessBaseAPI::GetTSVText ( int  page_number)

Make a TSV-formatted string from the internal data structures. page_number is 0-based but will appear in the output as 1-based.

Definition at line 1599 of file baseapi.cpp.

1599  {
1600  if (tesseract_ == NULL || (page_res_ == NULL && Recognize(NULL) < 0))
1601  return NULL;
1602 
1603  int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
1604  int page_id = page_number + 1; // we use 1-based page numbers.
1605 
1606  STRING tsv_str("");
1607 
1608  int page_num = page_id, block_num = 0, par_num = 0, line_num = 0,
1609  word_num = 0;
1610 
1611  tsv_str.add_str_int("1\t", page_num); // level 1 - page
1612  tsv_str.add_str_int("\t", block_num);
1613  tsv_str.add_str_int("\t", par_num);
1614  tsv_str.add_str_int("\t", line_num);
1615  tsv_str.add_str_int("\t", word_num);
1616  tsv_str.add_str_int("\t", rect_left_);
1617  tsv_str.add_str_int("\t", rect_top_);
1618  tsv_str.add_str_int("\t", rect_width_);
1619  tsv_str.add_str_int("\t", rect_height_);
1620  tsv_str += "\t-1\t\n";
1621 
1622  ResultIterator* res_it = GetIterator();
1623  while (!res_it->Empty(RIL_BLOCK)) {
1624  if (res_it->Empty(RIL_WORD)) {
1625  res_it->Next(RIL_WORD);
1626  continue;
1627  }
1628 
1629  // Add rows for any new block/paragraph/textline.
1630  if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
1631  block_num++, par_num = 0, line_num = 0, word_num = 0;
1632  tsv_str.add_str_int("2\t", page_num); // level 2 - block
1633  tsv_str.add_str_int("\t", block_num);
1634  tsv_str.add_str_int("\t", par_num);
1635  tsv_str.add_str_int("\t", line_num);
1636  tsv_str.add_str_int("\t", word_num);
1637  AddBoxToTSV(res_it, RIL_BLOCK, &tsv_str);
1638  tsv_str += "\t-1\t\n"; // end of row for block
1639  }
1640  if (res_it->IsAtBeginningOf(RIL_PARA)) {
1641  par_num++, line_num = 0, word_num = 0;
1642  tsv_str.add_str_int("3\t", page_num); // level 3 - paragraph
1643  tsv_str.add_str_int("\t", block_num);
1644  tsv_str.add_str_int("\t", par_num);
1645  tsv_str.add_str_int("\t", line_num);
1646  tsv_str.add_str_int("\t", word_num);
1647  AddBoxToTSV(res_it, RIL_PARA, &tsv_str);
1648  tsv_str += "\t-1\t\n"; // end of row for para
1649  }
1650  if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
1651  line_num++, word_num = 0;
1652  tsv_str.add_str_int("4\t", page_num); // level 4 - line
1653  tsv_str.add_str_int("\t", block_num);
1654  tsv_str.add_str_int("\t", par_num);
1655  tsv_str.add_str_int("\t", line_num);
1656  tsv_str.add_str_int("\t", word_num);
1657  AddBoxToTSV(res_it, RIL_TEXTLINE, &tsv_str);
1658  tsv_str += "\t-1\t\n"; // end of row for line
1659  }
1660 
1661  // Now, process the word...
1662  int left, top, right, bottom;
1663  bool bold, italic, underlined, monospace, serif, smallcaps;
1664  int pointsize, font_id;
1665  const char* font_name;
1666  res_it->BoundingBox(RIL_WORD, &left, &top, &right, &bottom);
1667  font_name =
1668  res_it->WordFontAttributes(&bold, &italic, &underlined, &monospace,
1669  &serif, &smallcaps, &pointsize, &font_id);
1670  word_num++;
1671  tsv_str.add_str_int("5\t", page_num); // level 5 - word
1672  tsv_str.add_str_int("\t", block_num);
1673  tsv_str.add_str_int("\t", par_num);
1674  tsv_str.add_str_int("\t", line_num);
1675  tsv_str.add_str_int("\t", word_num);
1676  tsv_str.add_str_int("\t", left);
1677  tsv_str.add_str_int("\t", top);
1678  tsv_str.add_str_int("\t", right - left);
1679  tsv_str.add_str_int("\t", bottom - top);
1680  tsv_str.add_str_int("\t", res_it->Confidence(RIL_WORD));
1681  tsv_str += "\t";
1682 
1683  // Increment counts if at end of block/paragraph/textline.
1684  if (res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD)) lcnt++;
1685  if (res_it->IsAtFinalElement(RIL_PARA, RIL_WORD)) pcnt++;
1686  if (res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD)) bcnt++;
1687 
1688  do {
1689  tsv_str += res_it->GetUTF8Text(RIL_SYMBOL);
1690  res_it->Next(RIL_SYMBOL);
1691  } while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
1692  tsv_str += "\n"; // end of row
1693  wcnt++;
1694  }
1695 
1696  char* ret = new char[tsv_str.length() + 1];
1697  strcpy(ret, tsv_str.string());
1698  delete res_it;
1699  return ret;
1700 }
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
ResultIterator * GetIterator()
Definition: baseapi.cpp:1254
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
Definition: strngs.h:44
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetUnichar()

const char * tesseract::TessBaseAPI::GetUnichar ( int  unichar_id)

This method returns the string form of the specified unichar.

Definition at line 2818 of file baseapi.cpp.

2818  {
2819  return tesseract_->unicharset.id_to_unichar(unichar_id);
2820 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
UNICHARSET unicharset
Definition: ccutil.h:70
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:266

◆ GetUNLVText()

char * tesseract::TessBaseAPI::GetUNLVText ( )

The recognized text is returned as a char* which is coded as UNLV format Latin-1 with specific reject and suspect codes and must be freed with the delete [] operator.

Definition at line 1786 of file baseapi.cpp.

1786  {
1787  if (tesseract_ == NULL ||
1788  (!recognition_done_ && Recognize(NULL) < 0))
1789  return NULL;
1790  bool tilde_crunch_written = false;
1791  bool last_char_was_newline = true;
1792  bool last_char_was_tilde = false;
1793 
1794  int total_length = TextLength(NULL);
1795  PAGE_RES_IT page_res_it(page_res_);
1796  char* result = new char[total_length];
1797  char* ptr = result;
1798  for (page_res_it.restart_page(); page_res_it.word () != NULL;
1799  page_res_it.forward()) {
1800  WERD_RES *word = page_res_it.word();
1801  // Process the current word.
1802  if (word->unlv_crunch_mode != CR_NONE) {
1803  if (word->unlv_crunch_mode != CR_DELETE &&
1804  (!tilde_crunch_written ||
1805  (word->unlv_crunch_mode == CR_KEEP_SPACE &&
1806  word->word->space() > 0 &&
1807  !word->word->flag(W_FUZZY_NON) &&
1808  !word->word->flag(W_FUZZY_SP)))) {
1809  if (!word->word->flag(W_BOL) &&
1810  word->word->space() > 0 &&
1811  !word->word->flag(W_FUZZY_NON) &&
1812  !word->word->flag(W_FUZZY_SP)) {
1813  /* Write a space to separate from preceding good text */
1814  *ptr++ = ' ';
1815  last_char_was_tilde = false;
1816  }
1817  if (!last_char_was_tilde) {
1818  // Write a reject char.
1819  last_char_was_tilde = true;
1820  *ptr++ = kUNLVReject;
1821  tilde_crunch_written = true;
1822  last_char_was_newline = false;
1823  }
1824  }
1825  } else {
1826  // NORMAL PROCESSING of non tilde crunched words.
1827  tilde_crunch_written = false;
1829  const char* wordstr = word->best_choice->unichar_string().string();
1830  const STRING& lengths = word->best_choice->unichar_lengths();
1831  int length = lengths.length();
1832  int i = 0;
1833  int offset = 0;
1834 
1835  if (last_char_was_tilde &&
1836  word->word->space() == 0 && wordstr[offset] == ' ') {
1837  // Prevent adjacent tilde across words - we know that adjacent tildes
1838  // within words have been removed.
1839  // Skip the first character.
1840  offset = lengths[i++];
1841  }
1842  if (i < length && wordstr[offset] != 0) {
1843  if (!last_char_was_newline)
1844  *ptr++ = ' ';
1845  else
1846  last_char_was_newline = false;
1847  for (; i < length; offset += lengths[i++]) {
1848  if (wordstr[offset] == ' ' ||
1849  wordstr[offset] == kTesseractReject) {
1850  *ptr++ = kUNLVReject;
1851  last_char_was_tilde = true;
1852  } else {
1853  if (word->reject_map[i].rejected())
1854  *ptr++ = kUNLVSuspect;
1855  UNICHAR ch(wordstr + offset, lengths[i]);
1856  int uni_ch = ch.first_uni();
1857  for (int j = 0; kUniChs[j] != 0; ++j) {
1858  if (kUniChs[j] == uni_ch) {
1859  uni_ch = kLatinChs[j];
1860  break;
1861  }
1862  }
1863  if (uni_ch <= 0xff) {
1864  *ptr++ = static_cast<char>(uni_ch);
1865  last_char_was_tilde = false;
1866  } else {
1867  *ptr++ = kUNLVReject;
1868  last_char_was_tilde = true;
1869  }
1870  }
1871  }
1872  }
1873  }
1874  if (word->word->flag(W_EOL) && !last_char_was_newline) {
1875  /* Add a new line output */
1876  *ptr++ = '\n';
1877  tilde_crunch_written = false;
1878  last_char_was_newline = true;
1879  last_char_was_tilde = false;
1880  }
1881  }
1882  *ptr++ = '\n';
1883  *ptr = '\0';
1884  return result;
1885 }
const char kUNLVSuspect
Definition: baseapi.cpp:90
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:294
Definition: werd.h:36
const STRING & unichar_string() const
Definition: ratngs.h:525
inT32 length() const
Definition: strngs.cpp:196
const char kTesseractReject
Definition: baseapi.cpp:86
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
WERD_CHOICE * best_choice
Definition: pageres.h:219
const char * string() const
Definition: strngs.cpp:201
uinT8 space()
Definition: werd.h:104
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
Definition: werd.h:35
const int kLatinChs[]
Definition: baseapi.cpp:1777
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:877
Definition: strngs.h:44
const char kUNLVReject
Definition: baseapi.cpp:88
TESS_LOCAL int TextLength(int *blob_count)
Definition: baseapi.cpp:2351
const STRING & unichar_lengths() const
Definition: ratngs.h:532
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
WERD * word
Definition: pageres.h:175
void set_unlv_suspects(WERD_RES *word)
Definition: output.cpp:305
REJMAP reject_map
Definition: pageres.h:271
const int kUniChs[]
Definition: baseapi.cpp:1773

◆ GetUTF8Text()

char * tesseract::TessBaseAPI::GetUTF8Text ( )

The recognized text is returned as a char* which is coded as UTF8 and must be freed with the delete [] operator.

Make a text string from the internal data structures.

Definition at line 1281 of file baseapi.cpp.

1281  {
1282  if (tesseract_ == NULL ||
1283  (!recognition_done_ && Recognize(NULL) < 0))
1284  return NULL;
1285  STRING text("");
1286  ResultIterator *it = GetIterator();
1287  do {
1288  if (it->Empty(RIL_PARA)) continue;
1289  char *para_text = it->GetUTF8Text(RIL_PARA);
1290  text += para_text;
1291  delete []para_text;
1292  } while (it->Next(RIL_PARA));
1293  char* result = new char[text.length() + 1];
1294  strncpy(result, text.string(), text.length() + 1);
1295  delete it;
1296  return result;
1297 }
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
ResultIterator * GetIterator()
Definition: baseapi.cpp:1254
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:877
Definition: strngs.h:44
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ GetWords()

Boxa * tesseract::TessBaseAPI::GetWords ( Pixa **  pixa)

Get the words as a leptonica-style Boxa, Pixa pair, in reading order. Can be called before or after Recognize.

Definition at line 617 of file baseapi.cpp.

617  {
618  return GetComponentImages(RIL_WORD, true, pixa, NULL);
619 }
Boxa * GetComponentImages(const PageIteratorLevel level, const bool text_only, const bool raw_image, const int raw_padding, Pixa **pixa, int **blockids, int **paraids)
Definition: baseapi.cpp:639

◆ InitTruthCallback()

void tesseract::TessBaseAPI::InitTruthCallback ( TruthCallback cb)
inline

Definition at line 763 of file baseapi.h.

763 { truth_cb_ = cb; }
TruthCallback * truth_cb_
Definition: baseapi.h:878

◆ IsValidCharacter()

bool tesseract::TessBaseAPI::IsValidCharacter ( const char *  utf8_character)

Definition at line 2127 of file baseapi.cpp.

2127  {
2128  return tesseract_->unicharset.contains_unichar(utf8_character);
2129 }
bool TESS_API contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:644
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
UNICHARSET unicharset
Definition: ccutil.h:70

◆ IsValidWord()

int tesseract::TessBaseAPI::IsValidWord ( const char *  word)

Check whether a word is valid according to Tesseract's language model

Returns
0 if the word is invalid, non-zero if valid.
Warning
temporary! This function will be removed from here and placed in a separate API at some future time.

Check whether a word is valid according to Tesseract's language model returns 0 if the word is invalid, non-zero if valid

Definition at line 2123 of file baseapi.cpp.

2123  {
2124  return tesseract_->getDict().valid_word(word);
2125 }
Dict & getDict()
Definition: classify.h:65
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:730
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ MakeTBLOB()

TBLOB * tesseract::TessBaseAPI::MakeTBLOB ( Pix *  pix)
static

Returns a TBLOB corresponding to the entire input image.

Creates a TBLOB* from the whole pix.

Definition at line 2492 of file baseapi.cpp.

2492  {
2493  int width = pixGetWidth(pix);
2494  int height = pixGetHeight(pix);
2495  BLOCK block("a character", TRUE, 0, 0, 0, 0, width, height);
2496 
2497  // Create C_BLOBs from the page
2498  extract_edges(pix, &block);
2499 
2500  // Merge all C_BLOBs
2501  C_BLOB_LIST *list = block.blob_list();
2502  C_BLOB_IT c_blob_it(list);
2503  if (c_blob_it.empty())
2504  return NULL;
2505  // Move all the outlines to the first blob.
2506  C_OUTLINE_IT ol_it(c_blob_it.data()->out_list());
2507  for (c_blob_it.forward();
2508  !c_blob_it.at_first();
2509  c_blob_it.forward()) {
2510  C_BLOB *c_blob = c_blob_it.data();
2511  ol_it.add_list_after(c_blob->out_list());
2512  }
2513  // Convert the first blob to the output TBLOB.
2514  return TBLOB::PolygonalCopy(false, c_blob_it.data());
2515 }
#define TRUE
Definition: capi.h:45
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:64
void extract_edges(Pix *pix, BLOCK *block)
Definition: edgblob.cpp:334
Definition: ocrblock.h:30
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:344

◆ MakeTessOCRRow()

ROW * tesseract::TessBaseAPI::MakeTessOCRRow ( float  baseline,
float  xheight,
float  descender,
float  ascender 
)
static

Returns a ROW object created from the input row specification.

Definition at line 2475 of file baseapi.cpp.

2478  {
2479  inT32 xstarts[] = {-32000};
2480  double quad_coeffs[] = {0, 0, baseline};
2481  return new ROW(1,
2482  xstarts,
2483  quad_coeffs,
2484  xheight,
2485  ascender - (baseline + xheight),
2486  descender - baseline,
2487  0,
2488  0);
2489 }
int inT32
Definition: host.h:35
Definition: ocrrow.h:32

◆ MeanTextConf()

int tesseract::TessBaseAPI::MeanTextConf ( )

Returns the (average) confidence value between 0 and 100.

Returns the average word confidence for Tesseract page result.

Definition at line 1956 of file baseapi.cpp.

1956  {
1957  int* conf = AllWordConfidences();
1958  if (!conf) return 0;
1959  int sum = 0;
1960  int *pt = conf;
1961  while (*pt >= 0) sum += *pt++;
1962  if (pt != conf) sum /= pt - conf;
1963  delete [] conf;
1964  return sum;
1965 }

◆ NormalizeTBLOB()

void tesseract::TessBaseAPI::NormalizeTBLOB ( TBLOB tblob,
ROW row,
bool  numeric_mode 
)
static

This method baseline normalizes a TBLOB in-place. The input row is used for normalization. The denorm is an optional parameter in which the normalization-antidote is returned.

Definition at line 2522 of file baseapi.cpp.

2522  {
2523  TBOX box = tblob->bounding_box();
2524  float x_center = (box.left() + box.right()) / 2.0f;
2525  float baseline = row->base_line(x_center);
2526  float scale = kBlnXHeight / row->x_height();
2527  tblob->Normalize(NULL, NULL, NULL, x_center, baseline, scale, scale,
2528  0.0f, static_cast<float>(kBlnBaselineOffset), false, NULL);
2529 }
const int kBlnBaselineOffset
Definition: normalis.h:29
float base_line(float xpos) const
Definition: ocrrow.h:56
void Normalize(const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift, bool inverse, Pix *pix)
Definition: blobs.cpp:413
TBOX bounding_box() const
Definition: blobs.cpp:482
inT16 left() const
Definition: rect.h:68
const int kBlnXHeight
Definition: normalis.h:28
Definition: rect.h:30
inT16 right() const
Definition: rect.h:75
float x_height() const
Definition: ocrrow.h:61

◆ NumDawgs()

int tesseract::TessBaseAPI::NumDawgs ( ) const

Return the number of dawgs loaded into tesseract_ object.

Definition at line 2829 of file baseapi.cpp.

2829  {
2830  return tesseract_ == NULL ? 0 : tesseract_->getDict().NumDawgs();
2831 }
int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
Definition: dict.h:410
Dict & getDict()
Definition: classify.h:65
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ oem()

OcrEngineMode tesseract::TessBaseAPI::oem ( ) const
inline

Definition at line 761 of file baseapi.h.

761 { return last_oem_requested_; }
OcrEngineMode last_oem_requested_
Last ocr language mode requested.
Definition: baseapi.h:876

◆ ProcessPage()

bool tesseract::TessBaseAPI::ProcessPage ( Pix *  pix,
int  page_index,
const char *  filename,
const char *  retry_config,
int  timeout_millisec,
TessResultRenderer renderer 
)

Turn a single image into symbolic text.

The pix is the image processed. filename and page_index are metadata used by side-effect processes, such as reading a box file or formatting as hOCR.

See ProcessPages for desciptions of other parameters.

Definition at line 1172 of file baseapi.cpp.

1174  {
1175  PERF_COUNT_START("ProcessPage")
1177  SetImage(pix);
1178  bool failed = false;
1179 
1180  if (tesseract_->tessedit_pageseg_mode == PSM_AUTO_ONLY) {
1181  // Disabled character recognition
1182  PageIterator* it = AnalyseLayout();
1183 
1184  if (it == NULL) {
1185  failed = true;
1186  } else {
1187  delete it;
1188  }
1190  failed = FindLines() != 0;
1191  } else if (timeout_millisec > 0) {
1192  // Running with a timeout.
1193  ETEXT_DESC monitor;
1194  monitor.cancel = NULL;
1195  monitor.cancel_this = NULL;
1196  monitor.set_deadline_msecs(timeout_millisec);
1197 
1198  // Now run the main recognition.
1199  failed = Recognize(&monitor) < 0;
1200  } else {
1201  // Normal layout and character recognition with no timeout.
1202  failed = Recognize(NULL) < 0;
1203  }
1204 
1206 #ifndef ANDROID_BUILD
1207  Pix* page_pix = GetThresholdedImage();
1208  pixWrite("tessinput.tif", page_pix, IFF_TIFF_G4);
1209 #endif // ANDROID_BUILD
1210  }
1211 
1212  if (failed && retry_config != NULL && retry_config[0] != '\0') {
1213  // Save current config variables before switching modes.
1214  FILE* fp = fopen(kOldVarsFile, "wb");
1215  PrintVariables(fp);
1216  fclose(fp);
1217  // Switch to alternate mode for retry.
1218  ReadConfigFile(retry_config);
1219  SetImage(pix);
1220  Recognize(NULL);
1221  // Restore saved config variables.
1223  }
1224 
1225  if (renderer && !failed) {
1226  failed = !renderer->AddImage(this);
1227  }
1228 
1230  return !failed;
1231 }
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:829
CANCEL_FUNC cancel
for errcode use
Definition: ocrclass.h:125
void ReadConfigFile(const char *filename)
Definition: baseapi.cpp:444
Orientation and script detection only.
Definition: publictypes.h:152
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:521
Automatic page segmentation, but no OSD, or OCR.
Definition: publictypes.h:155
void * cancel_this
called whenever progress increases
Definition: ocrclass.h:127
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2260
#define PERF_COUNT_START(FUNCT_NAME)
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:809
const char * kOldVarsFile
Definition: baseapi.cpp:99
void SetInputName(const char *name)
Definition: baseapi.cpp:199
Pix * GetThresholdedImage()
Definition: baseapi.cpp:569
#define PERF_COUNT_END
void PrintVariables(FILE *fp) const
Definition: baseapi.cpp:262
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
void set_deadline_msecs(inT32 deadline_msecs)
Definition: ocrclass.h:146

◆ ProcessPages()

bool tesseract::TessBaseAPI::ProcessPages ( const char *  filename,
const char *  retry_config,
int  timeout_millisec,
TessResultRenderer renderer 
)

Turns images into symbolic text.

filename can point to a single image, a multi-page TIFF, or a plain text list of image filenames.

retry_config is useful for debugging. If not NULL, you can fall back to an alternate configuration if a page fails for some reason.

timeout_millisec terminates processing if any single page takes too long. Set to 0 for unlimited time.

renderer is responible for creating the output. For example, use the TessTextRenderer if you want plaintext output, or the TessPDFRender to produce searchable PDF.

If tessedit_page_number is non-negative, will only process that single page. Works for multi-page tiff file, or filelist.

Returns true if successful, false on error.

Definition at line 1054 of file baseapi.cpp.

1056  {
1057  bool result =
1058  ProcessPagesInternal(filename, retry_config, timeout_millisec, renderer);
1059  if (result) {
1062  tprintf("Write of TR file failed: %s\n", output_file_->string());
1063  return false;
1064  }
1065  }
1066  return result;
1067 }
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:873
bool ProcessPagesInternal(const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
Definition: baseapi.cpp:1080
const char * string() const
Definition: strngs.cpp:201
#define tprintf(...)
Definition: tprintf.h:31
bool WriteTRFile(const STRING &filename)
Definition: blobclass.cpp:97
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ ProcessPagesInternal()

bool tesseract::TessBaseAPI::ProcessPagesInternal ( const char *  filename,
const char *  retry_config,
int  timeout_millisec,
TessResultRenderer renderer 
)

Definition at line 1080 of file baseapi.cpp.

1083  {
1084  PERF_COUNT_START("ProcessPages")
1085  bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
1086  if (stdInput) {
1087 #ifdef WIN32
1088  if (_setmode(_fileno(stdin), _O_BINARY) == -1)
1089  tprintf("ERROR: cin to binary: %s", strerror(errno));
1090 #endif // WIN32
1091  }
1092 
1093  if (stream_filelist) {
1094  return ProcessPagesFileList(stdin, NULL, retry_config,
1095  timeout_millisec, renderer,
1097  }
1098 
1099  // At this point we are officially in autodection territory.
1100  // That means any data in stdin must be buffered, to make it
1101  // seekable.
1102  std::string buf;
1103  const l_uint8 *data = NULL;
1104  if (stdInput) {
1105  buf.assign((std::istreambuf_iterator<char>(std::cin)),
1106  (std::istreambuf_iterator<char>()));
1107  data = reinterpret_cast<const l_uint8 *>(buf.data());
1108  }
1109 
1110  // Here is our autodetection
1111  int format;
1112  int r = (stdInput) ?
1113  findFileFormatBuffer(data, &format) :
1114  findFileFormat(filename, &format);
1115 
1116  // Maybe we have a filelist
1117  if (r != 0 || format == IFF_UNKNOWN) {
1118  STRING s;
1119  if (stdInput) {
1120  s = buf.c_str();
1121  } else {
1122  std::ifstream t(filename);
1123  std::string u((std::istreambuf_iterator<char>(t)),
1124  std::istreambuf_iterator<char>());
1125  s = u.c_str();
1126  }
1127  return ProcessPagesFileList(NULL, &s, retry_config,
1128  timeout_millisec, renderer,
1130  }
1131 
1132  // Maybe we have a TIFF which is potentially multipage
1133  bool tiff = (format == IFF_TIFF || format == IFF_TIFF_PACKBITS ||
1134  format == IFF_TIFF_RLE || format == IFF_TIFF_G3 ||
1135  format == IFF_TIFF_G4 || format == IFF_TIFF_LZW ||
1136  format == IFF_TIFF_ZIP);
1137 
1138  // Fail early if we can, before producing any output
1139  Pix *pix = NULL;
1140  if (!tiff) {
1141  pix = (stdInput) ? pixReadMem(data, buf.size()) : pixRead(filename);
1142  if (pix == NULL) {
1143  return false;
1144  }
1145  }
1146 
1147  // Begin the output
1148  if (renderer && !renderer->BeginDocument(unknown_title_)) {
1149  pixDestroy(&pix);
1150  return false;
1151  }
1152 
1153  // Produce output
1154  r = (tiff) ?
1155  ProcessPagesMultipageTiff(data, buf.size(), filename, retry_config,
1156  timeout_millisec, renderer,
1158  ProcessPage(pix, 0, filename, retry_config,
1159  timeout_millisec, renderer);
1160 
1161  // Clean up memory as needed
1162  pixDestroy(&pix);
1163 
1164  // End the output
1165  if (!r || (renderer && !renderer->EndDocument())) {
1166  return false;
1167  }
1169  return true;
1170 }
bool ProcessPage(Pix *pix, int page_index, const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
Definition: baseapi.cpp:1172
const char * c_str() const
Definition: strngs.cpp:212
#define PERF_COUNT_START(FUNCT_NAME)
bool stream_filelist
Definition: baseapi.cpp:79
#define tprintf(...)
Definition: tprintf.h:31
Definition: strngs.h:44
#define PERF_COUNT_END
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ Recognize()

int tesseract::TessBaseAPI::Recognize ( ETEXT_DESC monitor)

Recognize the image from SetAndThresholdImage, generating Tesseract internal structures. Returns 0 on success. Optional. The Get*Text functions below will call Recognize if needed. After Recognize, the output is kept internally until the next SetImage.

Recognize the tesseract global image and return the result as Tesseract internal structures.

Definition at line 829 of file baseapi.cpp.

829  {
830  if (tesseract_ == NULL)
831  return -1;
832  if (FindLines() != 0)
833  return -1;
834  delete page_res_;
835  if (block_list_->empty()) {
836  page_res_ = new PAGE_RES(false, block_list_,
838  return 0; // Empty page.
839  }
840 
842  recognition_done_ = true;
847  } else {
848  // TODO(rays) LSTM here.
849  page_res_ = new PAGE_RES(false,
851  }
852  if (page_res_ == NULL) {
853  return -1;
854  }
857  return 0;
858  }
859 
860  if (truth_cb_ != NULL) {
861  tesseract_->wordrec_run_blamer.set_value(true);
862  PageIterator *page_it = new PageIterator(
867  image_height_, page_it, this->tesseract()->pix_grey());
868  delete page_it;
869  }
870 
871  int result = 0;
873  #ifndef GRAPHICS_DISABLED
875  #endif // GRAPHICS_DISABLED
876  // The page_res is invalid after an interactive session, so cleanup
877  // in a way that lets us continue to the next page without crashing.
878  delete page_res_;
879  page_res_ = NULL;
880  return -1;
882  STRING fontname;
883  ExtractFontName(*output_file_, &fontname);
885  } else if (tesseract_->tessedit_ambigs_training) {
886  FILE *training_output_file = tesseract_->init_recog_training(*input_file_);
887  // OCR the page segmented into words by tesseract.
889  *input_file_, page_res_, monitor, training_output_file);
890  fclose(training_output_file);
891  } else {
892  // Now run the main recognition.
893  bool wait_for_text = true;
894  GetBoolVariable("paragraph_text_based", &wait_for_text);
895  if (!wait_for_text) DetectParagraphs(false);
896  if (tesseract_->recog_all_words(page_res_, monitor, NULL, NULL, 0)) {
897  if (wait_for_text) DetectParagraphs(true);
898  } else {
899  result = -1;
900  }
901  }
902  return result;
903 }
bool wordrec_run_blamer
Definition: wordrec.h:168
bool tessedit_resegment_from_line_boxes
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:873
void pgeditor_main(int width, int height, PAGE_RES *page_res)
Definition: pgedit.cpp:337
const UNICHARSET & getUnicharset() const
Definition: dict.h:97
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
int GetScaledYResolution() const
Definition: thresholder.h:93
bool GetBoolVariable(const char *name, bool *value) const
Definition: baseapi.cpp:234
virtual void Run(A1, A2, A3, A4)=0
PAGE_RES * ApplyBoxes(const STRING &fname, bool find_segmentation, BLOCK_LIST *block_list)
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2260
void CorrectClassifyWords(PAGE_RES *page_res)
void ApplyBoxTraining(const STRING &fontname, PAGE_RES *page_res)
TESS_LOCAL void DetectParagraphs(bool after_text_recognition)
Definition: baseapi.cpp:2604
Dict & getDict()
Definition: classify.h:65
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:877
void ExtractFontName(const STRING &filename, STRING *fontname)
Definition: blobclass.cpp:46
TruthCallback * truth_cb_
Definition: baseapi.h:878
FILE * init_recog_training(const STRING &fname)
Definition: strngs.h:44
bool recog_all_words(PAGE_RES *page_res, ETEXT_DESC *monitor, const TBOX *target_word_box, const char *word_config, int dopasses)
Definition: control.cpp:293
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:416
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract() const
Definition: baseapi.h:759
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
Pix * pix_grey() const
STRING * input_file_
Name used by training code.
Definition: baseapi.h:872
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870
void recog_training_segmented(const STRING &fname, PAGE_RES *page_res, volatile ETEXT_DESC *monitor, FILE *output_file)

◆ RecognizeForChopTest()

int tesseract::TessBaseAPI::RecognizeForChopTest ( ETEXT_DESC monitor)

Methods to retrieve information after SetAndThresholdImage(), Recognize() or TesseractRect(). (Recognize is called implicitly if needed.)Variant on Recognize used for testing chopper.

Tests the chopper by exhaustively running chop_one_blob.

Definition at line 906 of file baseapi.cpp.

906  {
907  if (tesseract_ == NULL)
908  return -1;
909  if (thresholder_ == NULL || thresholder_->IsEmpty()) {
910  tprintf("Please call SetImage before attempting recognition.");
911  return -1;
912  }
913  if (page_res_ != NULL)
914  ClearResults();
915  if (FindLines() != 0)
916  return -1;
917  // Additional conditions under which chopper test cannot be run
918  if (tesseract_->interactive_display_mode) return -1;
919 
920  recognition_done_ = true;
921 
922  page_res_ = new PAGE_RES(false, block_list_,
924 
925  PAGE_RES_IT page_res_it(page_res_);
926 
927  while (page_res_it.word() != NULL) {
928  WERD_RES *word_res = page_res_it.word();
929  GenericVector<TBOX> boxes;
930  tesseract_->MaximallyChopWord(boxes, page_res_it.block()->block,
931  page_res_it.row()->row, word_res);
932  page_res_it.forward();
933  }
934  return 0;
935 }
void MaximallyChopWord(const GenericVector< TBOX > &boxes, BLOCK *block, ROW *row, WERD_RES *word_res)
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:871
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2260
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:877
#define tprintf(...)
Definition: tprintf.h:31
bool IsEmpty() const
Return true if no image has been set.
Definition: thresholder.cpp:50
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:416
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
WERD * word
Definition: pageres.h:175
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:870

◆ RunAdaptiveClassifier()

void tesseract::TessBaseAPI::RunAdaptiveClassifier ( TBLOB blob,
int  num_max_matches,
int *  unichar_ids,
float *  ratings,
int *  num_matches_returned 
)

Method to run adaptive classifier on a blob. It returns at max num_max_matches results.

Method to run adaptive classifier on a blob.

Definition at line 2795 of file baseapi.cpp.

2799  {
2800  BLOB_CHOICE_LIST* choices = new BLOB_CHOICE_LIST;
2801  tesseract_->AdaptiveClassifier(blob, choices);
2802  BLOB_CHOICE_IT choices_it(choices);
2803  int& index = *num_matches_returned;
2804  index = 0;
2805  for (choices_it.mark_cycle_pt();
2806  !choices_it.cycled_list() && index < num_max_matches;
2807  choices_it.forward()) {
2808  BLOB_CHOICE* choice = choices_it.data();
2809  unichar_ids[index] = choice->unichar_id();
2810  ratings[index] = choice->rating();
2811  ++index;
2812  }
2813  *num_matches_returned = index;
2814  delete choices;
2815 }
UNICHAR_ID unichar_id() const
Definition: ratngs.h:76
float rating() const
Definition: ratngs.h:79
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:185
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ set_min_orientation_margin()

void tesseract::TessBaseAPI::set_min_orientation_margin ( double  margin)

Definition at line 2392 of file baseapi.cpp.

2392  {
2393  tesseract_->min_orientation_margin.set_value(margin);
2394 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ SetDictFunc()

void tesseract::TessBaseAPI::SetDictFunc ( DictFunc  f)

Sets Dict::letter_is_okay_ function to point to the given function.

Definition at line 2169 of file baseapi.cpp.

2169  {
2170  if (tesseract_ != NULL) {
2172  }
2173 }
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.h:354
Dict & getDict()
Definition: classify.h:65
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865

◆ SetFillLatticeFunc()

void tesseract::TessBaseAPI::SetFillLatticeFunc ( FillLatticeFunc  f)

Sets Wordrec::fill_lattice_ function to point to the given function.

Definition at line 2195 of file baseapi.cpp.

2195  {
2196  if (tesseract_ != NULL) tesseract_->fill_lattice_ = f;
2197 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
void(Wordrec::* fill_lattice_)(const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
Definition: wordrec.h:420

◆ SetImage() [1/2]

void tesseract::TessBaseAPI::SetImage ( const unsigned char *  imagedata,
int  width,
int  height,
int  bytes_per_pixel,
int  bytes_per_line 
)

Provide an image for Tesseract to recognize. Format is as TesseractRect above. Copies the image buffer and converts to Pix. SetImage clears all recognition results, and sets the rectangle to the full image, so it may be followed immediately by a GetUTF8Text, and it will automatically perform recognition.

Definition at line 521 of file baseapi.cpp.

523  {
524  if (InternalSetImage()) {
525  thresholder_->SetImage(imagedata, width, height,
526  bytes_per_pixel, bytes_per_line);
528  }
529 }
void SetInputImage(Pix *pix)
Definition: baseapi.cpp:938
TESS_LOCAL bool InternalSetImage()
Definition: baseapi.cpp:2200
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: thresholder.cpp:62

◆ SetImage() [2/2]

void tesseract::TessBaseAPI::SetImage ( Pix *  pix)

Provide an image for Tesseract to recognize. As with SetImage above, Tesseract takes its own copy of the image, so it need not persist until after Recognize. Pix vs raw, which to use? Use Pix where possible. Tesseract uses Pix as its internal representation and it is therefore more efficient to provide a Pix directly.

Definition at line 546 of file baseapi.cpp.

546  {
547  if (InternalSetImage()) {
548  thresholder_->SetImage(pix);
550  }
551 }
void SetInputImage(Pix *pix)
Definition: baseapi.cpp:938
TESS_LOCAL bool InternalSetImage()
Definition: baseapi.cpp:2200
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: thresholder.cpp:62

◆ SetProbabilityInContextFunc()

void tesseract::TessBaseAPI::SetProbabilityInContextFunc ( ProbabilityInContextFunc  f)

Sets Dict::probability_in_context_ function to point to the given function.

Sets Dict::probability_in_context_ function to point to the given function.

Parameters
fA single function that returns the probability of the current "character" (in general a utf-8 string), given the context of a previous utf-8 string.

Definition at line 2183 of file baseapi.cpp.

2183  {
2184  if (tesseract_ != NULL) {
2186  // Set it for the sublangs too.
2187  int num_subs = tesseract_->num_sub_langs();
2188  for (int i = 0; i < num_subs; ++i) {
2190  }
2191  }
2192 }
double(Dict::* probability_in_context_)(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
Probability in context function used by the ngram permuter.
Definition: dict.h:364
Dict & getDict()
Definition: classify.h:65
Tesseract * get_sub_lang(int index) const
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865
int num_sub_langs() const

◆ SetRectangle()

void tesseract::TessBaseAPI::SetRectangle ( int  left,
int  top,
int  width,
int  height 
)

Restrict recognition to a sub-rectangle of the image. Call after SetImage. Each SetRectangle clears the recogntion results so multiple rectangles can be recognized with the same image.

Definition at line 558 of file baseapi.cpp.

558  {
559  if (thresholder_ == NULL)
560  return;
561  thresholder_->SetRectangle(left, top, width, height);
562  ClearResults();
563 }
void SetRectangle(int left, int top, int width, int height)
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868

◆ SetSourceResolution()

void tesseract::TessBaseAPI::SetSourceResolution ( int  ppi)

Set the resolution of the source image in pixels per inch so font size information can be calculated in results. Call this after SetImage().

Definition at line 531 of file baseapi.cpp.

531  {
532  if (thresholder_)
534  else
535  tprintf("Please call SetImage before SetSourceResolution.\n");
536 }
void SetSourceYResolution(int ppi)
Definition: thresholder.h:86
#define tprintf(...)
Definition: tprintf.h:31
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868

◆ SetThresholder()

void tesseract::TessBaseAPI::SetThresholder ( ImageThresholder thresholder)
inline

In extreme cases only, usually with a subclass of Thresholder, it is possible to provide a different Thresholder. The Thresholder may be preloaded with an image, settings etc, or they may be set after. Note that Tesseract takes ownership of the Thresholder and will delete it when it it is replaced or the API is destructed.

Definition at line 375 of file baseapi.h.

375  {
376  delete thresholder_;
377  thresholder_ = thresholder;
378  ClearResults();
379  }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:868

◆ tesseract()

Tesseract* tesseract::TessBaseAPI::tesseract ( ) const
inline

Definition at line 759 of file baseapi.h.

759 { return tesseract_; }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:865