tesseract  4.0.0-beta.1-59-g2cc4
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
 
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)
 
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 1972 of file baseapi.cpp.

1972  {
1973  int debug = 0;
1974  GetIntVariable("applybox_debug", &debug);
1975  bool success = true;
1976  PageSegMode current_psm = GetPageSegMode();
1978  SetVariable("classify_enable_learning", "0");
1979  const std::unique_ptr<const char[]> text(GetUTF8Text());
1980  if (debug) {
1981  tprintf("Trying to adapt \"%s\" to \"%s\"\n", text.get(), wordstr);
1982  }
1983  if (text != NULL) {
1984  PAGE_RES_IT it(page_res_);
1985  WERD_RES* word_res = it.word();
1986  if (word_res != NULL) {
1987  word_res->word->set_text(wordstr);
1988  } else {
1989  success = false;
1990  }
1991  // Check to see if text matches wordstr.
1992  int w = 0;
1993  int t = 0;
1994  for (t = 0; text[t] != '\0'; ++t) {
1995  if (text[t] == '\n' || text[t] == ' ')
1996  continue;
1997  while (wordstr[w] == ' ') ++w;
1998  if (text[t] != wordstr[w])
1999  break;
2000  ++w;
2001  }
2002  if (text[t] != '\0' || wordstr[w] != '\0') {
2003  // No match.
2004  delete page_res_;
2005  GenericVector<TBOX> boxes;
2009  PAGE_RES_IT pr_it(page_res_);
2010  if (pr_it.word() == NULL)
2011  success = false;
2012  else
2013  word_res = pr_it.word();
2014  } else {
2015  word_res->BestChoiceToCorrectText();
2016  }
2017  if (success) {
2018  tesseract_->EnableLearning = true;
2019  tesseract_->LearnWord(NULL, word_res);
2020  }
2021  } else {
2022  success = false;
2023  }
2024  SetPageSegMode(current_psm);
2025  return success;
2026 }
PAGE_RES * SetupApplyBoxes(const GenericVector< TBOX > &boxes, BLOCK_LIST *block_list)
Definition: applybox.cpp:217
void ReSegmentByClassification(PAGE_RES *page_res)
Definition: applybox.cpp:509
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
void LearnWord(const char *fontname, WERD_RES *word)
Definition: adaptmatch.cpp:244
void SetPageSegMode(PageSegMode mode)
Definition: baseapi.cpp:492
PageSegMode GetPageSegMode() const
Definition: baseapi.cpp:499
void BestChoiceToCorrectText()
Definition: pageres.cpp:918
WERD * word
Definition: pageres.h:175
#define tprintf(...)
Definition: tprintf.h:31
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
CMD_EVENTS mode
Definition: pgedit.cpp:116
void set_text(const char *new_text)
Definition: werd.h:126
bool GetIntVariable(const char *name, int *value) const
Definition: baseapi.cpp:278
void TidyUp(PAGE_RES *page_res)
Definition: applybox.cpp:706
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:266

◆ 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 1938 of file baseapi.cpp.

1938  {
1939  if (tesseract_ == NULL ||
1940  (!recognition_done_ && Recognize(NULL) < 0))
1941  return NULL;
1942  int n_word = 0;
1943  PAGE_RES_IT res_it(page_res_);
1944  for (res_it.restart_page(); res_it.word() != NULL; res_it.forward())
1945  n_word++;
1946 
1947  int* conf = new int[n_word+1];
1948  n_word = 0;
1949  for (res_it.restart_page(); res_it.word() != NULL; res_it.forward()) {
1950  WERD_RES *word = res_it.word();
1951  WERD_CHOICE* choice = word->best_choice;
1952  int w_conf = static_cast<int>(100 + 5 * choice->certainty());
1953  // This is the eq for converting Tesseract confidence to 1..100
1954  if (w_conf < 0) w_conf = 0;
1955  if (w_conf > 100) w_conf = 100;
1956  conf[n_word++] = w_conf;
1957  }
1958  conf[n_word] = -1;
1959  return conf;
1960 }
WERD_CHOICE * best_choice
Definition: pageres.h:219
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:798
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:871
WERD * word
Definition: pageres.h:175
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
float certainty() const
Definition: ratngs.h:326

◆ 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 778 of file baseapi.cpp.

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

◆ AnalyseLayout() [2/2]

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

Definition at line 780 of file baseapi.cpp.

780  {
781  if (FindLines() == 0) {
782  if (block_list_->empty())
783  return NULL; // The page was empty.
784  page_res_ = new PAGE_RES(merge_similar_words, block_list_, NULL);
785  DetectParagraphs(false);
786  return new PageIterator(
790  }
791  return NULL;
792 }
int GetScaledYResolution() const
Definition: thresholder.h:93
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2228
TESS_LOCAL void DetectParagraphs(bool after_text_recognition)
Definition: baseapi.cpp:2582

◆ 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 2034 of file baseapi.cpp.

2034  {
2035  if (thresholder_ != NULL)
2036  thresholder_->Clear();
2037  ClearResults();
2038  if (tesseract_ != NULL) SetInputImage(NULL);
2039 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
void SetInputImage(Pix *pix)
Definition: baseapi.cpp:911
virtual void Clear()
Destroy the Pix if there is one, freeing memory.
Definition: thresholder.cpp:45

◆ 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 2082 of file baseapi.cpp.

2082  {
2084 }
void DeleteUnusedDawgs()
Definition: dawg_cache.h:43
static DawgCache * GlobalDawgCache()
Definition: dict.cpp:192

◆ 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 2448 of file baseapi.cpp.

2448  {
2449  delete block_list;
2450 }

◆ 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 1866 of file baseapi.cpp.

1868  {
1869  OSResults osr;
1870 
1871  bool osd = DetectOS(&osr);
1872  if (!osd) {
1873  return false;
1874  }
1875 
1876  int orient_id = osr.best_result.orientation_id;
1877  int script_id = osr.get_best_script(orient_id);
1878  if (orient_conf) *orient_conf = osr.best_result.oconfidence;
1879  if (orient_deg) *orient_deg = orient_id * 90; // convert quadrant to degrees
1880 
1881  if (script_name) {
1882  const char* script = osr.unicharset->get_script_from_script_id(script_id);
1883 
1884  *script_name = script;
1885  }
1886 
1887  if (script_conf) *script_conf = osr.best_result.sconfidence;
1888 
1889  return true;
1890 }
int orientation_id
Definition: osdetect.h:41
UNICHARSET * unicharset
Definition: osdetect.h:78
bool DetectOS(OSResults *)
Definition: baseapi.cpp:2357
float oconfidence
Definition: osdetect.h:44
float sconfidence
Definition: osdetect.h:43
OSBestResult best_result
Definition: osdetect.h:79
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:853
TESS_API int get_best_script(int orientation_id) const
Definition: osdetect.cpp:111

◆ 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 2357 of file baseapi.cpp.

2357  {
2358  if (tesseract_ == NULL)
2359  return false;
2360  ClearResults();
2361  if (tesseract_->pix_binary() == NULL &&
2363  return false;
2364  }
2365  if (input_file_ == NULL)
2366  input_file_ = new STRING(kInputFile);
2368 }
const char * kInputFile
Definition: baseapi.cpp:96
STRING * input_file_
Name used by training code.
Definition: baseapi.h:866
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
Definition: strngs.h:45
virtual TESS_LOCAL bool Threshold(Pix **pix)
Definition: baseapi.cpp:2184
int orientation_and_script_detection(STRING &filename, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:188
Pix * pix_binary() const

◆ 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 2047 of file baseapi.cpp.

2047  {
2048  Clear();
2049  delete thresholder_;
2050  thresholder_ = NULL;
2051  delete page_res_;
2052  page_res_ = NULL;
2053  delete block_list_;
2054  block_list_ = NULL;
2055  if (paragraph_models_ != NULL) {
2057  delete paragraph_models_;
2058  paragraph_models_ = NULL;
2059  }
2060  if (osd_tesseract_ == tesseract_) osd_tesseract_ = nullptr;
2061  delete tesseract_;
2062  tesseract_ = nullptr;
2063  delete osd_tesseract_;
2064  osd_tesseract_ = NULL;
2065  delete equ_detect_;
2066  equ_detect_ = NULL;
2067  delete input_file_;
2068  input_file_ = NULL;
2069  delete output_file_;
2070  output_file_ = NULL;
2071  delete datapath_;
2072  datapath_ = NULL;
2073  delete language_;
2074  language_ = NULL;
2075 }
Tesseract * osd_tesseract_
For orientation & script detection.
Definition: baseapi.h:859
void delete_data_pointers()
GenericVector< ParagraphModel * > * paragraph_models_
Definition: baseapi.h:863
STRING * input_file_
Name used by training code.
Definition: baseapi.h:866
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
EquationDetect * equ_detect_
The equation detector.
Definition: baseapi.h:860
STRING * language_
Last initialized language.
Definition: baseapi.h:869
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:867
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
STRING * datapath_
Current location of tessdata.
Definition: baseapi.h:868

◆ FindLinesCreateBlockList()

BLOCK_LIST * tesseract::TessBaseAPI::FindLinesCreateBlockList ( )

Find lines from the image making the BLOCK_LIST.

Definition at line 2436 of file baseapi.cpp.

2436  {
2437  FindLines();
2438  BLOCK_LIST* result = block_list_;
2439  block_list_ = NULL;
2440  return result;
2441 }
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2228

◆ 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 2748 of file baseapi.cpp.

2749  {
2750  TBOX box(left, bottom, right, top);
2751  BLOCK_IT b_it(blocks);
2752  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
2753  BLOCK* block = b_it.data();
2754  if (!box.major_overlap(block->bounding_box()))
2755  continue;
2756  ROW_IT r_it(block->row_list());
2757  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
2758  ROW* row = r_it.data();
2759  if (!box.major_overlap(row->bounding_box()))
2760  continue;
2761  WERD_IT w_it(row->word_list());
2762  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
2763  WERD* word = w_it.data();
2764  if (box.major_overlap(word->bounding_box()))
2765  return row;
2766  }
2767  }
2768  }
2769  return NULL;
2770 }
WERD_LIST * word_list()
Definition: ocrrow.h:52
Definition: rect.h:30
TBOX bounding_box() const
Definition: ocrrow.h:85
Definition: werd.h:60
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:120
Definition: ocrrow.h:32
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: ocrblock.h:30

◆ 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 2388 of file baseapi.cpp.

2389  {
2390  delete[] *block_orientation;
2391  *block_orientation = NULL;
2392  delete[] *vertical_writing;
2393  *vertical_writing = NULL;
2394  BLOCK_IT block_it(block_list_);
2395 
2396  block_it.move_to_first();
2397  int num_blocks = 0;
2398  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
2399  if (!block_it.data()->poly_block()->IsText()) {
2400  continue;
2401  }
2402  ++num_blocks;
2403  }
2404  if (!num_blocks) {
2405  tprintf("WARNING: Found no blocks\n");
2406  return;
2407  }
2408  *block_orientation = new int[num_blocks];
2409  *vertical_writing = new bool[num_blocks];
2410  block_it.move_to_first();
2411  int i = 0;
2412  for (block_it.mark_cycle_pt(); !block_it.cycled_list();
2413  block_it.forward()) {
2414  if (!block_it.data()->poly_block()->IsText()) {
2415  continue;
2416  }
2417  FCOORD re_rotation = block_it.data()->re_rotation();
2418  float re_theta = re_rotation.angle();
2419  FCOORD classify_rotation = block_it.data()->classify_rotation();
2420  float classify_theta = classify_rotation.angle();
2421  double rot_theta = - (re_theta - classify_theta) * 2.0 / PI;
2422  if (rot_theta < 0) rot_theta += 4;
2423  int num_rotations = static_cast<int>(rot_theta + 0.5);
2424  (*block_orientation)[i] = num_rotations;
2425  // The classify_rotation is non-zero only if the text has vertical
2426  // writing direction.
2427  (*vertical_writing)[i] = classify_rotation.y() != 0.0f;
2428  ++i;
2429  }
2430 }
float angle() const
find angle
Definition: points.h:249
float y() const
Definition: points.h:212
#define PI
Definition: const.h:19
#define tprintf(...)
Definition: tprintf.h:31
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
Definition: points.h:189

◆ 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. 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. Returned string must be freed with the delete [] operator.

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

Definition at line 1702 of file baseapi.cpp.

1702  {
1703  if (tesseract_ == NULL ||
1704  (!recognition_done_ && Recognize(NULL) < 0))
1705  return NULL;
1706  int blob_count;
1707  int utf8_length = TextLength(&blob_count);
1708  int total_length = blob_count * kBytesPerBoxFileLine + utf8_length +
1710  char* result = new char[total_length];
1711  result[0] = '\0';
1712  int output_length = 0;
1713  LTRResultIterator* it = GetLTRIterator();
1714  do {
1715  int left, top, right, bottom;
1716  if (it->BoundingBox(RIL_SYMBOL, &left, &top, &right, &bottom)) {
1717  const std::unique_ptr</*non-const*/ char[]> text(
1718  it->GetUTF8Text(RIL_SYMBOL));
1719  // Tesseract uses space for recognition failure. Fix to a reject
1720  // character, kTesseractReject so we don't create illegal box files.
1721  for (int i = 0; text[i] != '\0'; ++i) {
1722  if (text[i] == ' ')
1723  text[i] = kTesseractReject;
1724  }
1725  snprintf(result + output_length, total_length - output_length,
1726  "%s %d %d %d %d %d\n", text.get(), left, image_height_ - bottom,
1727  right, image_height_ - top, page_number);
1728  output_length += strlen(result + output_length);
1729  // Just in case...
1730  if (output_length + kMaxBytesPerLine > total_length)
1731  break;
1732  }
1733  } while (it->Next(RIL_SYMBOL));
1734  delete it;
1735  return result;
1736 }
const int kMaxBytesPerLine
Definition: baseapi.cpp:1693
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:798
TESS_LOCAL LTRResultIterator * GetLTRIterator()
Definition: baseapi.cpp:1210
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:871
const int kBytesPerBoxFileLine
Definition: baseapi.cpp:1684
TESS_LOCAL int TextLength(int *blob_count)
Definition: baseapi.cpp:2327
const char kTesseractReject
Definition: baseapi.cpp:87

◆ 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 674 of file baseapi.cpp.

678  {
679  PageIterator* page_it = GetIterator();
680  if (page_it == NULL)
681  page_it = AnalyseLayout();
682  if (page_it == NULL)
683  return NULL; // Failed.
684 
685  // Count the components to get a size for the arrays.
686  int component_count = 0;
687  int left, top, right, bottom;
688 
689  TessResultCallback<bool>* get_bbox = NULL;
690  if (raw_image) {
691  // Get bounding box in original raw image with padding.
693  level, raw_padding,
694  &left, &top, &right, &bottom);
695  } else {
696  // Get bounding box from binarized imaged. Note that this could be
697  // differently scaled from the original image.
698  get_bbox = NewPermanentTessCallback(page_it,
700  level, &left, &top, &right, &bottom);
701  }
702  do {
703  if (get_bbox->Run() &&
704  (!text_only || PTIsTextType(page_it->BlockType())))
705  ++component_count;
706  } while (page_it->Next(level));
707 
708  Boxa* boxa = boxaCreate(component_count);
709  if (pixa != NULL)
710  *pixa = pixaCreate(component_count);
711  if (blockids != NULL)
712  *blockids = new int[component_count];
713  if (paraids != NULL)
714  *paraids = new int[component_count];
715 
716  int blockid = 0;
717  int paraid = 0;
718  int component_index = 0;
719  page_it->Begin();
720  do {
721  if (get_bbox->Run() &&
722  (!text_only || PTIsTextType(page_it->BlockType()))) {
723  Box* lbox = boxCreate(left, top, right - left, bottom - top);
724  boxaAddBox(boxa, lbox, L_INSERT);
725  if (pixa != NULL) {
726  Pix* pix = NULL;
727  if (raw_image) {
728  pix = page_it->GetImage(level, raw_padding, GetInputImage(), &left,
729  &top);
730  } else {
731  pix = page_it->GetBinaryImage(level);
732  }
733  pixaAddPix(*pixa, pix, L_INSERT);
734  pixaAddBox(*pixa, lbox, L_CLONE);
735  }
736  if (paraids != NULL) {
737  (*paraids)[component_index] = paraid;
738  if (page_it->IsAtFinalElement(RIL_PARA, level))
739  ++paraid;
740  }
741  if (blockids != NULL) {
742  (*blockids)[component_index] = blockid;
743  if (page_it->IsAtFinalElement(RIL_BLOCK, level)) {
744  ++blockid;
745  paraid = 0;
746  }
747  }
748  ++component_index;
749  }
750  } while (page_it->Next(level));
751  delete page_it;
752  delete get_bbox;
753  return boxa;
754 }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:82
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:778
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
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
ResultIterator * GetIterator()
Definition: baseapi.cpp:1227
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:674

◆ 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 662 of file baseapi.cpp.

662  {
663  return GetComponentImages(RIL_SYMBOL, true, pixa, NULL);
664 }
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:674

◆ GetDawg()

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

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

Definition at line 2801 of file baseapi.cpp.

2801  {
2802  if (tesseract_ == NULL || i >= NumDawgs()) return NULL;
2803  return tesseract_->getDict().GetDawg(i);
2804 }
Dict & getDict() override
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int NumDawgs() const
Definition: baseapi.cpp:2807
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
Definition: dict.h:414

◆ 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 2720 of file baseapi.cpp.

2723  {
2724  GenericVector<int> outline_counts;
2727  INT_FX_RESULT_STRUCT fx_info;
2728  tesseract_->ExtractFeatures(*blob, false, &bl_features,
2729  &cn_features, &fx_info, &outline_counts);
2730  if (cn_features.empty() || cn_features.size() > MAX_NUM_INT_FEATURES) {
2731  *num_features = 0;
2732  return; // Feature extraction failed.
2733  }
2734  *num_features = cn_features.size();
2735  memcpy(int_features, &cn_features[0], *num_features * sizeof(cn_features[0]));
2736  // TODO(rays) Pass outline_counts back and simplify the calling code.
2737  if (feature_outline_index != NULL) {
2738  int f = 0;
2739  for (int i = 0; i < outline_counts.size(); ++i) {
2740  while (f < outline_counts[i])
2741  feature_outline_index[f++] = i;
2742  }
2743  }
2744 }
bool empty() const
Definition: genericvector.h:91
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
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int size() const
Definition: genericvector.h:72
#define MAX_NUM_INT_FEATURES
Definition: intproto.h:132

◆ 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 Returned string must be freed with the delete [] operator.

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. Returned string must be freed with the delete [] operator.

Definition at line 1402 of file baseapi.cpp.

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

◆ 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. Returned string must be freed with the delete [] operator.

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. Returned string must be freed with the delete [] operator.

Definition at line 1389 of file baseapi.cpp.

1389  {
1390  return GetHOCRText(NULL, page_number);
1391 }
char * GetHOCRText(ETEXT_DESC *monitor, int page_number)
Definition: baseapi.cpp:1402

◆ 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 1227 of file baseapi.cpp.

1227  {
1228  if (tesseract_ == NULL || page_res_ == NULL)
1229  return NULL;
1230  return ResultIterator::StartOfParagraph(LTRResultIterator(
1234 }
int GetScaledYResolution() const
Definition: thresholder.h:93
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
static ResultIterator * StartOfParagraph(const LTRResultIterator &resit)
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
PAGE_RES * page_res_
The page-level data.
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 1244 of file baseapi.cpp.

1244  {
1245  if (tesseract_ == NULL || page_res_ == NULL)
1246  return NULL;
1247  return new MutableIterator(page_res_, tesseract_,
1251 }
int GetScaledYResolution() const
Definition: thresholder.h:93
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
PAGE_RES * page_res_
The page-level data.
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 1897 of file baseapi.cpp.

1897  {
1898  int orient_deg;
1899  float orient_conf;
1900  const char* script_name;
1901  float script_conf;
1902 
1903  if (!DetectOrientationScript(&orient_deg, &orient_conf, &script_name,
1904  &script_conf))
1905  return NULL;
1906 
1907  // clockwise rotation needed to make the page upright
1908  int rotate = OrientationIdToValue(orient_deg / 90);
1909 
1910  const int kOsdBufsize = 255;
1911  char* osd_buf = new char[kOsdBufsize];
1912  snprintf(osd_buf, kOsdBufsize,
1913  "Page number: %d\n"
1914  "Orientation in degrees: %d\n"
1915  "Rotate: %d\n"
1916  "Orientation confidence: %.2f\n"
1917  "Script: %s\n"
1918  "Script confidence: %.2f\n",
1919  page_number, orient_deg, rotate, orient_conf, script_name,
1920  script_conf);
1921 
1922  return osd_buf;
1923 }
int OrientationIdToValue(const int &id)
Definition: osdetect.cpp:562
bool DetectOrientationScript(int *orient_deg, float *orient_conf, const char **script_name, float *script_conf)
Definition: baseapi.cpp:1866

◆ 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 617 of file baseapi.cpp.

617  {
618  return GetComponentImages(RIL_BLOCK, false, 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:674

◆ 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 643 of file baseapi.cpp.

643  {
644  return GetComponentImages(RIL_TEXTLINE, false, pixa, blockids);
645 }
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:674

◆ GetTextDirection()

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

Definition at line 2101 of file baseapi.cpp.

2101  {
2102  PageIterator* it = AnalyseLayout();
2103  if (it == NULL) {
2104  return false;
2105  }
2106  int x1, x2, y1, y2;
2107  it->Baseline(RIL_TEXTLINE, &x1, &y1, &x2, &y2);
2108  // Calculate offset and slope (NOTE: Kind of ugly)
2109  if (x2 <= x1) x2 = x1 + 1;
2110  // Convert the point pair to slope/offset of the baseline (in image coords.)
2111  *out_slope = static_cast<float>(y2 - y1) / (x2 - x1);
2112  *out_offset = static_cast<int>(y1 - *out_slope * x1);
2113  // Get the y-coord of the baseline at the left and right edges of the
2114  // textline's bounding box.
2115  int left, top, right, bottom;
2116  if (!it->BoundingBox(RIL_TEXTLINE, &left, &top, &right, &bottom)) {
2117  delete it;
2118  return false;
2119  }
2120  int left_y = IntCastRounded(*out_slope * left + *out_offset);
2121  int right_y = IntCastRounded(*out_slope * right + *out_offset);
2122  // Shift the baseline down so it passes through the nearest bottom-corner
2123  // of the textline's bounding box. This is the difference between the y
2124  // at the lowest (max) edge of the box and the actual box bottom.
2125  *out_offset += bottom - MAX(left_y, right_y);
2126  // Switch back to bottom-up tesseract coordinates. Requires negation of
2127  // the slope and height - offset for the offset.
2128  *out_slope = -*out_slope;
2129  *out_offset = rect_height_ - *out_offset;
2130  delete it;
2131 
2132  return true;
2133 }
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:778
#define MAX(x, y)
Definition: ndminx.h:24
int IntCastRounded(double x)
Definition: helpers.h:179

◆ 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 629 of file baseapi.cpp.

630  {
631  return GetComponentImages(RIL_TEXTLINE, true, raw_image, raw_padding,
632  pixa, blockids, paraids);
633 }
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:674

◆ 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:629

◆ 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 603 of file baseapi.cpp.

603  {
604  if (tesseract_ == nullptr || thresholder_ == nullptr) return nullptr;
605  if (tesseract_->pix_binary() == nullptr &&
607  return nullptr;
608  }
609  return pixClone(tesseract_->pix_binary());
610 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
virtual TESS_LOCAL bool Threshold(Pix **pix)
Definition: baseapi.cpp:2184
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
Pix * pix_binary() const

◆ 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 756 of file baseapi.cpp.

756  {
757  if (thresholder_ == NULL) {
758  return 0;
759  }
760  return thresholder_->GetScaleFactor();
761 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862

◆ 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. Returned string must be freed with the delete [] operator.

Definition at line 1574 of file baseapi.cpp.

1574  {
1575  if (tesseract_ == NULL || (page_res_ == NULL && Recognize(NULL) < 0))
1576  return NULL;
1577 
1578  int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
1579  int page_id = page_number + 1; // we use 1-based page numbers.
1580 
1581  STRING tsv_str("");
1582 
1583  int page_num = page_id, block_num = 0, par_num = 0, line_num = 0,
1584  word_num = 0;
1585 
1586  tsv_str.add_str_int("1\t", page_num); // level 1 - page
1587  tsv_str.add_str_int("\t", block_num);
1588  tsv_str.add_str_int("\t", par_num);
1589  tsv_str.add_str_int("\t", line_num);
1590  tsv_str.add_str_int("\t", word_num);
1591  tsv_str.add_str_int("\t", rect_left_);
1592  tsv_str.add_str_int("\t", rect_top_);
1593  tsv_str.add_str_int("\t", rect_width_);
1594  tsv_str.add_str_int("\t", rect_height_);
1595  tsv_str += "\t-1\t\n";
1596 
1597  ResultIterator* res_it = GetIterator();
1598  while (!res_it->Empty(RIL_BLOCK)) {
1599  if (res_it->Empty(RIL_WORD)) {
1600  res_it->Next(RIL_WORD);
1601  continue;
1602  }
1603 
1604  // Add rows for any new block/paragraph/textline.
1605  if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
1606  block_num++, par_num = 0, line_num = 0, word_num = 0;
1607  tsv_str.add_str_int("2\t", page_num); // level 2 - block
1608  tsv_str.add_str_int("\t", block_num);
1609  tsv_str.add_str_int("\t", par_num);
1610  tsv_str.add_str_int("\t", line_num);
1611  tsv_str.add_str_int("\t", word_num);
1612  AddBoxToTSV(res_it, RIL_BLOCK, &tsv_str);
1613  tsv_str += "\t-1\t\n"; // end of row for block
1614  }
1615  if (res_it->IsAtBeginningOf(RIL_PARA)) {
1616  par_num++, line_num = 0, word_num = 0;
1617  tsv_str.add_str_int("3\t", page_num); // level 3 - paragraph
1618  tsv_str.add_str_int("\t", block_num);
1619  tsv_str.add_str_int("\t", par_num);
1620  tsv_str.add_str_int("\t", line_num);
1621  tsv_str.add_str_int("\t", word_num);
1622  AddBoxToTSV(res_it, RIL_PARA, &tsv_str);
1623  tsv_str += "\t-1\t\n"; // end of row for para
1624  }
1625  if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
1626  line_num++, word_num = 0;
1627  tsv_str.add_str_int("4\t", page_num); // level 4 - line
1628  tsv_str.add_str_int("\t", block_num);
1629  tsv_str.add_str_int("\t", par_num);
1630  tsv_str.add_str_int("\t", line_num);
1631  tsv_str.add_str_int("\t", word_num);
1632  AddBoxToTSV(res_it, RIL_TEXTLINE, &tsv_str);
1633  tsv_str += "\t-1\t\n"; // end of row for line
1634  }
1635 
1636  // Now, process the word...
1637  int left, top, right, bottom;
1638  res_it->BoundingBox(RIL_WORD, &left, &top, &right, &bottom);
1639  word_num++;
1640  tsv_str.add_str_int("5\t", page_num); // level 5 - word
1641  tsv_str.add_str_int("\t", block_num);
1642  tsv_str.add_str_int("\t", par_num);
1643  tsv_str.add_str_int("\t", line_num);
1644  tsv_str.add_str_int("\t", word_num);
1645  tsv_str.add_str_int("\t", left);
1646  tsv_str.add_str_int("\t", top);
1647  tsv_str.add_str_int("\t", right - left);
1648  tsv_str.add_str_int("\t", bottom - top);
1649  tsv_str.add_str_int("\t", res_it->Confidence(RIL_WORD));
1650  tsv_str += "\t";
1651 
1652  // Increment counts if at end of block/paragraph/textline.
1653  if (res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD)) lcnt++;
1654  if (res_it->IsAtFinalElement(RIL_PARA, RIL_WORD)) pcnt++;
1655  if (res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD)) bcnt++;
1656 
1657  do {
1658  tsv_str +=
1659  std::unique_ptr<const char[]>(res_it->GetUTF8Text(RIL_SYMBOL)).get();
1660  res_it->Next(RIL_SYMBOL);
1661  } while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
1662  tsv_str += "\n"; // end of row
1663  wcnt++;
1664  }
1665 
1666  char* ret = new char[tsv_str.length() + 1];
1667  strcpy(ret, tsv_str.string());
1668  delete res_it;
1669  return ret;
1670 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:798
Definition: strngs.h:45
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
ResultIterator * GetIterator()
Definition: baseapi.cpp:1227

◆ GetUnichar()

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

This method returns the string form of the specified unichar.

Definition at line 2796 of file baseapi.cpp.

2796  {
2797  return tesseract_->unicharset.id_to_unichar(unichar_id);
2798 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:288
UNICHARSET unicharset
Definition: ccutil.h:68

◆ 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. Returned string must be freed with the delete [] operator.

Definition at line 1756 of file baseapi.cpp.

1756  {
1757  if (tesseract_ == NULL ||
1758  (!recognition_done_ && Recognize(NULL) < 0))
1759  return NULL;
1760  bool tilde_crunch_written = false;
1761  bool last_char_was_newline = true;
1762  bool last_char_was_tilde = false;
1763 
1764  int total_length = TextLength(NULL);
1765  PAGE_RES_IT page_res_it(page_res_);
1766  char* result = new char[total_length];
1767  char* ptr = result;
1768  for (page_res_it.restart_page(); page_res_it.word () != NULL;
1769  page_res_it.forward()) {
1770  WERD_RES *word = page_res_it.word();
1771  // Process the current word.
1772  if (word->unlv_crunch_mode != CR_NONE) {
1773  if (word->unlv_crunch_mode != CR_DELETE &&
1774  (!tilde_crunch_written ||
1775  (word->unlv_crunch_mode == CR_KEEP_SPACE &&
1776  word->word->space() > 0 &&
1777  !word->word->flag(W_FUZZY_NON) &&
1778  !word->word->flag(W_FUZZY_SP)))) {
1779  if (!word->word->flag(W_BOL) &&
1780  word->word->space() > 0 &&
1781  !word->word->flag(W_FUZZY_NON) &&
1782  !word->word->flag(W_FUZZY_SP)) {
1783  /* Write a space to separate from preceding good text */
1784  *ptr++ = ' ';
1785  last_char_was_tilde = false;
1786  }
1787  if (!last_char_was_tilde) {
1788  // Write a reject char.
1789  last_char_was_tilde = true;
1790  *ptr++ = kUNLVReject;
1791  tilde_crunch_written = true;
1792  last_char_was_newline = false;
1793  }
1794  }
1795  } else {
1796  // NORMAL PROCESSING of non tilde crunched words.
1797  tilde_crunch_written = false;
1799  const char* wordstr = word->best_choice->unichar_string().string();
1800  const STRING& lengths = word->best_choice->unichar_lengths();
1801  int length = lengths.length();
1802  int i = 0;
1803  int offset = 0;
1804 
1805  if (last_char_was_tilde &&
1806  word->word->space() == 0 && wordstr[offset] == ' ') {
1807  // Prevent adjacent tilde across words - we know that adjacent tildes
1808  // within words have been removed.
1809  // Skip the first character.
1810  offset = lengths[i++];
1811  }
1812  if (i < length && wordstr[offset] != 0) {
1813  if (!last_char_was_newline)
1814  *ptr++ = ' ';
1815  else
1816  last_char_was_newline = false;
1817  for (; i < length; offset += lengths[i++]) {
1818  if (wordstr[offset] == ' ' ||
1819  wordstr[offset] == kTesseractReject) {
1820  *ptr++ = kUNLVReject;
1821  last_char_was_tilde = true;
1822  } else {
1823  if (word->reject_map[i].rejected())
1824  *ptr++ = kUNLVSuspect;
1825  UNICHAR ch(wordstr + offset, lengths[i]);
1826  int uni_ch = ch.first_uni();
1827  for (int j = 0; kUniChs[j] != 0; ++j) {
1828  if (kUniChs[j] == uni_ch) {
1829  uni_ch = kLatinChs[j];
1830  break;
1831  }
1832  }
1833  if (uni_ch <= 0xff) {
1834  *ptr++ = static_cast<char>(uni_ch);
1835  last_char_was_tilde = false;
1836  } else {
1837  *ptr++ = kUNLVReject;
1838  last_char_was_tilde = true;
1839  }
1840  }
1841  }
1842  }
1843  }
1844  if (word->word->flag(W_EOL) && !last_char_was_newline) {
1845  /* Add a new line output */
1846  *ptr++ = '\n';
1847  tilde_crunch_written = false;
1848  last_char_was_newline = true;
1849  last_char_was_tilde = false;
1850  }
1851  }
1852  *ptr++ = '\n';
1853  *ptr = '\0';
1854  return result;
1855 }
const int kLatinChs[]
Definition: baseapi.cpp:1747
WERD_CHOICE * best_choice
Definition: pageres.h:219
REJMAP reject_map
Definition: pageres.h:271
Definition: werd.h:36
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:798
Definition: strngs.h:45
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:871
void set_unlv_suspects(WERD_RES *word)
Definition: output.cpp:305
const STRING & unichar_lengths() const
Definition: ratngs.h:544
Definition: werd.h:35
const char kUNLVReject
Definition: baseapi.cpp:89
const int kUniChs[]
Definition: baseapi.cpp:1743
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:294
const char kUNLVSuspect
Definition: baseapi.cpp:91
WERD * word
Definition: pageres.h:175
const STRING & unichar_string() const
Definition: ratngs.h:537
TESS_LOCAL int TextLength(int *blob_count)
Definition: baseapi.cpp:2327
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
const char * string() const
Definition: strngs.cpp:198
int32_t length() const
Definition: strngs.cpp:193
const char kTesseractReject
Definition: baseapi.cpp:87
uint8_t space()
Definition: werd.h:104

◆ 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 1254 of file baseapi.cpp.

1254  {
1255  if (tesseract_ == NULL ||
1256  (!recognition_done_ && Recognize(NULL) < 0))
1257  return NULL;
1258  STRING text("");
1259  ResultIterator *it = GetIterator();
1260  do {
1261  if (it->Empty(RIL_PARA)) continue;
1262  const std::unique_ptr<const char[]> para_text(it->GetUTF8Text(RIL_PARA));
1263  text += para_text.get();
1264  } while (it->Next(RIL_PARA));
1265  char* result = new char[text.length() + 1];
1266  strncpy(result, text.string(), text.length() + 1);
1267  delete it;
1268  return result;
1269 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:798
Definition: strngs.h:45
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:871
ResultIterator * GetIterator()
Definition: baseapi.cpp:1227

◆ 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 652 of file baseapi.cpp.

652  {
653  return GetComponentImages(RIL_WORD, true, pixa, NULL);
654 }
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:674

◆ InitTruthCallback()

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

Definition at line 761 of file baseapi.h.

761 { truth_cb_ = cb; }
TruthCallback * truth_cb_
Definition: baseapi.h:872

◆ IsValidCharacter()

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

Definition at line 2094 of file baseapi.cpp.

2094  {
2095  return tesseract_->unicharset.contains_unichar(utf8_character);
2096 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
bool contains_unichar(const char *const unichar_repr) const
Definition: unicharset.cpp:668
UNICHARSET unicharset
Definition: ccutil.h:68

◆ 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 2090 of file baseapi.cpp.

2090  {
2091  return tesseract_->getDict().valid_word(word);
2092 }
Dict & getDict() override
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:746

◆ 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 2470 of file baseapi.cpp.

2470  {
2471  int width = pixGetWidth(pix);
2472  int height = pixGetHeight(pix);
2473  BLOCK block("a character", TRUE, 0, 0, 0, 0, width, height);
2474 
2475  // Create C_BLOBs from the page
2476  extract_edges(pix, &block);
2477 
2478  // Merge all C_BLOBs
2479  C_BLOB_LIST *list = block.blob_list();
2480  C_BLOB_IT c_blob_it(list);
2481  if (c_blob_it.empty())
2482  return NULL;
2483  // Move all the outlines to the first blob.
2484  C_OUTLINE_IT ol_it(c_blob_it.data()->out_list());
2485  for (c_blob_it.forward();
2486  !c_blob_it.at_first();
2487  c_blob_it.forward()) {
2488  C_BLOB *c_blob = c_blob_it.data();
2489  ol_it.add_list_after(c_blob->out_list());
2490  }
2491  // Convert the first blob to the output TBLOB.
2492  return TBLOB::PolygonalCopy(false, c_blob_it.data());
2493 }
#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
static TBLOB * PolygonalCopy(bool allow_detailed_fx, C_BLOB *src)
Definition: blobs.cpp:344
Definition: ocrblock.h:30

◆ 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 2453 of file baseapi.cpp.

2456  {
2457  int32_t xstarts[] = {-32000};
2458  double quad_coeffs[] = {0, 0, baseline};
2459  return new ROW(1,
2460  xstarts,
2461  quad_coeffs,
2462  xheight,
2463  ascender - (baseline + xheight),
2464  descender - baseline,
2465  0,
2466  0);
2467 }
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 1926 of file baseapi.cpp.

1926  {
1927  int* conf = AllWordConfidences();
1928  if (!conf) return 0;
1929  int sum = 0;
1930  int *pt = conf;
1931  while (*pt >= 0) sum += *pt++;
1932  if (pt != conf) sum /= pt - conf;
1933  delete [] conf;
1934  return sum;
1935 }

◆ 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 2500 of file baseapi.cpp.

2500  {
2501  TBOX box = tblob->bounding_box();
2502  float x_center = (box.left() + box.right()) / 2.0f;
2503  float baseline = row->base_line(x_center);
2504  float scale = kBlnXHeight / row->x_height();
2505  tblob->Normalize(NULL, NULL, NULL, x_center, baseline, scale, scale,
2506  0.0f, static_cast<float>(kBlnBaselineOffset), false, NULL);
2507 }
float base_line(float xpos) const
Definition: ocrrow.h:56
int16_t left() const
Definition: rect.h:68
Definition: rect.h:30
const int kBlnXHeight
Definition: normalis.h:28
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
float x_height() const
Definition: ocrrow.h:61
TBOX bounding_box() const
Definition: blobs.cpp:482
const int kBlnBaselineOffset
Definition: normalis.h:29
int16_t right() const
Definition: rect.h:75

◆ NumDawgs()

int tesseract::TessBaseAPI::NumDawgs ( ) const

Return the number of dawgs loaded into tesseract_ object.

Definition at line 2807 of file baseapi.cpp.

2807  {
2808  return tesseract_ == NULL ? 0 : tesseract_->getDict().NumDawgs();
2809 }
Dict & getDict() override
int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
Definition: dict.h:412
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858

◆ oem()

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

Definition at line 759 of file baseapi.h.

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

◆ 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 1145 of file baseapi.cpp.

1147  {
1148  PERF_COUNT_START("ProcessPage")
1150  SetImage(pix);
1151  bool failed = false;
1152 
1153  if (tesseract_->tessedit_pageseg_mode == PSM_AUTO_ONLY) {
1154  // Disabled character recognition
1155  PageIterator* it = AnalyseLayout();
1156 
1157  if (it == NULL) {
1158  failed = true;
1159  } else {
1160  delete it;
1161  }
1163  failed = FindLines() != 0;
1164  } else if (timeout_millisec > 0) {
1165  // Running with a timeout.
1166  ETEXT_DESC monitor;
1167  monitor.cancel = NULL;
1168  monitor.cancel_this = NULL;
1169  monitor.set_deadline_msecs(timeout_millisec);
1170 
1171  // Now run the main recognition.
1172  failed = Recognize(&monitor) < 0;
1173  } else {
1174  // Normal layout and character recognition with no timeout.
1175  failed = Recognize(NULL) < 0;
1176  }
1177 
1179 #ifndef ANDROID_BUILD
1180  Pix* page_pix = GetThresholdedImage();
1181  pixWrite("tessinput.tif", page_pix, IFF_TIFF_G4);
1182 #endif // ANDROID_BUILD
1183  }
1184 
1185  if (failed && retry_config != NULL && retry_config[0] != '\0') {
1186  // Save current config variables before switching modes.
1187  FILE* fp = fopen(kOldVarsFile, "wb");
1188  PrintVariables(fp);
1189  fclose(fp);
1190  // Switch to alternate mode for retry.
1191  ReadConfigFile(retry_config);
1192  SetImage(pix);
1193  Recognize(NULL);
1194  // Restore saved config variables.
1196  }
1197 
1198  if (renderer && !failed) {
1199  failed = !renderer->AddImage(this);
1200  }
1201 
1203  return !failed;
1204 }
const char * kOldVarsFile
Definition: baseapi.cpp:100
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:778
#define PERF_COUNT_START(FUNCT_NAME)
void * cancel_this
called whenever progress increases
Definition: ocrclass.h:127
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:555
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:798
void set_deadline_msecs(int32_t deadline_msecs)
Definition: ocrclass.h:146
void SetInputName(const char *name)
Definition: baseapi.cpp:251
void PrintVariables(FILE *fp) const
Definition: baseapi.cpp:314
Orientation and script detection only.
Definition: publictypes.h:164
#define PERF_COUNT_END
Pix * GetThresholdedImage()
Definition: baseapi.cpp:603
CANCEL_FUNC cancel
for errcode use
Definition: ocrclass.h:125
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2228
Automatic page segmentation, but no OSD, or OCR.
Definition: publictypes.h:167
void ReadConfigFile(const char *filename)
Definition: baseapi.cpp:478

◆ 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 1027 of file baseapi.cpp.

1029  {
1030  bool result =
1031  ProcessPagesInternal(filename, retry_config, timeout_millisec, renderer);
1032  if (result) {
1035  tprintf("Write of TR file failed: %s\n", output_file_->string());
1036  return false;
1037  }
1038  }
1039  return result;
1040 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
bool WriteTRFile(const STRING &filename)
Definition: blobclass.cpp:97
bool ProcessPagesInternal(const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
Definition: baseapi.cpp:1053
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:867
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198

◆ ProcessPagesInternal()

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

Definition at line 1053 of file baseapi.cpp.

1056  {
1057  PERF_COUNT_START("ProcessPages")
1058  bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
1059  if (stdInput) {
1060 #ifdef WIN32
1061  if (_setmode(_fileno(stdin), _O_BINARY) == -1)
1062  tprintf("ERROR: cin to binary: %s", strerror(errno));
1063 #endif // WIN32
1064  }
1065 
1066  if (stream_filelist) {
1067  return ProcessPagesFileList(stdin, NULL, retry_config,
1068  timeout_millisec, renderer,
1070  }
1071 
1072  // At this point we are officially in autodection territory.
1073  // That means any data in stdin must be buffered, to make it
1074  // seekable.
1075  std::string buf;
1076  const l_uint8 *data = NULL;
1077  if (stdInput) {
1078  buf.assign((std::istreambuf_iterator<char>(std::cin)),
1079  (std::istreambuf_iterator<char>()));
1080  data = reinterpret_cast<const l_uint8 *>(buf.data());
1081  }
1082 
1083  // Here is our autodetection
1084  int format;
1085  int r = (stdInput) ?
1086  findFileFormatBuffer(data, &format) :
1087  findFileFormat(filename, &format);
1088 
1089  // Maybe we have a filelist
1090  if (r != 0 || format == IFF_UNKNOWN) {
1091  STRING s;
1092  if (stdInput) {
1093  s = buf.c_str();
1094  } else {
1095  std::ifstream t(filename);
1096  std::string u((std::istreambuf_iterator<char>(t)),
1097  std::istreambuf_iterator<char>());
1098  s = u.c_str();
1099  }
1100  return ProcessPagesFileList(NULL, &s, retry_config,
1101  timeout_millisec, renderer,
1103  }
1104 
1105  // Maybe we have a TIFF which is potentially multipage
1106  bool tiff = (format == IFF_TIFF || format == IFF_TIFF_PACKBITS ||
1107  format == IFF_TIFF_RLE || format == IFF_TIFF_G3 ||
1108  format == IFF_TIFF_G4 || format == IFF_TIFF_LZW ||
1109  format == IFF_TIFF_ZIP);
1110 
1111  // Fail early if we can, before producing any output
1112  Pix *pix = NULL;
1113  if (!tiff) {
1114  pix = (stdInput) ? pixReadMem(data, buf.size()) : pixRead(filename);
1115  if (pix == NULL) {
1116  return false;
1117  }
1118  }
1119 
1120  // Begin the output
1121  if (renderer && !renderer->BeginDocument(unknown_title_)) {
1122  pixDestroy(&pix);
1123  return false;
1124  }
1125 
1126  // Produce output
1127  r = (tiff) ?
1128  ProcessPagesMultipageTiff(data, buf.size(), filename, retry_config,
1129  timeout_millisec, renderer,
1131  ProcessPage(pix, 0, filename, retry_config,
1132  timeout_millisec, renderer);
1133 
1134  // Clean up memory as needed
1135  pixDestroy(&pix);
1136 
1137  // End the output
1138  if (!r || (renderer && !renderer->EndDocument())) {
1139  return false;
1140  }
1142  return true;
1143 }
#define PERF_COUNT_START(FUNCT_NAME)
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
Definition: strngs.h:45
#define tprintf(...)
Definition: tprintf.h:31
bool ProcessPage(Pix *pix, int page_index, const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
Definition: baseapi.cpp:1145
#define PERF_COUNT_END
bool stream_filelist
Definition: baseapi.cpp:80
const char * c_str() const
Definition: strngs.cpp:209

◆ 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 798 of file baseapi.cpp.

798  {
799  if (tesseract_ == NULL)
800  return -1;
801  if (FindLines() != 0)
802  return -1;
803  delete page_res_;
804  if (block_list_->empty()) {
805  page_res_ = new PAGE_RES(false, block_list_,
807  return 0; // Empty page.
808  }
809 
811  recognition_done_ = true;
816  } else {
819  }
820  if (page_res_ == NULL) {
821  return -1;
822  }
826  return 0;
827  }
830  return 0;
831  }
832 
833  if (truth_cb_ != NULL) {
834  tesseract_->wordrec_run_blamer.set_value(true);
835  PageIterator *page_it = new PageIterator(
840  image_height_, page_it, this->tesseract()->pix_grey());
841  delete page_it;
842  }
843 
844  int result = 0;
846  #ifndef GRAPHICS_DISABLED
848  #endif // GRAPHICS_DISABLED
849  // The page_res is invalid after an interactive session, so cleanup
850  // in a way that lets us continue to the next page without crashing.
851  delete page_res_;
852  page_res_ = NULL;
853  return -1;
855  STRING fontname;
856  ExtractFontName(*output_file_, &fontname);
858  } else if (tesseract_->tessedit_ambigs_training) {
859  FILE *training_output_file = tesseract_->init_recog_training(*input_file_);
860  // OCR the page segmented into words by tesseract.
862  *input_file_, page_res_, monitor, training_output_file);
863  fclose(training_output_file);
864  } else {
865  // Now run the main recognition.
866  bool wait_for_text = true;
867  GetBoolVariable("paragraph_text_based", &wait_for_text);
868  if (!wait_for_text) DetectParagraphs(false);
869  if (tesseract_->recog_all_words(page_res_, monitor, NULL, NULL, 0)) {
870  if (wait_for_text) DetectParagraphs(true);
871  } else {
872  result = -1;
873  }
874  }
875  return result;
876 }
Dict & getDict() override
Pix * pix_grey() const
int GetScaledYResolution() const
Definition: thresholder.h:93
STRING * input_file_
Name used by training code.
Definition: baseapi.h:866
void ExtractFontName(const STRING &filename, STRING *fontname)
Definition: blobclass.cpp:46
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
void recog_training_segmented(const STRING &fname, PAGE_RES *page_res, volatile ETEXT_DESC *monitor, FILE *output_file)
Definition: strngs.h:45
void CorrectClassifyWords(PAGE_RES *page_res)
Definition: applybox.cpp:772
bool wordrec_run_blamer
Definition: wordrec.h:168
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:871
FILE * init_recog_training(const STRING &fname)
Tesseract * tesseract() const
Definition: baseapi.h:757
TruthCallback * truth_cb_
Definition: baseapi.h:872
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:867
void pgeditor_main(int width, int height, PAGE_RES *page_res)
Definition: pgedit.cpp:337
bool tessedit_resegment_from_line_boxes
bool AnyLSTMLang() const
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
PAGE_RES * ApplyBoxes(const STRING &fname, bool find_segmentation, BLOCK_LIST *block_list)
Definition: applybox.cpp:117
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:412
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
bool GetBoolVariable(const char *name, bool *value) const
Definition: baseapi.cpp:286
const UNICHARSET & getUnicharset() const
Definition: dict.h:97
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2228
virtual void Run(A1, A2, A3, A4)=0
void TrainLineRecognizer(const STRING &input_imagename, const STRING &output_basename, BLOCK_LIST *block_list)
Definition: linerec.cpp:42
void ApplyBoxTraining(const STRING &fontname, PAGE_RES *page_res)
Definition: applybox.cpp:796
TESS_LOCAL void DetectParagraphs(bool after_text_recognition)
Definition: baseapi.cpp:2582
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:300

◆ 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 879 of file baseapi.cpp.

879  {
880  if (tesseract_ == NULL)
881  return -1;
882  if (thresholder_ == NULL || thresholder_->IsEmpty()) {
883  tprintf("Please call SetImage before attempting recognition.\n");
884  return -1;
885  }
886  if (page_res_ != NULL)
887  ClearResults();
888  if (FindLines() != 0)
889  return -1;
890  // Additional conditions under which chopper test cannot be run
891  if (tesseract_->interactive_display_mode) return -1;
892 
893  recognition_done_ = true;
894 
895  page_res_ = new PAGE_RES(false, block_list_,
897 
898  PAGE_RES_IT page_res_it(page_res_);
899 
900  while (page_res_it.word() != NULL) {
901  WERD_RES *word_res = page_res_it.word();
902  GenericVector<TBOX> boxes;
903  tesseract_->MaximallyChopWord(boxes, page_res_it.block()->block,
904  page_res_it.row()->row, word_res);
905  page_res_it.forward();
906  }
907  return 0;
908 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:871
bool IsEmpty() const
Return true if no image has been set.
Definition: thresholder.cpp:50
WERD * word
Definition: pageres.h:175
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
#define tprintf(...)
Definition: tprintf.h:31
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:865
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:412
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:864
void MaximallyChopWord(const GenericVector< TBOX > &boxes, BLOCK *block, ROW *row, WERD_RES *word_res)
Definition: applybox.cpp:253
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:2228

◆ 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 2773 of file baseapi.cpp.

2777  {
2778  BLOB_CHOICE_LIST* choices = new BLOB_CHOICE_LIST;
2779  tesseract_->AdaptiveClassifier(blob, choices);
2780  BLOB_CHOICE_IT choices_it(choices);
2781  int& index = *num_matches_returned;
2782  index = 0;
2783  for (choices_it.mark_cycle_pt();
2784  !choices_it.cycled_list() && index < num_max_matches;
2785  choices_it.forward()) {
2786  BLOB_CHOICE* choice = choices_it.data();
2787  unichar_ids[index] = choice->unichar_id();
2788  ratings[index] = choice->rating();
2789  ++index;
2790  }
2791  *num_matches_returned = index;
2792  delete choices;
2793 }
void AdaptiveClassifier(TBLOB *Blob, BLOB_CHOICE_LIST *Choices)
Definition: adaptmatch.cpp:185
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
UNICHAR_ID unichar_id() const
Definition: ratngs.h:76
float rating() const
Definition: ratngs.h:79

◆ set_min_orientation_margin()

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

Definition at line 2370 of file baseapi.cpp.

2370  {
2371  tesseract_->min_orientation_margin.set_value(margin);
2372 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858

◆ SetDictFunc()

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

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

Definition at line 2136 of file baseapi.cpp.

2136  {
2137  if (tesseract_ != NULL) {
2139  }
2140 }
Dict & getDict() override
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.h:356

◆ SetFillLatticeFunc()

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

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

Definition at line 2162 of file baseapi.cpp.

2162  {
2163  if (tesseract_ != NULL) tesseract_->fill_lattice_ = f;
2164 }
void(Wordrec::* fill_lattice_)(const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
Definition: wordrec.h:416
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858

◆ 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 555 of file baseapi.cpp.

557  {
558  if (InternalSetImage()) {
559  thresholder_->SetImage(imagedata, width, height,
560  bytes_per_pixel, bytes_per_line);
562  }
563 }
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: thresholder.cpp:62
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
void SetInputImage(Pix *pix)
Definition: baseapi.cpp:911
TESS_LOCAL bool InternalSetImage()
Definition: baseapi.cpp:2167

◆ 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 580 of file baseapi.cpp.

580  {
581  if (InternalSetImage()) {
582  thresholder_->SetImage(pix);
584  }
585 }
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: thresholder.cpp:62
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
void SetInputImage(Pix *pix)
Definition: baseapi.cpp:911
TESS_LOCAL bool InternalSetImage()
Definition: baseapi.cpp:2167

◆ 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 2150 of file baseapi.cpp.

2150  {
2151  if (tesseract_ != NULL) {
2153  // Set it for the sublangs too.
2154  int num_subs = tesseract_->num_sub_langs();
2155  for (int i = 0; i < num_subs; ++i) {
2157  }
2158  }
2159 }
Dict & getDict() override
Tesseract * get_sub_lang(int index) const
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:858
int num_sub_langs() const
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:366

◆ 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 592 of file baseapi.cpp.

592  {
593  if (thresholder_ == NULL)
594  return;
595  thresholder_->SetRectangle(left, top, width, height);
596  ClearResults();
597 }
void SetRectangle(int left, int top, int width, int height)
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862

◆ 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 565 of file baseapi.cpp.

565  {
566  if (thresholder_)
568  else
569  tprintf("Please call SetImage before SetSourceResolution.\n");
570 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:862
#define tprintf(...)
Definition: tprintf.h:31
void SetSourceYResolution(int ppi)
Definition: thresholder.h:86

◆ 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:862

◆ tesseract()

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

Definition at line 757 of file baseapi.h.

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