Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 (const 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 (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 (PageIteratorLevel level, bool text_only, Pixa **pixa, int **blockids)
 
int tesseract::TessBaseAPI::GetThresholdedImageScaleFactor () const
 
void tesseract::TessBaseAPI::DumpPGM (const char *filename)
 
PageIterator * tesseract::TessBaseAPI::AnalyseLayout ()
 
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, STRING *text_out)
 
bool tesseract::TessBaseAPI::ProcessPage (Pix *pix, int page_index, const char *filename, const char *retry_config, int timeout_millisec, STRING *text_out)
 
ResultIterator * tesseract::TessBaseAPI::GetIterator ()
 
MutableIterator * tesseract::TessBaseAPI::GetMutableIterator ()
 
char * tesseract::TessBaseAPI::GetUTF8Text ()
 
char * tesseract::TessBaseAPI::GetHOCRText (int page_number)
 
char * tesseract::TessBaseAPI::GetBoxText (int page_number)
 
char * tesseract::TessBaseAPI::GetUNLVText ()
 
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 ()
 
int tesseract::TessBaseAPI::IsValidWord (const char *word)
 
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, const DENORM &denorm, INT_FEATURE_ARRAY int_features, int *num_features, int *FeatureOutlineIndex)
 
static ROWtesseract::TessBaseAPI::FindRowForBox (BLOCK_LIST *blocks, int left, int top, int right, int bottom)
 
void tesseract::TessBaseAPI::RunAdaptiveClassifier (TBLOB *blob, const DENORM &denorm, int num_max_matches, int *unichar_ids, float *ratings, int *num_matches_returned)
 
const char * tesseract::TessBaseAPI::GetUnichar (int unichar_id)
 
const Dawg * tesseract::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, DENORM *denorm)
 
Tesseract *const tesseract::TessBaseAPI::tesseract () const
 
OcrEngineMode const tesseract::TessBaseAPI::oem () const
 
void tesseract::TessBaseAPI::InitTruthCallback (TruthCallback *cb)
 
CubeRecoContext * tesseract::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

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

1396  {
1397  int debug = 0;
1398  GetIntVariable("applybox_debug", &debug);
1399  bool success = true;
1400  PageSegMode current_psm = GetPageSegMode();
1402  SetVariable("classify_enable_learning", "0");
1403  char* text = GetUTF8Text();
1404  if (debug) {
1405  tprintf("Trying to adapt \"%s\" to \"%s\"\n", text, wordstr);
1406  }
1407  if (text != NULL) {
1408  PAGE_RES_IT it(page_res_);
1409  WERD_RES* word_res = it.word();
1410  if (word_res != NULL) {
1411  word_res->word->set_text(wordstr);
1412  } else {
1413  success = false;
1414  }
1415  // Check to see if text matches wordstr.
1416  int w = 0;
1417  int t = 0;
1418  for (t = 0; text[t] != '\0'; ++t) {
1419  if (text[t] == '\n' || text[t] == ' ')
1420  continue;
1421  while (wordstr[w] != '\0' && wordstr[w] == ' ')
1422  ++w;
1423  if (text[t] != wordstr[w])
1424  break;
1425  ++w;
1426  }
1427  if (text[t] != '\0' || wordstr[w] != '\0') {
1428  // No match.
1429  delete page_res_;
1430  GenericVector<TBOX> boxes;
1434  PAGE_RES_IT pr_it(page_res_);
1435  if (pr_it.word() == NULL)
1436  success = false;
1437  else
1438  word_res = pr_it.word();
1439  } else {
1440  word_res->BestChoiceToCorrectText();
1441  }
1442  if (success) {
1443  tesseract_->EnableLearning = true;
1444  tesseract_->LearnWord(NULL, NULL, word_res);
1445  }
1446  delete [] text;
1447  } else {
1448  success = false;
1449  }
1450  SetPageSegMode(current_psm);
1451  return success;
1452 }
void set_text(const char *new_text)
Definition: werd.h:120
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
void LearnWord(const char *filename, const char *rejmap, WERD_RES *word)
Definition: adaptmatch.cpp:254
#define NULL
Definition: host.h:144
PAGE_RES * SetupApplyBoxes(const GenericVector< TBOX > &boxes, BLOCK_LIST *block_list)
Definition: applybox.cpp:197
bool GetIntVariable(const char *name, int *value) const
Definition: baseapi.cpp:165
WERD * word
Definition: pageres.h:334
void ReSegmentByClassification(PAGE_RES *page_res)
Definition: applybox.cpp:510
PageSegMode GetPageSegMode() const
Definition: baseapi.cpp:377
CMD_EVENTS mode
Definition: pgedit.cpp:115
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
void TidyUp(PAGE_RES *page_res)
Definition: applybox.cpp:702
void BestChoiceToCorrectText()
Definition: pageres.cpp:572
void SetPageSegMode(PageSegMode mode)
Definition: baseapi.cpp:370
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:153
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 1362 of file baseapi.cpp.

1362  {
1363  if (tesseract_ == NULL ||
1364  (!recognition_done_ && Recognize(NULL) < 0))
1365  return NULL;
1366  int n_word = 0;
1367  PAGE_RES_IT res_it(page_res_);
1368  for (res_it.restart_page(); res_it.word() != NULL; res_it.forward())
1369  n_word++;
1370 
1371  int* conf = new int[n_word+1];
1372  n_word = 0;
1373  for (res_it.restart_page(); res_it.word() != NULL; res_it.forward()) {
1374  WERD_RES *word = res_it.word();
1375  WERD_CHOICE* choice = word->best_choice;
1376  int w_conf = static_cast<int>(100 + 5 * choice->certainty());
1377  // This is the eq for converting Tesseract confidence to 1..100
1378  if (w_conf < 0) w_conf = 0;
1379  if (w_conf > 100) w_conf = 100;
1380  conf[n_word++] = w_conf;
1381  }
1382  conf[n_word] = -1;
1383  return conf;
1384 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
float certainty() const
Definition: ratngs.h:234
#define NULL
Definition: host.h:144
WERD * word
Definition: pageres.h:334
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:773
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:696
WERD_CHOICE * best_choice
Definition: pageres.h:359
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. Returns NULL on error. 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.

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

678  {
679  if (FindLines() == 0) {
680  if (block_list_->empty())
681  return NULL; // The page was empty.
683  DetectParagraphs(false);
684  return new PageIterator(
688  }
689  return NULL;
690 }
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:1636
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
int GetScaledYResolution() const
Definition: thresholder.h:93
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
TESS_LOCAL void DetectParagraphs(bool after_text_recognition)
Definition: baseapi.cpp:1987
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 1460 of file baseapi.cpp.

1460  {
1461  if (thresholder_ != NULL)
1462  thresholder_->Clear();
1463  ClearResults();
1464 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
virtual void Clear()
Destroy the Pix if there is one, freeing memory.
Definition: thresholder.cpp:45
#define NULL
Definition: host.h:144
TESS_LOCAL void ClearResults()
Definition: baseapi.cpp:1699
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 1845 of file baseapi.cpp.

1845  {
1846  delete block_list;
1847 }
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 1756 of file baseapi.cpp.

1756  {
1757  if (tesseract_ == NULL)
1758  return false;
1759  ClearResults();
1760  if (tesseract_->pix_binary() == NULL)
1762  if (input_file_ == NULL)
1763  input_file_ = new STRING(kInputFile);
1765 }
STRING * input_file_
Name used by training code.
Definition: baseapi.h:768
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
int orientation_and_script_detection(STRING &filename, OSResults *osr, tesseract::Tesseract *tess)
Definition: osdetect.cpp:189
const char * kInputFile
Definition: baseapi.cpp:88
TESS_LOCAL void ClearResults()
Definition: baseapi.cpp:1699
Definition: strngs.h:40
virtual TESS_LOCAL void Threshold(Pix **pix)
Definition: baseapi.cpp:1603
Pix * pix_binary() const
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 604 of file baseapi.cpp.

604  {
605  if (tesseract_ == NULL)
606  return;
607  FILE *fp = fopen(filename, "wb");
608  Pix* pix = tesseract_->pix_binary();
609  int width = pixGetWidth(pix);
610  int height = pixGetHeight(pix);
611  l_uint32* data = pixGetData(pix);
612  fprintf(fp, "P5 %d %d 255\n", width, height);
613  for (int y = 0; y < height; ++y, data += pixGetWpl(pix)) {
614  for (int x = 0; x < width; ++x) {
615  uinT8 b = GET_DATA_BIT(data, x) ? 0 : 255;
616  fwrite(&b, 1, 1, fp);
617  }
618  }
619  fclose(fp);
620 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
unsigned char uinT8
Definition: host.h:99
Pix * pix_binary() const
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 1472 of file baseapi.cpp.

1472  {
1473  if (thresholder_ != NULL) {
1474  delete thresholder_;
1475  thresholder_ = NULL;
1476  }
1477  if (page_res_ != NULL) {
1478  delete page_res_;
1479  page_res_ = NULL;
1480  }
1481  if (block_list_ != NULL) {
1482  delete block_list_;
1483  block_list_ = NULL;
1484  }
1485  if (paragraph_models_ != NULL) {
1487  delete paragraph_models_;
1489  }
1490  if (tesseract_ != NULL) {
1491  delete tesseract_;
1492  if (osd_tesseract_ == tesseract_)
1493  osd_tesseract_ = NULL;
1494  tesseract_ = NULL;
1495  }
1496  if (osd_tesseract_ != NULL) {
1497  delete osd_tesseract_;
1498  osd_tesseract_ = NULL;
1499  }
1500  if (equ_detect_ != NULL) {
1501  delete equ_detect_;
1502  equ_detect_ = NULL;
1503  }
1504  if (input_file_ != NULL) {
1505  delete input_file_;
1506  input_file_ = NULL;
1507  }
1508  if (output_file_ != NULL) {
1509  delete output_file_;
1510  output_file_ = NULL;
1511  }
1512  if (datapath_ != NULL) {
1513  delete datapath_;
1514  datapath_ = NULL;
1515  }
1516  if (language_ != NULL) {
1517  delete language_;
1518  language_ = NULL;
1519  }
1520 }
void delete_data_pointers()
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
EquationDetect * equ_detect_
The equation detector.
Definition: baseapi.h:763
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
STRING * input_file_
Name used by training code.
Definition: baseapi.h:768
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
STRING * datapath_
Current location of tessdata.
Definition: baseapi.h:770
GenericVector< ParagraphModel * > * paragraph_models_
Definition: baseapi.h:765
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:769
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
Tesseract * osd_tesseract_
For orientation & script detection.
Definition: baseapi.h:762
STRING * language_
Last initialized language.
Definition: baseapi.h:771
BLOCK_LIST * tesseract::TessBaseAPI::FindLinesCreateBlockList ( )

Find lines from the image making the BLOCK_LIST.

Definition at line 1833 of file baseapi.cpp.

1833  {
1834  FindLines();
1835  BLOCK_LIST* result = block_list_;
1836  block_list_ = NULL;
1837  return result;
1838 }
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:1636
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
#define NULL
Definition: host.h:144
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 2138 of file baseapi.cpp.

2139  {
2140  TBOX box(left, bottom, right, top);
2141  BLOCK_IT b_it(blocks);
2142  for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
2143  BLOCK* block = b_it.data();
2144  if (!box.major_overlap(block->bounding_box()))
2145  continue;
2146  ROW_IT r_it(block->row_list());
2147  for (r_it.mark_cycle_pt(); !r_it.cycled_list(); r_it.forward()) {
2148  ROW* row = r_it.data();
2149  if (!box.major_overlap(row->bounding_box()))
2150  continue;
2151  WERD_IT w_it(row->word_list());
2152  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
2153  WERD* word = w_it.data();
2154  if (box.major_overlap(word->bounding_box()))
2155  return row;
2156  }
2157  }
2158  }
2159  return NULL;
2160 }
TBOX bounding_box()
Definition: werd.cpp:164
#define NULL
Definition: host.h:144
ROW_LIST * row_list()
get rows
Definition: ocrblock.h:121
Definition: rect.h:29
Definition: ocrrow.h:32
Definition: ocrblock.h:31
Definition: werd.h:60
TBOX bounding_box() const
Definition: ocrrow.h:85
WERD_LIST * word_list()
Definition: ocrrow.h:52
size_t top
Definition: tessarray.h:52
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:70
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 1785 of file baseapi.cpp.

1786  {
1787  delete[] *block_orientation;
1788  *block_orientation = NULL;
1789  delete[] *vertical_writing;
1790  *vertical_writing = NULL;
1791  BLOCK_IT block_it(block_list_);
1792 
1793  block_it.move_to_first();
1794  int num_blocks = 0;
1795  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
1796  if (!block_it.data()->poly_block()->IsText()) {
1797  continue;
1798  }
1799  ++num_blocks;
1800  }
1801  if (!num_blocks) {
1802  tprintf("WARNING: Found no blocks\n");
1803  return;
1804  }
1805  *block_orientation = new int[num_blocks];
1806  *vertical_writing = new bool[num_blocks];
1807  block_it.move_to_first();
1808  int i = 0;
1809  for (block_it.mark_cycle_pt(); !block_it.cycled_list();
1810  block_it.forward()) {
1811  if (!block_it.data()->poly_block()->IsText()) {
1812  continue;
1813  }
1814  FCOORD re_rotation = block_it.data()->re_rotation();
1815  float re_theta = re_rotation.angle();
1816  FCOORD classify_rotation = block_it.data()->classify_rotation();
1817  float classify_theta = classify_rotation.angle();
1818  double rot_theta = - (re_theta - classify_theta) * 2.0 / PI;
1819  if (rot_theta < 0) rot_theta += 4;
1820  int num_rotations = static_cast<int>(rot_theta + 0.5);
1821  (*block_orientation)[i] = num_rotations;
1822  // The classify_rotation is non-zero only if the text has vertical
1823  // writing direction.
1824  (*vertical_writing)[i] = classify_rotation.y() != 0.0f;
1825  ++i;
1826  }
1827 }
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
#define NULL
Definition: host.h:144
#define PI
Definition: const.h:19
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
float angle() const
find angle
Definition: points.h:249
Definition: points.h:189
float y() const
Definition: points.h:212
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 1193 of file baseapi.cpp.

1193  {
1194  if (tesseract_ == NULL ||
1195  (!recognition_done_ && Recognize(NULL) < 0))
1196  return NULL;
1197  int blob_count;
1198  int utf8_length = TextLength(&blob_count);
1199  int total_length = blob_count * kBytesPerBoxFileLine + utf8_length +
1201  char* result = new char[total_length];
1202  strcpy(result, "\0");
1203  int output_length = 0;
1204  LTRResultIterator* it = GetLTRIterator();
1205  do {
1206  int left, top, right, bottom;
1207  if (it->BoundingBox(RIL_SYMBOL, &left, &top, &right, &bottom)) {
1208  char* text = it->GetUTF8Text(RIL_SYMBOL);
1209  // Tesseract uses space for recognition failure. Fix to a reject
1210  // character, kTesseractReject so we don't create illegal box files.
1211  for (int i = 0; text[i] != '\0'; ++i) {
1212  if (text[i] == ' ')
1213  text[i] = kTesseractReject;
1214  }
1215  snprintf(result + output_length, total_length - output_length,
1216  "%s %d %d %d %d %d\n",
1217  text, left, image_height_ - bottom,
1218  right, image_height_ - top, page_number);
1219  output_length += strlen(result + output_length);
1220  delete [] text;
1221  // Just in case...
1222  if (output_length + kMaxBytesPerLine > total_length)
1223  break;
1224  }
1225  } while (it->Next(RIL_SYMBOL));
1226  delete it;
1227  return result;
1228 }
const int kBytesPerBoxFileLine
Definition: baseapi.cpp:1176
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
const int kMaxBytesPerLine
Definition: baseapi.cpp:1185
#define NULL
Definition: host.h:144
TESS_LOCAL LTRResultIterator * GetLTRIterator()
Definition: baseapi.cpp:973
const char kTesseractReject
Definition: baseapi.cpp:79
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:773
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:696
size_t top
Definition: tessarray.h:52
TESS_LOCAL int TextLength(int *blob_count)
Definition: baseapi.cpp:1726
Boxa * tesseract::TessBaseAPI::GetComponentImages ( PageIteratorLevel  level,
bool  text_only,
Pixa **  pixa,
int **  blockids 
)

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

549  {
550  PageIterator* page_it = GetIterator();
551  if (page_it == NULL)
552  page_it = AnalyseLayout();
553  if (page_it == NULL)
554  return NULL; // Failed.
555 
556  // Count the components to get a size for the arrays.
557  int component_count = 0;
558  int left, top, right, bottom;
559  do {
560  if (page_it->BoundingBoxInternal(level, &left, &top, &right, &bottom) &&
561  (!text_only || PTIsTextType(page_it->BlockType())))
562  ++component_count;
563  } while (page_it->Next(level));
564 
565  Boxa* boxa = boxaCreate(component_count);
566  if (pixa != NULL)
567  *pixa = pixaCreate(component_count);
568  if (blockids != NULL)
569  *blockids = new int[component_count];
570 
571  int blockid = 0;
572  int component_index = 0;
573  page_it->Begin();
574  do {
575  if (page_it->BoundingBoxInternal(level, &left, &top, &right, &bottom) &&
576  (!text_only || PTIsTextType(page_it->BlockType()))) {
577  Box* lbox = boxCreate(left, top, right - left, bottom - top);
578  boxaAddBox(boxa, lbox, L_INSERT);
579  if (pixa != NULL) {
580  Pix* pix = page_it->GetBinaryImage(level);
581  pixaAddPix(*pixa, pix, L_INSERT);
582  pixaAddBox(*pixa, lbox, L_CLONE);
583  }
584  if (blockids != NULL) {
585  (*blockids)[component_index] = blockid;
586  if (page_it->IsAtFinalElement(RIL_BLOCK, level))
587  ++blockid;
588  }
589  ++component_index;
590  }
591  } while (page_it->Next(level));
592  delete page_it;
593  return boxa;
594 }
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:678
#define NULL
Definition: host.h:144
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70
size_t top
Definition: tessarray.h:52
ResultIterator * GetIterator()
Definition: baseapi.cpp:990
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 535 of file baseapi.cpp.

535  {
536  return GetComponentImages(RIL_SYMBOL, true, pixa, NULL);
537 }
#define NULL
Definition: host.h:144
Boxa * GetComponentImages(PageIteratorLevel level, bool text_only, Pixa **pixa, int **blockids)
Definition: baseapi.cpp:547
CubeRecoContext * tesseract::TessBaseAPI::GetCubeRecoContext ( ) const

Return a pointer to underlying CubeRecoContext object if present.

Definition at line 2202 of file baseapi.cpp.

2202  {
2203  return (tesseract_ == NULL) ? NULL : tesseract_->GetCubeRecoContext();
2204 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
CubeRecoContext * GetCubeRecoContext()
const Dawg * tesseract::TessBaseAPI::GetDawg ( int  i) const

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

Definition at line 2191 of file baseapi.cpp.

2191  {
2192  if (tesseract_ == NULL || i >= NumDawgs()) return NULL;
2193  return tesseract_->getDict().GetDawg(i);
2194 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
Dict & getDict()
Definition: classify.h:62
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
Definition: dict.h:605
int NumDawgs() const
Definition: baseapi.cpp:2197
void tesseract::TessBaseAPI::GetFeaturesForBlob ( TBLOB blob,
const DENORM denorm,
INT_FEATURE_ARRAY  int_features,
int *  num_features,
int *  FeatureOutlineIndex 
)

This method returns the features associated with the input image.

This method returns the features associated with the input blob.

Definition at line 2119 of file baseapi.cpp.

2122  {
2123  if (tesseract_) {
2125  }
2126  uinT8* norm_array = new uinT8[MAX_NUM_CLASSES];
2127  inT32 len;
2128  *num_features = tesseract_->GetCharNormFeatures(
2129  blob, denorm, tesseract_->PreTrainedTemplates,
2130  int_features, norm_array, norm_array, &len, FeatureOutlineIndex);
2131  delete [] norm_array;
2132 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
int inT32
Definition: host.h:102
INT_TEMPLATES PreTrainedTemplates
Definition: classify.h:426
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
void ResetFeaturesHaveBeenExtracted()
unsigned char uinT8
Definition: host.h:99
int GetCharNormFeatures(TBLOB *Blob, const DENORM &denorm, INT_TEMPLATES Templates, INT_FEATURE_ARRAY IntFeatures, uinT8 *PrunerNormArray, uinT8 *CharNormArray, inT32 *BlobLength, inT32 *FeatureOutlineIndex)
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 1055 of file baseapi.cpp.

1055  {
1056  if (tesseract_ == NULL ||
1057  (page_res_ == NULL && Recognize(NULL) < 0))
1058  return NULL;
1059 
1060  int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
1061  int page_id = page_number + 1; // hOCR uses 1-based page numbers.
1062 
1063  STRING hocr_str("");
1064 
1065  if (input_file_ == NULL)
1066  SetInputName(NULL);
1067 
1068  hocr_str.add_str_int(" <div class='ocr_page' id='page_", page_id);
1069  hocr_str += "' title='image \"";
1070  hocr_str += input_file_ ? *input_file_ : "unknown";
1071  hocr_str.add_str_int("\"; bbox ", rect_left_);
1072  hocr_str.add_str_int(" ", rect_top_);
1073  hocr_str.add_str_int(" ", rect_width_);
1074  hocr_str.add_str_int(" ", rect_height_);
1075  hocr_str.add_str_int("; ppageno ", page_number);
1076  hocr_str += "'>\n";
1077 
1078  ResultIterator *res_it = GetIterator();
1079  while (!res_it->Empty(RIL_BLOCK)) {
1080  if (res_it->Empty(RIL_WORD)) {
1081  res_it->Next(RIL_WORD);
1082  continue;
1083  }
1084 
1085  // Open any new block/paragraph/textline.
1086  if (res_it->IsAtBeginningOf(RIL_BLOCK)) {
1087  hocr_str.add_str_int(" <div class='ocr_carea' id='block_", bcnt);
1088  hocr_str.add_str_int("_", bcnt);
1089  AddBoxTohOCR(res_it, RIL_BLOCK, &hocr_str);
1090  }
1091  if (res_it->IsAtBeginningOf(RIL_PARA)) {
1092  if (res_it->ParagraphIsLtr()) {
1093  hocr_str.add_str_int("\n <p class='ocr_par' dir='ltr' id='par_", pcnt);
1094  } else {
1095  hocr_str.add_str_int("\n <p class='ocr_par' dir='rtl' id='par_", pcnt);
1096  }
1097  AddBoxTohOCR(res_it, RIL_PARA, &hocr_str);
1098  }
1099  if (res_it->IsAtBeginningOf(RIL_TEXTLINE)) {
1100  hocr_str.add_str_int("\n <span class='ocr_line' id='line_", lcnt);
1101  AddBoxTohOCR(res_it, RIL_TEXTLINE, &hocr_str);
1102  }
1103 
1104  // Now, process the word...
1105  hocr_str.add_str_int("<span class='ocrx_word' id='word_", wcnt);
1106  AddBoxTohOCR(res_it, RIL_WORD, &hocr_str);
1107  const char *font_name;
1108  bool bold, italic, underlined, monospace, serif, smallcaps;
1109  int pointsize, font_id;
1110  font_name = res_it->WordFontAttributes(&bold, &italic, &underlined,
1111  &monospace, &serif, &smallcaps,
1112  &pointsize, &font_id);
1113  bool last_word_in_line = res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD);
1114  bool last_word_in_para = res_it->IsAtFinalElement(RIL_PARA, RIL_WORD);
1115  bool last_word_in_block = res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD);
1116  if (bold) hocr_str += "<strong>";
1117  if (italic) hocr_str += "<em>";
1118  do {
1119  const char *grapheme = res_it->GetUTF8Text(RIL_SYMBOL);
1120  if (grapheme && grapheme[0] != 0) {
1121  if (grapheme[1] == 0) {
1122  switch (grapheme[0]) {
1123  case '<': hocr_str += "&lt;"; break;
1124  case '>': hocr_str += "&gt;"; break;
1125  case '&': hocr_str += "&amp;"; break;
1126  case '"': hocr_str += "&quot;"; break;
1127  case '\'': hocr_str += "&#39;"; break;
1128  default: hocr_str += grapheme;
1129  }
1130  } else {
1131  hocr_str += grapheme;
1132  }
1133  }
1134  delete []grapheme;
1135  res_it->Next(RIL_SYMBOL);
1136  } while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
1137  if (italic) hocr_str += "</em>";
1138  if (bold) hocr_str += "</strong>";
1139  hocr_str += "</span> ";
1140  wcnt++;
1141  // Close any ending block/paragraph/textline.
1142  if (last_word_in_line) {
1143  hocr_str += "\n </span>";
1144  lcnt++;
1145  }
1146  if (last_word_in_para) {
1147  hocr_str += "\n </p>\n";
1148  pcnt++;
1149  }
1150  if (last_word_in_block) {
1151  hocr_str += " </div>\n";
1152  bcnt++;
1153  }
1154  }
1155  hocr_str += " </div>\n";
1156 
1157  char *ret = new char[hocr_str.length() + 1];
1158  strcpy(ret, hocr_str.string());
1159  delete res_it;
1160  return ret;
1161 }
STRING * input_file_
Name used by training code.
Definition: baseapi.h:768
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
void SetInputName(const char *name)
Definition: baseapi.cpp:138
#define NULL
Definition: host.h:144
void add_str_int(const char *str, int number)
Definition: strngs.cpp:334
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
Definition: strngs.h:40
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:696
ResultIterator * GetIterator()
Definition: baseapi.cpp:990
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 990 of file baseapi.cpp.

990  {
991  if (tesseract_ == NULL || page_res_ == NULL)
992  return NULL;
993  return ResultIterator::StartOfParagraph(LTRResultIterator(
997 }
static ResultIterator * StartOfParagraph(const LTRResultIterator &resit)
int GetScaledYResolution() const
Definition: thresholder.h:93
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
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 1007 of file baseapi.cpp.

1007  {
1008  if (tesseract_ == NULL || page_res_ == NULL)
1009  return NULL;
1010  return new MutableIterator(page_res_, tesseract_,
1014 }
int GetScaledYResolution() const
Definition: thresholder.h:93
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
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 494 of file baseapi.cpp.

494  {
495  return GetComponentImages(RIL_BLOCK, false, pixa, NULL);
496 }
#define NULL
Definition: host.h:144
Boxa * GetComponentImages(PageIteratorLevel level, bool text_only, Pixa **pixa, int **blockids)
Definition: baseapi.cpp:547
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 516 of file baseapi.cpp.

516  {
517  return GetComponentImages(RIL_TEXTLINE, false, pixa, blockids);
518 }
Boxa * GetComponentImages(PageIteratorLevel level, bool text_only, Pixa **pixa, int **blockids)
Definition: baseapi.cpp:547
bool tesseract::TessBaseAPI::GetTextDirection ( int *  out_offset,
float *  out_slope 
)

Definition at line 1531 of file baseapi.cpp.

1531  {
1532  if (page_res_ == NULL)
1533  FindLines();
1534  if (block_list_->length() < 1) {
1535  return false;
1536  }
1537 
1538  // Get first block
1539  BLOCK_IT block_it(block_list_);
1540  block_it.move_to_first();
1541  ROW_LIST* rows = block_it.data()->row_list();
1542  if (rows->length() < 1) {
1543  return false;
1544  }
1545 
1546  // Get first line of block
1547  ROW_IT row_it(rows);
1548  row_it.move_to_first();
1549  ROW* row = row_it.data();
1550 
1551  // Calculate offset and slope (NOTE: Kind of ugly)
1552  *out_offset = static_cast<int>(row->base_line(0.0));
1553  *out_slope = row->base_line(1.0) - row->base_line(0.0);
1554 
1555  return true;
1556 }
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:1636
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
#define NULL
Definition: host.h:144
float base_line(float xpos) const
Definition: ocrrow.h:56
Definition: ocrrow.h:32
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
Boxa * tesseract::TessBaseAPI::GetTextlines ( Pixa **  pixa,
int **  blockids 
)

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.

Definition at line 504 of file baseapi.cpp.

504  {
505  return GetComponentImages(RIL_TEXTLINE, true, pixa, blockids);
506 }
Boxa * GetComponentImages(PageIteratorLevel level, bool text_only, Pixa **pixa, int **blockids)
Definition: baseapi.cpp:547
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 if you have Leptonica installed. Get a copy of the internal thresholded image from Tesseract.

Definition at line 481 of file baseapi.cpp.

481  {
482  if (tesseract_ == NULL)
483  return NULL;
484  if (tesseract_->pix_binary() == NULL)
486  return pixClone(tesseract_->pix_binary());
487 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
virtual TESS_LOCAL void Threshold(Pix **pix)
Definition: baseapi.cpp:1603
Pix * pix_binary() const
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 596 of file baseapi.cpp.

596  {
597  if (thresholder_ == NULL) {
598  return 0;
599  }
600  return thresholder_->GetScaleFactor();
601 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
#define NULL
Definition: host.h:144
const char * tesseract::TessBaseAPI::GetUnichar ( int  unichar_id)

This method returns the string form of the specified unichar.

Definition at line 2186 of file baseapi.cpp.

2186  {
2187  return tesseract_->unicharset.id_to_unichar(unichar_id);
2188 }
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:233
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
UNICHARSET unicharset
Definition: ccutil.h:72
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 1248 of file baseapi.cpp.

1248  {
1249  if (tesseract_ == NULL ||
1250  (!recognition_done_ && Recognize(NULL) < 0))
1251  return NULL;
1252  bool tilde_crunch_written = false;
1253  bool last_char_was_newline = true;
1254  bool last_char_was_tilde = false;
1255 
1256  int total_length = TextLength(NULL);
1257  PAGE_RES_IT page_res_it(page_res_);
1258  char* result = new char[total_length];
1259  char* ptr = result;
1260  for (page_res_it.restart_page(); page_res_it.word () != NULL;
1261  page_res_it.forward()) {
1262  WERD_RES *word = page_res_it.word();
1263  // Process the current word.
1264  if (word->unlv_crunch_mode != CR_NONE) {
1265  if (word->unlv_crunch_mode != CR_DELETE &&
1266  (!tilde_crunch_written ||
1267  (word->unlv_crunch_mode == CR_KEEP_SPACE &&
1268  word->word->space() > 0 &&
1269  !word->word->flag(W_FUZZY_NON) &&
1270  !word->word->flag(W_FUZZY_SP)))) {
1271  if (!word->word->flag(W_BOL) &&
1272  word->word->space() > 0 &&
1273  !word->word->flag(W_FUZZY_NON) &&
1274  !word->word->flag(W_FUZZY_SP)) {
1275  /* Write a space to separate from preceeding good text */
1276  *ptr++ = ' ';
1277  last_char_was_tilde = false;
1278  }
1279  if (!last_char_was_tilde) {
1280  // Write a reject char.
1281  last_char_was_tilde = true;
1282  *ptr++ = kUNLVReject;
1283  tilde_crunch_written = true;
1284  last_char_was_newline = false;
1285  }
1286  }
1287  } else {
1288  // NORMAL PROCESSING of non tilde crunched words.
1289  tilde_crunch_written = false;
1291  const char* wordstr = word->best_choice->unichar_string().string();
1292  const STRING& lengths = word->best_choice->unichar_lengths();
1293  int length = lengths.length();
1294  int i = 0;
1295  int offset = 0;
1296 
1297  if (last_char_was_tilde &&
1298  word->word->space() == 0 && wordstr[offset] == ' ') {
1299  // Prevent adjacent tilde across words - we know that adjacent tildes
1300  // within words have been removed.
1301  // Skip the first character.
1302  offset = lengths[i++];
1303  }
1304  if (i < length && wordstr[offset] != 0) {
1305  if (!last_char_was_newline)
1306  *ptr++ = ' ';
1307  else
1308  last_char_was_newline = false;
1309  for (; i < length; offset += lengths[i++]) {
1310  if (wordstr[offset] == ' ' ||
1311  wordstr[offset] == kTesseractReject) {
1312  *ptr++ = kUNLVReject;
1313  last_char_was_tilde = true;
1314  } else {
1315  if (word->reject_map[i].rejected())
1316  *ptr++ = kUNLVSuspect;
1317  UNICHAR ch(wordstr + offset, lengths[i]);
1318  int uni_ch = ch.first_uni();
1319  for (int j = 0; kUniChs[j] != 0; ++j) {
1320  if (kUniChs[j] == uni_ch) {
1321  uni_ch = kLatinChs[j];
1322  break;
1323  }
1324  }
1325  if (uni_ch <= 0xff) {
1326  *ptr++ = static_cast<char>(uni_ch);
1327  last_char_was_tilde = false;
1328  } else {
1329  *ptr++ = kUNLVReject;
1330  last_char_was_tilde = true;
1331  }
1332  }
1333  }
1334  }
1335  }
1336  if (word->word->flag(W_EOL) && !last_char_was_newline) {
1337  /* Add a new line output */
1338  *ptr++ = '\n';
1339  tilde_crunch_written = false;
1340  last_char_was_newline = true;
1341  last_char_was_tilde = false;
1342  }
1343  }
1344  *ptr++ = '\n';
1345  *ptr = '\0';
1346  return result;
1347 }
const STRING & unichar_string() const
Definition: ratngs.h:395
const int kLatinChs[]
Definition: baseapi.cpp:1239
const int kUniChs[]
Definition: baseapi.cpp:1235
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
inT32 length() const
Definition: strngs.cpp:151
const char kUNLVSuspect
Definition: baseapi.cpp:83
REJMAP reject_map
Definition: pageres.h:408
#define NULL
Definition: host.h:144
uinT8 space()
Definition: werd.h:104
const char kTesseractReject
Definition: baseapi.cpp:79
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:122
WERD * word
Definition: pageres.h:334
void set_unlv_suspects(WERD_RES *word)
Definition: output.cpp:371
Definition: werd.h:35
const char * string() const
Definition: strngs.cpp:156
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:773
Definition: strngs.h:40
const STRING & unichar_lengths() const
Definition: ratngs.h:402
const char kUNLVReject
Definition: baseapi.cpp:81
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:696
TESS_LOCAL int TextLength(int *blob_count)
Definition: baseapi.cpp:1726
Definition: werd.h:36
CRUNCH_MODE unlv_crunch_mode
Definition: pageres.h:430
WERD_CHOICE * best_choice
Definition: pageres.h:359
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 1017 of file baseapi.cpp.

1017  {
1018  if (tesseract_ == NULL ||
1019  (!recognition_done_ && Recognize(NULL) < 0))
1020  return NULL;
1021  STRING text("");
1022  ResultIterator *it = GetIterator();
1023  do {
1024  if (it->Empty(RIL_PARA)) continue;
1025  char *para_text = it->GetUTF8Text(RIL_PARA);
1026  text += para_text;
1027  delete []para_text;
1028  } while (it->Next(RIL_PARA));
1029  char* result = new char[text.length() + 1];
1030  strncpy(result, text.string(), text.length() + 1);
1031  delete it;
1032  return result;
1033 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:773
Definition: strngs.h:40
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:696
ResultIterator * GetIterator()
Definition: baseapi.cpp:990
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 525 of file baseapi.cpp.

525  {
526  return GetComponentImages(RIL_WORD, true, pixa, NULL);
527 }
#define NULL
Definition: host.h:144
Boxa * GetComponentImages(PageIteratorLevel level, bool text_only, Pixa **pixa, int **blockids)
Definition: baseapi.cpp:547
void tesseract::TessBaseAPI::InitTruthCallback ( TruthCallback cb)
inline

Definition at line 661 of file baseapi.h.

661 { truth_cb_ = cb; }
TruthCallback * truth_cb_
Definition: baseapi.h:774
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 1526 of file baseapi.cpp.

1526  {
1527  return tesseract_->getDict().valid_word(word);
1528 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
Dict & getDict()
Definition: classify.h:62
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:807
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 1867 of file baseapi.cpp.

1867  {
1868  int width = pixGetWidth(pix);
1869  int height = pixGetHeight(pix);
1870  BLOCK block("a character", TRUE, 0, 0, 0, 0, width, height);
1871 
1872  // Create C_BLOBs from the page
1873  extract_edges(pix, &block);
1874 
1875  // Merge all C_BLOBs
1876  C_BLOB_LIST *list = block.blob_list();
1877  C_BLOB_IT c_blob_it(list);
1878  if (c_blob_it.empty())
1879  return NULL;
1880  // Move all the outlines to the first blob.
1881  C_OUTLINE_IT ol_it(c_blob_it.data()->out_list());
1882  for (c_blob_it.forward();
1883  !c_blob_it.at_first();
1884  c_blob_it.forward()) {
1885  C_BLOB *c_blob = c_blob_it.data();
1886  ol_it.add_list_after(c_blob->out_list());
1887  }
1888  // Convert the first blob to the output TBLOB.
1889  return TBLOB::PolygonalCopy(c_blob_it.data());
1890 }
void extract_edges(Pix *pix, BLOCK *block)
Definition: edgblob.cpp:335
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:42
#define NULL
Definition: host.h:144
Definition: ocrblock.h:31
static TBLOB * PolygonalCopy(C_BLOB *src)
Definition: blobs.cpp:269
#define TRUE
Definition: capi.h:27
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 1850 of file baseapi.cpp.

1853  {
1854  inT32 xstarts[] = {-32000};
1855  double quad_coeffs[] = {0, 0, baseline};
1856  return new ROW(1,
1857  xstarts,
1858  quad_coeffs,
1859  xheight,
1860  ascender - (baseline + xheight),
1861  descender - baseline,
1862  0,
1863  0);
1864 }
int inT32
Definition: host.h:102
Definition: ocrrow.h:32
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 1350 of file baseapi.cpp.

1350  {
1351  int* conf = AllWordConfidences();
1352  if (!conf) return 0;
1353  int sum = 0;
1354  int *pt = conf;
1355  while (*pt >= 0) sum += *pt++;
1356  if (pt != conf) sum /= pt - conf;
1357  delete [] conf;
1358  return sum;
1359 }
void tesseract::TessBaseAPI::NormalizeTBLOB ( TBLOB tblob,
ROW row,
bool  numeric_mode,
DENORM denorm 
)
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 1897 of file baseapi.cpp.

1898  {
1899  TWERD word;
1900  word.blobs = tblob;
1901  if (denorm != NULL) {
1902  word.SetupBLNormalize(NULL, row, row->x_height(), numeric_mode, denorm);
1903  word.Normalize(*denorm);
1904  } else {
1905  DENORM normer;
1906  word.SetupBLNormalize(NULL, row, row->x_height(), numeric_mode, &normer);
1907  word.Normalize(normer);
1908  }
1909  word.blobs = NULL;
1910 }
void SetupBLNormalize(const BLOCK *block, const ROW *row, float x_height, bool numeric_mode, DENORM *denorm) const
Definition: blobs.cpp:424
#define NULL
Definition: host.h:144
Definition: blobs.h:233
TBLOB * blobs
Definition: blobs.h:274
void Normalize(const DENORM &denorm)
Definition: blobs.cpp:447
float x_height() const
Definition: ocrrow.h:61
int tesseract::TessBaseAPI::NumDawgs ( ) const

Return the number of dawgs loaded into tesseract_ object.

Definition at line 2197 of file baseapi.cpp.

2197  {
2198  return tesseract_ == NULL ? 0 : tesseract_->getDict().NumDawgs();
2199 }
const int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
Definition: dict.h:603
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
Dict & getDict()
Definition: classify.h:62
OcrEngineMode const tesseract::TessBaseAPI::oem ( ) const
inline

Definition at line 657 of file baseapi.h.

657  {
658  return last_oem_requested_;
659  }
OcrEngineMode last_oem_requested_
Last ocr language mode requested.
Definition: baseapi.h:772
bool tesseract::TessBaseAPI::ProcessPage ( Pix *  pix,
int  page_index,
const char *  filename,
const char *  retry_config,
int  timeout_millisec,
STRING text_out 
)

Recognizes a single page for ProcessPages, appending the text to text_out. 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. If non-zero timeout_millisec terminates processing after the timeout. If non-NULL and non-empty, and some page fails for some reason, the page is reprocessed with the retry_config config file. Useful for interactively debugging a bad page. The text is returned in text_out. Returns false on error.

Definition at line 905 of file baseapi.cpp.

907  {
909  SetImage(pix);
910  bool failed = false;
911  if (timeout_millisec > 0) {
912  // Running with a timeout.
913  ETEXT_DESC monitor;
914  monitor.cancel = NULL;
915  monitor.cancel_this = NULL;
916  monitor.set_deadline_msecs(timeout_millisec);
917  // Now run the main recognition.
918  failed = Recognize(&monitor) < 0;
921  // Disabled character recognition.
922  PageIterator* it = AnalyseLayout();
923  if (it == NULL) {
924  failed = true;
925  } else {
926  delete it;
927  return true;
928  }
929  } else {
930  // Normal layout and character recognition with no timeout.
931  failed = Recognize(NULL) < 0;
932  }
934  Pix* page_pix = GetThresholdedImage();
935  pixWrite("tessinput.tif", page_pix, IFF_TIFF_G4);
936  }
937  if (failed && retry_config != NULL && retry_config[0] != '\0') {
938  // Save current config variables before switching modes.
939  FILE* fp = fopen(kOldVarsFile, "wb");
940  PrintVariables(fp);
941  fclose(fp);
942  // Switch to alternate mode for retry.
943  ReadConfigFile(retry_config);
944  SetImage(pix);
945  Recognize(NULL);
946  // Restore saved config variables.
948  }
949  // Get text only if successful.
950  if (!failed) {
951  char* text;
954  text = GetBoxText(page_index);
955  } else if (tesseract_->tessedit_write_unlv) {
956  text = GetUNLVText();
957  } else if (tesseract_->tessedit_create_hocr) {
958  text = GetHOCRText(page_index);
959  } else {
960  text = GetUTF8Text();
961  }
962  *text_out += text;
963  delete [] text;
964  return true;
965  }
966  return false;
967 }
PageIterator * AnalyseLayout()
Definition: baseapi.cpp:678
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
const char * kOldVarsFile
Definition: baseapi.cpp:90
void SetInputName(const char *name)
Definition: baseapi.cpp:138
CANCEL_FUNC cancel
Definition: ocrclass.h:119
#define NULL
Definition: host.h:144
void * cancel_this
Definition: ocrclass.h:120
char * GetHOCRText(int page_number)
Definition: baseapi.cpp:1055
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:435
Automatic page segmentation, but no OSD, or OCR.
Definition: publictypes.h:151
char * GetBoxText(int page_number)
Definition: baseapi.cpp:1193
Orientation and script detection only.
Definition: publictypes.h:148
void set_deadline_msecs(inT32 deadline_msecs)
Definition: ocrclass.h:132
void ReadConfigFile(const char *filename)
Definition: baseapi.cpp:356
int Recognize(ETEXT_DESC *monitor)
Definition: baseapi.cpp:696
void PrintVariables(FILE *fp) const
Definition: baseapi.cpp:201
Pix * GetThresholdedImage()
Definition: baseapi.cpp:481
bool tesseract::TessBaseAPI::ProcessPages ( const char *  filename,
const char *  retry_config,
int  timeout_millisec,
STRING text_out 
)

Recognizes all the pages in the named file, as a multi-page tiff or list of filenames, or single image, and gets the appropriate kind of text according to parameters: tessedit_create_boxfile, tessedit_make_boxes_from_boxes, tessedit_write_unlv, tessedit_create_hocr. Calls ProcessPage on each page in the input file, which may be a multi-page tiff, single-page other file format, or a plain text list of images to read. If tessedit_page_number is non-negative, processing begins at that page of a multi-page tiff file, or filelist. The text is returned in text_out. Returns false on error. If non-zero timeout_millisec terminates processing after the timeout on a single page. If non-NULL and non-empty, and some page fails for some reason, the page is reprocessed with the retry_config config file. Useful for interactively debugging a bad page.

Definition at line 803 of file baseapi.cpp.

805  {
806  int page = tesseract_->tessedit_page_number;
807  if (page < 0)
808  page = 0;
809  FILE* fp = fopen(filename, "rb");
810  if (fp == NULL) {
811  tprintf(_("Image file %s cannot be opened!\n"), filename);
812  return false;
813  }
814  // Find the number of pages if a tiff file, or zero otherwise.
815  int npages = CountTiffPages(fp);
816  fclose(fp);
817 
819  *text_out =
820  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
821  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
822  " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
823  "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" "
824  "lang=\"en\">\n <head>\n <title></title>\n"
825  " <meta http-equiv=\"Content-Type\" content=\"text/html; "
826  "charset=utf-8\" />\n"
827  " <meta name='ocr-system' content='tesseract " VERSION "' />\n"
828  " <meta name='ocr-capabilities' content='ocr_page ocr_carea ocr_par"
829  " ocr_line ocrx_word'/>\n"
830  " </head>\n <body>\n";
831  } else {
832  *text_out = "";
833  }
834 
835  bool success = true;
836  Pix *pix;
837  if (npages > 0) {
838  for (; page < npages && (pix = pixReadTiff(filename, page)) != NULL;
839  ++page) {
840  if ((page >= 0) && (npages > 1))
841  tprintf(_("Page %d of %d\n"), page + 1, npages);
842  char page_str[kMaxIntSize];
843  snprintf(page_str, kMaxIntSize - 1, "%d", page);
844  SetVariable("applybox_page", page_str);
845  success &= ProcessPage(pix, page, filename, retry_config,
846  timeout_millisec, text_out);
847  pixDestroy(&pix);
848  if (tesseract_->tessedit_page_number >= 0 || npages == 1) {
849  break;
850  }
851  }
852  } else {
853  // The file is not a tiff file, so use the general pixRead function.
854  pix = pixRead(filename);
855  if (pix != NULL) {
856  success &= ProcessPage(pix, 0, filename, retry_config,
857  timeout_millisec, text_out);
858  pixDestroy(&pix);
859  } else {
860  // The file is not an image file, so try it as a list of filenames.
861  FILE* fimg = fopen(filename, "rb");
862  if (fimg == NULL) {
863  tprintf(_("File %s cannot be opened!\n"), filename);
864  return false;
865  }
866  tprintf(_("Reading %s as a list of filenames...\n"), filename);
867  char pagename[MAX_PATH];
868  // Skip to the requested page number.
869  for (int i = 0; i < page &&
870  fgets(pagename, sizeof(pagename), fimg) != NULL;
871  ++i);
872  while (fgets(pagename, sizeof(pagename), fimg) != NULL) {
873  chomp_string(pagename);
874  pix = pixRead(pagename);
875  if (pix == NULL) {
876  tprintf(_("Image file %s cannot be read!\n"), pagename);
877  fclose(fimg);
878  return false;
879  }
880  tprintf(_("Page %d : %s\n"), page, pagename);
881  success &= ProcessPage(pix, page, pagename, retry_config,
882  timeout_millisec, text_out);
883  pixDestroy(&pix);
884  ++page;
885  }
886  fclose(fimg);
887  }
888  }
890  *text_out += " </body>\n</html>\n";
891  return success;
892 }
#define MAX_PATH
Definition: platform.h:41
const int kMaxIntSize
Definition: baseapi.cpp:92
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
#define VERSION
Definition: config_auto.h:168
int CountTiffPages(FILE *fp)
Definition: imgtiff.cpp:80
void chomp_string(char *str)
Definition: helpers.h:32
bool ProcessPage(Pix *pix, int page_index, const char *filename, const char *retry_config, int timeout_millisec, STRING *text_out)
Definition: baseapi.cpp:905
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
#define _(x)
Definition: baseapi.cpp:32
bool SetVariable(const char *name, const char *value)
Definition: baseapi.cpp:153
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 696 of file baseapi.cpp.

696  {
697  if (tesseract_ == NULL)
698  return -1;
699  if (FindLines() != 0)
700  return -1;
701  if (page_res_ != NULL)
702  delete page_res_;
703  if (block_list_->empty()) {
705  return 0; // Empty page.
706  }
707 
709  recognition_done_ = true;
714  else
718  return 0;
719  }
720 
721  if (truth_cb_ != NULL) {
722  tesseract_->wordrec_run_blamer.set_value(true);
725  }
726 
727  int result = 0;
729  #ifndef GRAPHICS_DISABLED
731  #endif // GRAPHICS_DISABLED
732  // The page_res is invalid after an interactive session, so cleanup
733  // in a way that lets us continue to the next page without crashing.
734  delete page_res_;
735  page_res_ = NULL;
736  return -1;
739  } else if (tesseract_->tessedit_ambigs_training) {
740  FILE *training_output_file = tesseract_->init_recog_training(*input_file_);
741  // OCR the page segmented into words by tesseract.
743  *input_file_, page_res_, monitor, training_output_file);
744  fclose(training_output_file);
745  } else {
746  // Now run the main recognition.
747  if (tesseract_->recog_all_words(page_res_, monitor, NULL, NULL, 0)) {
748  DetectParagraphs(true);
749  } else {
750  result = -1;
751  }
752  }
753  return result;
754 }
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:178
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:1636
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
STRING * input_file_
Name used by training code.
Definition: baseapi.h:768
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
PAGE_RES * ApplyBoxes(const STRING &fname, bool find_segmentation, BLOCK_LIST *block_list)
Definition: applybox.cpp:111
#define NULL
Definition: host.h:144
const UNICHARSET & getUnicharset() const
Definition: dict.h:100
bool tessedit_resegment_from_line_boxes
void recog_training_segmented(const STRING &fname, PAGE_RES *page_res, volatile ETEXT_DESC *monitor, FILE *output_file)
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:506
STRING * output_file_
Name used by debug code.
Definition: baseapi.h:769
Dict & getDict()
Definition: classify.h:62
bool wordrec_run_blamer
Definition: wordrec.h:143
TruthCallback * truth_cb_
Definition: baseapi.h:774
FILE * init_recog_training(const STRING &fname)
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:773
void CorrectClassifyWords(PAGE_RES *page_res)
Definition: applybox.cpp:764
void ApplyBoxTraining(const STRING &filename, PAGE_RES *page_res)
Definition: applybox.cpp:786
TESS_LOCAL void DetectParagraphs(bool after_text_recognition)
Definition: baseapi.cpp:1987
void pgeditor_main(int width, int height, PAGE_RES *page_res)
Definition: pgedit.cpp:336
virtual void Run(A1, A2, A3)=0
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 757 of file baseapi.cpp.

757  {
758  if (tesseract_ == NULL)
759  return -1;
760  if (thresholder_ == NULL || thresholder_->IsEmpty()) {
761  tprintf("Please call SetImage before attempting recognition.");
762  return -1;
763  }
764  if (page_res_ != NULL)
765  ClearResults();
766  if (FindLines() != 0)
767  return -1;
768  // Additional conditions under which chopper test cannot be run
769  if (tesseract_->interactive_display_mode) return -1;
770 
771  recognition_done_ = true;
772 
774 
775  PAGE_RES_IT page_res_it(page_res_);
776 
777  while (page_res_it.word() != NULL) {
778  WERD_RES *word_res = page_res_it.word();
779  GenericVector<TBOX> boxes;
780  tesseract_->MaximallyChopWord(boxes, page_res_it.block()->block,
781  page_res_it.row()->row, word_res);
782  page_res_it.forward();
783  }
784  return 0;
785 }
TESS_LOCAL int FindLines()
Definition: baseapi.cpp:1636
BLOCK_LIST * block_list_
The page layout.
Definition: baseapi.h:766
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
void MaximallyChopWord(const GenericVector< TBOX > &boxes, BLOCK *block, ROW *row, WERD_RES *word_res)
Definition: applybox.cpp:257
bool IsEmpty() const
Return true if no image has been set.
Definition: thresholder.cpp:54
WERD_CHOICE * prev_word_best_choice_
Definition: wordrec.h:506
WERD * word
Definition: pageres.h:334
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
PAGE_RES * page_res_
The page-level data.
Definition: baseapi.h:767
bool recognition_done_
page_res_ contains recognition data.
Definition: baseapi.h:773
TESS_LOCAL void ClearResults()
Definition: baseapi.cpp:1699
void tesseract::TessBaseAPI::RunAdaptiveClassifier ( TBLOB blob,
const DENORM denorm,
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 2163 of file baseapi.cpp.

2167  {
2168  BLOB_CHOICE_LIST* choices = new BLOB_CHOICE_LIST;
2169  tesseract_->AdaptiveClassifier(blob, denorm, choices, NULL);
2170  BLOB_CHOICE_IT choices_it(choices);
2171  int& index = *num_matches_returned;
2172  index = 0;
2173  for (choices_it.mark_cycle_pt();
2174  !choices_it.cycled_list() && index < num_max_matches;
2175  choices_it.forward()) {
2176  BLOB_CHOICE* choice = choices_it.data();
2177  unichar_ids[index] = choice->unichar_id();
2178  ratings[index] = choice->rating();
2179  ++index;
2180  }
2181  *num_matches_returned = index;
2182  delete choices;
2183 }
void AdaptiveClassifier(TBLOB *Blob, const DENORM &denorm, BLOB_CHOICE_LIST *Choices, CLASS_PRUNER_RESULTS cp_results)
Definition: adaptmatch.cpp:178
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
UNICHAR_ID unichar_id() const
Definition: ratngs.h:59
float rating() const
Definition: ratngs.h:62
void tesseract::TessBaseAPI::set_min_orientation_margin ( double  margin)

Definition at line 1767 of file baseapi.cpp.

1767  {
1768  tesseract_->min_orientation_margin.set_value(margin);
1769 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
void tesseract::TessBaseAPI::SetDictFunc ( DictFunc  f)

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

Definition at line 1559 of file baseapi.cpp.

1559  {
1560  if (tesseract_ != NULL) {
1562  }
1563 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
Dict & getDict()
Definition: classify.h:62
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.h:560
void tesseract::TessBaseAPI::SetFillLatticeFunc ( FillLatticeFunc  f)

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

Definition at line 1581 of file baseapi.cpp.

1581  {
1583 }
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
void(Wordrec::* fill_lattice_)(const MATRIX &ratings, const LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
Definition: wordrec.h:510
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. Does not copy the image buffer, or take ownership. The source image may be destroyed after Recognize is called, either explicitly or implicitly via one of the Get*Text functions. 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 435 of file baseapi.cpp.

437  {
438  if (InternalSetImage())
439  thresholder_->SetImage(imagedata, width, height,
440  bytes_per_pixel, bytes_per_line);
441 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: thresholder.cpp:70
TESS_LOCAL bool InternalSetImage()
Definition: baseapi.cpp:1586
void tesseract::TessBaseAPI::SetImage ( const Pix *  pix)

Provide an image for Tesseract to recognize. As with SetImage above, Tesseract doesn't take a copy or ownership or pixDestroy the image, so it must persist until after Recognize. Pix vs raw, which to use? Use Pix where possible. A future version of Tesseract may choose to use Pix as its internal representation and discard IMAGE altogether. Because of that, an implementation that sources and targets Pix may end up with less copies than an implementation that does not.

Definition at line 460 of file baseapi.cpp.

460  {
461  if (InternalSetImage())
462  thresholder_->SetImage(pix);
463 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: thresholder.cpp:70
TESS_LOCAL bool InternalSetImage()
Definition: baseapi.cpp:1586
void tesseract::TessBaseAPI::SetProbabilityInContextFunc ( ProbabilityInContextFunc  f)

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

Definition at line 1569 of file baseapi.cpp.

1569  {
1570  if (tesseract_ != NULL) {
1572  // Set it for the sublangs too.
1573  int num_subs = tesseract_->num_sub_langs();
1574  for (int i = 0; i < num_subs; ++i) {
1576  }
1577  }
1578 }
int num_sub_langs() const
Tesseract * tesseract_
The underlying data object.
Definition: baseapi.h:757
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
Dict & getDict()
Definition: classify.h:62
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:570
Tesseract * get_sub_lang(int index) const
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 470 of file baseapi.cpp.

470  {
471  if (thresholder_ == NULL)
472  return;
473  thresholder_->SetRectangle(left, top, width, height);
474  ClearResults();
475 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
#define NULL
Definition: host.h:144
void SetRectangle(int left, int top, int width, int height)
Definition: thresholder.cpp:88
TESS_LOCAL void ClearResults()
Definition: baseapi.cpp:1699
size_t top
Definition: tessarray.h:52
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 443 of file baseapi.cpp.

443  {
444  if (thresholder_)
446  else
447  tprintf("Please call SetImage before SetSourceResolution.\n");
448 }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
void SetSourceYResolution(int ppi)
Definition: thresholder.h:86
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
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 348 of file baseapi.h.

348  {
349  if (thresholder_ != NULL)
350  delete thresholder_;
351  thresholder_ = thresholder;
352  ClearResults();
353  }
ImageThresholder * thresholder_
Image thresholding module.
Definition: baseapi.h:764
#define NULL
Definition: host.h:144
TESS_LOCAL void ClearResults()
Definition: baseapi.cpp:1699
Tesseract* const tesseract::TessBaseAPI::tesseract ( ) const
inline

Definition at line 653 of file baseapi.h.

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