Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract Namespace Reference

Classes

struct  TESS_CHAR
 
class  TessBaseAPI
 
class  CubeRecoContext
 
class  CubeClassifier
 
class  CubeTessClassifier
 
struct  DocQualCallbacks
 
class  EquationDetect
 
class  LTRResultIterator
 
class  ChoiceIterator
 
class  MutableIterator
 
class  PageIterator
 
class  UnicodeSpanSkipper
 
struct  Cluster
 
class  SimpleClusterer
 
struct  GeometricClassifierState
 
struct  Interval
 
class  RowInfo
 
struct  LineHypothesis
 
class  RowScratchRegisters
 
class  ParagraphTheory
 
class  ParagraphModelSmearer
 
class  ResultIterator
 
class  TesseractCubeCombiner
 
struct  TesseractStats
 
class  Tesseract
 
class  ImageThresholder
 
class  BoxWord
 
class  CCStruct
 
class  DetLineFit
 
class  DPPoint
 
struct  FontSpacingInfo
 
struct  FontInfo
 
struct  FontSet
 
struct  ParamsTrainingHypothesis
 
class  ParamsTrainingBundle
 
class  UnicharIdArrayUtils
 
class  AmbigSpec
 
class  UnicharAmbigs
 
class  BitVector
 
class  CCUtilMutex
 
class  CCUtil
 
class  PointerVector
 
class  IndexMap
 
class  IndexMapBiDi
 
struct  ParamsVectors
 
class  ParamUtils
 
class  Param
 
class  IntParam
 
class  BoolParam
 
class  StringParam
 
class  DoubleParam
 
class  TessdataManager
 
class  Classify
 
class  ErrorCounter
 
class  IntFeatureDist
 
class  IntFeatureMap
 
class  IntFeatureSpace
 
class  ClassPruner
 
struct  ShapeDist
 
class  MasterTrainer
 
class  SampleIterator
 
struct  ShapeRating
 
class  ShapeClassifier
 
struct  UnicharAndFonts
 
class  Shape
 
class  ShapeTable
 
class  TessClassifier
 
class  TrainingSample
 
class  TrainingSampleSet
 
class  AltList
 
class  BeamSearch
 
class  Bmp8
 
class  CachedFile
 
class  CharAltList
 
struct  Bigram
 
struct  CharBigram
 
struct  CharBigramTable
 
class  CharBigrams
 
class  CharSamp
 
class  CharSampEnum
 
class  CharSampSet
 
class  CharSet
 
class  CharClassifier
 
class  CharClassifierFactory
 
class  ConCompPt
 
class  ConComp
 
class  ConvNetCharClassifier
 
class  CubeLineObject
 
class  CubeLineSegmenter
 
class  CubeObject
 
class  CubeSearchObject
 
class  CubeTuningParams
 
class  CubeUtils
 
class  FeatureBase
 
class  FeatureBmp
 
class  FeatureChebyshev
 
class  FeatureHybrid
 
class  HybridNeuralNetCharClassifier
 
class  LangModEdge
 
class  LangModel
 
class  SearchColumn
 
class  SearchNode
 
class  SearchNodeHashTable
 
class  SearchObject
 
class  TessLangModEdge
 
class  TessLangModel
 
class  TuningParams
 
class  WordAltList
 
class  WordListLangModel
 
struct  PairSizeInfo
 
struct  FontPairSizeInfo
 
class  WordSizeModel
 
class  WordUnigrams
 
class  CUtil
 
struct  NodeChild
 
class  Dawg
 
struct  DawgInfo
 
class  DawgInfoVector
 
class  SquishedDawg
 
struct  DawgArgs
 
class  Dict
 
class  PermuterState
 
class  Trie
 
class  Image
 
class  InputFileBuffer
 
class  NeuralNet
 
class  Neuron
 
struct  AlignedBlobParams
 
class  AlignedBlob
 
class  GridSearch
 
class  GridBase
 
class  IntGrid
 
class  BBGrid
 
class  TabEventHandler
 
class  BlobGrid
 
class  CCNonTextDetect
 
class  ColumnFinder
 
class  ColPartition
 
class  ColPartitionGrid
 
class  ColPartitionSet
 
class  PixelHistogram
 
class  ShiroRekhaSplitter
 
class  EquationDetectBase
 
class  ImageFind
 
class  LineFinder
 
class  StrokeWidth
 
class  TabFind
 
class  ColSegment
 
class  TableFinder
 
class  StructuredTable
 
class  TableRecognizer
 
class  TabConstraint
 
class  TabVector
 
class  TextlineProjection
 
class  Textord
 
class  WorkingPartSet
 
struct  AssociateStats
 
class  AssociateUtils
 
struct  LanguageModelConsistencyInfo
 
struct  LanguageModelDawgInfo
 
struct  LanguageModelNgramInfo
 
struct  ViterbiStateEntry
 
struct  LanguageModelState
 
struct  BestChoiceBundle
 
struct  BestPathByColumn
 
class  LanguageModel
 
struct  MATCH
 
class  BlobMatchTable
 
class  FRAGMENT
 
class  Wordrec
 

Typedefs

typedef int(Dict::* DictFunc )(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
 
typedef double(Dict::* ProbabilityInContextFunc )(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
 
typedef void(Wordrec::* FillLatticeFunc )(const MATRIX &ratings, const LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
 
typedef TessCallback3< const
UNICHARSET &, int, PAGE_RES * > 
TruthCallback
 
typedef GenericVectorEqEq
< const ParagraphModel * > 
SetOfModels
 
typedef void(Tesseract::* WordRecognizer )(BLOCK *block, ROW *row, WERD_RES *word)
 
typedef GenericVector
< ParamsTrainingHypothesis
ParamsTrainingHypothesisList
 
typedef GenericVector< UNICHAR_IDUnicharIdVector
 
typedef GenericVector
< AmbigSpec_LIST * > 
UnicharAmbigsVector
 
typedef signed int char_32
 
typedef basic_string< char_32string_32
 
typedef GenericVector< NodeChildNodeChildVector
 
typedef GenericVector< int > SuccessorList
 
typedef GenericVector
< SuccessorList * > 
SuccessorListsVector
 
typedef GenericVector< Dawg * > DawgVector
 
typedef GridSearch< BLOBNBOX,
BLOBNBOX_CLIST, BLOBNBOX_C_IT > 
BlobGridSearch
 
typedef GridSearch
< ColPartition,
ColPartition_CLIST,
ColPartition_C_IT > 
ColPartitionGridSearch
 
typedef GenericVector
< ColPartitionSet * > 
PartSetVector
 
typedef TessResultCallback1
< bool, int > 
WidthCallback
 
typedef BBGrid< ColSegment,
ColSegment_CLIST,
ColSegment_C_IT > 
ColSegmentGrid
 
typedef GridSearch< ColSegment,
ColSegment_CLIST,
ColSegment_C_IT > 
ColSegmentGridSearch
 
typedef unsigned char LanguageModelFlagsType
 

Enumerations

enum  LineType { LT_START = 'S', LT_BODY = 'C', LT_UNKNOWN = 'U', LT_MULTIPLE = 'M' }
 
enum  CMD_EVENTS { ACTION_1_CMD_EVENT, RECOG_WERDS, RECOG_PSEUDO, ACTION_2_CMD_EVENT }
 
enum  ScriptPos { SP_NORMAL, SP_SUBSCRIPT, SP_SUPERSCRIPT, SP_DROPCAP }
 
enum  NormalizationMode { NM_BASELINE = -3, NM_CHAR_ISOTROPIC = -2, NM_CHAR_ANISOTROPIC = -1 }
 
enum  ParamsTrainingRawFeatureType {
  PTRAIN_RAW_FEATURE_DICT_MATCH_TYPE, PTRAIN_RAW_FEATURE_UNAMBIG_DICT_MATCH, PTRAIN_RAW_FEATURE_SHAPE_COST, PTRAIN_RAW_FEATURE_NGRAM_PROB,
  PTRAIN_RAW_FEATURE_NUM_BAD_PUNC, PTRAIN_RAW_FEATURE_NUM_BAD_CASE, PTRAIN_RAW_FEATURE_NUM_BAD_CHAR_TYPE, PTRAIN_RAW_FEATURE_NUM_BAD_SPACING,
  PTRAIN_RAW_FEATURE_NUM_BAD_SCRIPT, PTRAIN_RAW_FEATURE_NUM_BAD_FONT, PTRAIN_RAW_FEATURE_WORST_CERT, PTRAIN_RAW_FEATURE_RATING,
  PTRAIN_RAW_FEATURE_ADAPTED, PTRAIN_RAW_FEATURE_NUM_UNICHARS, PTRAIN_RAW_FEATURE_OUTLINE_LEN, PTRAIN_NUM_RAW_FEATURE_TYPES
}
 
enum  Orientation { ORIENTATION_PAGE_UP = 0, ORIENTATION_PAGE_RIGHT = 1, ORIENTATION_PAGE_DOWN = 2, ORIENTATION_PAGE_LEFT = 3 }
 
enum  WritingDirection { WRITING_DIRECTION_LEFT_TO_RIGHT = 0, WRITING_DIRECTION_RIGHT_TO_LEFT = 1, WRITING_DIRECTION_TOP_TO_BOTTOM = 2 }
 
enum  TextlineOrder { TEXTLINE_ORDER_LEFT_TO_RIGHT = 0, TEXTLINE_ORDER_RIGHT_TO_LEFT = 1, TEXTLINE_ORDER_TOP_TO_BOTTOM = 2 }
 
enum  PageSegMode {
  PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO,
  PSM_SINGLE_COLUMN, PSM_SINGLE_BLOCK_VERT_TEXT, PSM_SINGLE_BLOCK, PSM_SINGLE_LINE,
  PSM_SINGLE_WORD, PSM_CIRCLE_WORD, PSM_SINGLE_CHAR, PSM_COUNT
}
 
enum  PageIteratorLevel {
  RIL_BLOCK, RIL_PARA, RIL_TEXTLINE, RIL_WORD,
  RIL_SYMBOL
}
 
enum  ParagraphJustification { JUSTIFICATION_UNKNOWN, JUSTIFICATION_LEFT, JUSTIFICATION_CENTER, JUSTIFICATION_RIGHT }
 
enum  OcrEngineMode { OEM_TESSERACT_ONLY, OEM_CUBE_ONLY, OEM_TESSERACT_CUBE_COMBINED, OEM_DEFAULT }
 
enum  AmbigType {
  NOT_AMBIG, REPLACE_AMBIG, DEFINITE_AMBIG, SIMILAR_AMBIG,
  CASE_AMBIG, AMBIG_TYPE_COUNT
}
 
enum  SetParamConstraint { SET_PARAM_CONSTRAINT_NONE, SET_PARAM_CONSTRAINT_DEBUG_ONLY, SET_PARAM_CONSTRAINT_NON_DEBUG_ONLY, SET_PARAM_CONSTRAINT_NON_INIT_ONLY }
 
enum  TessdataType {
  TESSDATA_LANG_CONFIG, TESSDATA_UNICHARSET, TESSDATA_AMBIGS, TESSDATA_INTTEMP,
  TESSDATA_PFFMTABLE, TESSDATA_NORMPROTO, TESSDATA_PUNC_DAWG, TESSDATA_SYSTEM_DAWG,
  TESSDATA_NUMBER_DAWG, TESSDATA_FREQ_DAWG, TESSDATA_FIXED_LENGTH_DAWGS, TESSDATA_CUBE_UNICHARSET,
  TESSDATA_CUBE_SYSTEM_DAWG, TESSDATA_SHAPE_TABLE, TESSDATA_BIGRAM_DAWG, TESSDATA_UNAMBIG_DAWG,
  TESSDATA_PARAMS_TRAINING_MODEL, TESSDATA_NUM_ENTRIES
}
 
enum  CharSegmentationType { CST_FRAGMENT, CST_WHOLE, CST_IMPROPER, CST_NGRAM }
 
enum  CountTypes {
  CT_SHAPE_TOP_CORRECT, CT_SHAPE_TOP_ERR, CT_FONT_ATTR_ERR, CT_UNICHAR_TOP1_ERR,
  CT_UNICHAR_TOP2_ERR, CT_UNICHAR_TOPN_ERR, CT_OK_MULTI_UNICHAR, CT_REJECT,
  CT_NUM_RESULTS, CT_RANK, CT_REJECTED_JUNK, CT_ACCEPTED_JUNK,
  CT_SIZE
}
 
enum  DawgType {
  DAWG_TYPE_PUNCTUATION, DAWG_TYPE_WORD, DAWG_TYPE_NUMBER, DAWG_TYPE_PATTERN,
  DAWG_TYPE_COUNT
}
 
enum  ColumnSpanningType {
  CST_NOISE, CST_FLOWING, CST_HEADING, CST_PULLOUT,
  CST_COUNT
}
 
enum  NeighbourPartitionType {
  NPT_HTEXT, NPT_VTEXT, NPT_WEAK_HTEXT, NPT_WEAK_VTEXT,
  NPT_IMAGE, NPT_COUNT
}
 
enum  LeftOrRight { LR_LEFT, LR_RIGHT }
 
enum  ColSegType {
  COL_UNKNOWN, COL_TEXT, COL_TABLE, COL_MIXED,
  COL_COUNT
}
 
enum  TabAlignment {
  TA_LEFT_ALIGNED, TA_LEFT_RAGGED, TA_CENTER_JUSTIFIED, TA_RIGHT_ALIGNED,
  TA_RIGHT_RAGGED, TA_SEPARATOR, TA_COUNT
}
 

Functions

int CubeAPITest (Boxa *boxa_blocks, Pixa *pixa_blocks, Boxa *boxa_words, Pixa *pixa_words, const FCOORD &reskew, Pix *page_pix, PAGE_RES *page_res)
 
TBLOBmake_tesseract_blob (float baseline, float xheight, float descender, float ascender, bool numeric_mode, Pix *pix)
 
TBOX char_box_to_tbox (Box *char_box, TBOX word_box, int x_offset)
 
bool IsTextOrEquationType (PolyBlockType type)
 
bool IsLeftIndented (const EquationDetect::IndentType type)
 
bool IsRightIndented (const EquationDetect::IndentType type)
 
template<typename T >
void SimpleSwap (T &a, T &b)
 
STRING RtlEmbed (const STRING &word, bool rtlify)
 
bool IsLatinLetter (int ch)
 
bool IsDigitLike (int ch)
 
bool IsOpeningPunct (int ch)
 
bool IsTerminalPunct (int ch)
 
const char * SkipChars (const char *str, const char *toskip)
 
const char * SkipChars (const char *str, bool(*skip)(int))
 
const char * SkipOne (const char *str, const char *toskip)
 
bool LikelyListNumeral (const STRING &word)
 
bool LikelyListMark (const STRING &word)
 
bool AsciiLikelyListItem (const STRING &word)
 
int UnicodeFor (const UNICHARSET *u, const WERD_CHOICE *werd, int pos)
 
bool LikelyListMarkUnicode (int ch)
 
bool UniLikelyListItem (const UNICHARSET *u, const WERD_CHOICE *werd)
 
void LeftWordAttributes (const UNICHARSET *unicharset, const WERD_CHOICE *werd, const STRING &utf8, bool *is_list, bool *starts_idea, bool *ends_idea)
 
void RightWordAttributes (const UNICHARSET *unicharset, const WERD_CHOICE *werd, const STRING &utf8, bool *is_list, bool *starts_idea, bool *ends_idea)
 
int ClosestCluster (const GenericVector< Cluster > &clusters, int value)
 
void CalculateTabStops (GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, int tolerance, GenericVector< Cluster > *left_tabs, GenericVector< Cluster > *right_tabs)
 
void MarkRowsWithModel (GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, const ParagraphModel *model, bool ltr, int eop_threshold)
 
void GeometricClassifyThreeTabStopTextBlock (int debug_level, GeometricClassifierState &s, ParagraphTheory *theory)
 
void GeometricClassify (int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
 
bool ValidFirstLine (const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
 
bool ValidBodyLine (const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
 
bool CrownCompatible (const GenericVector< RowScratchRegisters > *rows, int a, int b, const ParagraphModel *model)
 
void DiscardUnusedModels (const GenericVector< RowScratchRegisters > &rows, ParagraphTheory *theory)
 
void DowngradeWeakestToCrowns (int debug_level, ParagraphTheory *theory, GenericVector< RowScratchRegisters > *rows)
 
void RecomputeMarginsAndClearHypotheses (GenericVector< RowScratchRegisters > *rows, int start, int end, int percentile)
 
int InterwordSpace (const GenericVector< RowScratchRegisters > &rows, int row_start, int row_end)
 
bool FirstWordWouldHaveFit (const RowScratchRegisters &before, const RowScratchRegisters &after, tesseract::ParagraphJustification justification)
 
bool FirstWordWouldHaveFit (const RowScratchRegisters &before, const RowScratchRegisters &after)
 
bool TextSupportsBreak (const RowScratchRegisters &before, const RowScratchRegisters &after)
 
bool LikelyParagraphStart (const RowScratchRegisters &before, const RowScratchRegisters &after)
 
bool LikelyParagraphStart (const RowScratchRegisters &before, const RowScratchRegisters &after, tesseract::ParagraphJustification j)
 
ParagraphModel InternalParagraphModelByOutline (const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance, bool *consistent)
 
ParagraphModel ParagraphModelByOutline (int debug_level, const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance)
 
bool RowsFitModel (const GenericVector< RowScratchRegisters > *rows, int start, int end, const ParagraphModel *model)
 
void MarkStrongEvidence (GenericVector< RowScratchRegisters > *rows, int row_start, int row_end)
 
void ModelStrongEvidence (int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, bool allow_flush_models, ParagraphTheory *theory)
 
void StrongEvidenceClassify (int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
 
void SeparateSimpleLeaderLines (GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
 
void ConvertHypothesizedModelRunsToParagraphs (int debug_level, const GenericVector< RowScratchRegisters > &rows, GenericVector< PARA * > *row_owners, ParagraphTheory *theory)
 
bool RowIsStranded (const GenericVector< RowScratchRegisters > &rows, int row)
 
void LeftoverSegments (const GenericVector< RowScratchRegisters > &rows, GenericVector< Interval > *to_fix, int row_start, int row_end)
 
void CanonicalizeDetectionResults (GenericVector< PARA * > *row_owners, PARA_LIST *paragraphs)
 
void DetectParagraphs (int debug_level, GenericVector< RowInfo > *row_infos, GenericVector< PARA * > *row_owners, PARA_LIST *paragraphs, GenericVector< ParagraphModel * > *models)
 
void InitializeTextAndBoxesPreRecognition (const MutableIterator &it, RowInfo *info)
 
void InitializeRowInfo (bool after_recognition, const MutableIterator &it, RowInfo *info)
 
void DetectParagraphs (int debug_level, bool after_text_recognition, const MutableIterator *block_start, GenericVector< ParagraphModel * > *models)
 
bool StrongModel (const ParagraphModel *model)
 
bool read_t (PAGE_RES_IT *page_res_it, TBOX *tbox)
 
ICOORD ComputeEndFromGradient (const ICOORD &start, double m)
 
bool CompareFontInfo (const FontInfo &fi1, const FontInfo &fi2)
 
bool CompareFontSet (const FontSet &fs1, const FontSet &fs2)
 
void FontInfoDeleteCallback (FontInfo f)
 
void FontSetDeleteCallback (FontSet fs)
 
bool read_info (FILE *f, FontInfo *fi, bool swap)
 
bool write_info (FILE *f, const FontInfo &fi)
 
bool read_spacing_info (FILE *f, FontInfo *fi, bool swap)
 
bool write_spacing_info (FILE *f, const FontInfo &fi)
 
bool read_set (FILE *f, FontSet *fs, bool swap)
 
bool write_set (FILE *f, const FontSet &fs)
 
void OtsuThreshold (const unsigned char *imagedata, int bytes_per_pixel, int bytes_per_line, int left, int top, int width, int height, int **thresholds, int **hi_values)
 
void HistogramRect (const unsigned char *imagedata, int bytes_per_pixel, int bytes_per_line, int left, int top, int width, int height, int *histogram)
 
int OtsuStats (const int *histogram, int *H_out, int *omega0_out)
 
 ELISTIZE (AmbigSpec)
 
 ELISTIZEH (AmbigSpec)
 
template<typename T >
bool cmp_eq (T const &t1, T const &t2)
 
template<typename T >
int sort_cmp (const void *t1, const void *t2)
 
template<typename T >
int sort_ptr_cmp (const void *t1, const void *t2)
 
void ClearFeatureSpaceWindow (NORM_METHOD norm_method, ScrollView *window)
 
WERD_CHOICEget_best_delete_other (WERD_CHOICE *choice1, WERD_CHOICE *choice2)
 
BLOB_CHOICEget_nth_choice (BLOB_CHOICE_LIST *blob_list, int n)
 
UNICHAR_ID get_top_choice_uid (BLOB_CHOICE_LIST *blob_list)
 
int find_choice_by_uid (BLOB_CHOICE_LIST *blob_list, UNICHAR_ID target_uid)
 
WERD_CHOICEget_choice_from_posstr (const UNICHARSET *unicharset, const BLOB_CHOICE_LIST_VECTOR &char_choices, int start_pos, const char *pos_str, float *certainties)
 
void get_posstr_from_choice (const BLOB_CHOICE_LIST_VECTOR &char_choices, WERD_CHOICE *word_choice, int start_pos, char *pos_str)
 
BLOB_CHOICEfind_choice_by_type (BLOB_CHOICE_LIST *blob_choices, char target_type, const UNICHARSET &unicharset)
 
BLOB_CHOICEfind_choice_by_script (BLOB_CHOICE_LIST *blob_choices, int target_sid, int backup_sid, int secondary_sid)
 
Pix * GridReducedPix (const TBOX &box, int gridsize, ICOORD bleft, int *left, int *bottom)
 
Pix * TraceOutlineOnReducedPix (C_OUTLINE *outline, int gridsize, ICOORD bleft, int *left, int *bottom)
 
Pix * TraceBlockOnReducedPix (BLOCK *block, int gridsize, ICOORD bleft, int *left, int *bottom)
 
template<class BBC >
int SortByBoxLeft (const void *void1, const void *void2)
 
template<class BBC >
int SortRightToLeft (const void *void1, const void *void2)
 
template<class BBC >
int SortByBoxBottom (const void *void1, const void *void2)
 
template<typename T >
void DeleteObject (T *object)
 
ShapeTableLoadShapeTable (const STRING &file_prefix)
 
void WriteShapeTable (const STRING &file_prefix, const ShapeTable &shape_table)
 
MasterTrainerLoadTrainingData (int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
 
 ELISTIZE (ViterbiStateEntry)
 
 ELISTIZEH (ViterbiStateEntry)
 
template<class BLOB_CHOICE >
int SortByUnicharID (const void *void1, const void *void2)
 
template<class BLOB_CHOICE >
int SortByRating (const void *void1, const void *void2)
 

Variables

const int kMinRectSize = 10
 
const char kTesseractReject = '~'
 
const char kUNLVReject = '~'
 
const char kUNLVSuspect = '^'
 
const char * kInputFile = "noname.tif"
 
const char * kOldVarsFile = "failed_vars.txt"
 
const int kMaxIntSize = 22
 
const int kMinCredibleResolution = 70
 Minimum believable resolution. More...
 
const int kMaxCredibleResolution = 2400
 
const int kNumbersPerBlob = 5
 
const int kBytesPerNumber = 5
 
const int kBytesPerBlob = kNumbersPerBlob * (kBytesPerNumber + 1) + 1
 
const int kBytesPerBoxFileLine = (kBytesPerNumber + 1) * kNumbersPerBlob + 1
 
const int kBytesPer64BitNumber = 20
 
const int kMaxBytesPerLine
 
const int kUniChs []
 
const int kLatinChs []
 
const float kMathDigitDensityTh1 = 0.25
 
const float kMathDigitDensityTh2 = 0.1
 
const float kMathItalicDensityTh = 0.5
 
const float kUnclearDensityTh = 0.25
 
const int kSeedBlobsCountTh = 10
 
const int kLeftIndentAlignmentCountTh = 1
 
const int kMaxCharTopRange = 48
 
const int kDefaultResolution = 300
 Default resolution used if input in not believable. More...
 
const int kMaxCircleErosions = 8
 
const int kStrayLinePer = 6
 
const ParagraphModelkCrownLeft = reinterpret_cast<ParagraphModel *>(0xDEAD111F)
 
const ParagraphModelkCrownRight = reinterpret_cast<ParagraphModel *>(0xDEAD888F)
 
const inT16 kMaxBoxEdgeDiff = 2
 
const int kBoxClipTolerance = 2
 
const int kMinSubscriptOffset = 20
 
const int kMinSuperscriptOffset = 20
 
const int kMaxDropCapBottom = -128
 
const int kNumEndPoints = 3
 
const int kHistogramSize = 256
 
CCUtilMutex tprintfMutex
 
const char * kUTF8LineSeparator = "\u2028"
 
const char * kUTF8ParagraphSeparator = "\u2029"
 
const char * kLRM = "\u200E"
 
const char * kRLM = "\u200F"
 
const char * kRLE = "\u202A"
 
const char * kPDF = "\u202C"
 
const char * kHyphenLikeUTF8 []
 
const char * kApostropheLikeUTF8 []
 
const int kMaxOffsetDist = 32
 
const double kMinPCLengthIncrease = 1.0 / 1024
 
const int kMinClusteredShapes = 1
 
const int kMaxUnicharsPerCluster = 2000
 
const float kFontMergeDistance = 0.025
 
const float kInfiniteDist = 999.0f
 
const int kRandomizingCenter = 128
 
const int kTestChar = -1
 
const int kSquareLimit = 25
 
const int kPrime1 = 17
 
const int kPrime2 = 13
 
const int kMinOutlierSamples = 5
 
const int kStateCnt = 4
 
const int kNumLiteralCnt = 5
 
const int case_state_table [6][4]
 
const char kDoNotReverse [] = "RRP_DO_NO_REVERSE"
 
const char kReverseIfHasRTL [] = "RRP_REVERSE_IF_HAS_RTL"
 
const char kForceReverse [] = "RRP_FORCE_REVERSE"
 
const char *const RTLReversePolicyNames []
 
const double kAlignedFraction = 0.03125
 
const double kRaggedFraction = 2.5
 
const double kAlignedGapFraction = 0.75
 
const double kRaggedGapFraction = 1.0
 
const int kVLineAlignment = 3
 
const int kVLineGutter = 1
 
const int kVLineSearchSize = 150
 
const int kMinRaggedTabs = 5
 
const int kMinAlignedTabs = 4
 
const int kVLineMinLength = 500
 
const double kMinTabGradient = 4.0
 
const int kMaxSkewFactor = 15
 
const char * kTextordDebugPix = "psdebug_pix"
 
const double kMaxSmallNeighboursPerPix = 1.0 / 32
 
const int kMaxLargeOverlapsWithSmall = 3
 
const int kMaxMediumOverlapsWithSmall = 12
 
const int kMaxLargeOverlapsWithMedium = 12
 
const int kOriginalNoiseMultiple = 8
 
const int kNoisePadding = 4
 
const double kPhotoOffsetFraction = 0.375
 
const double kMinGoodTextPARatio = 1.5
 
const int kMinColumnWidth = 100
 
const int kMaxIncompatibleColumnCount = 2
 
const double kMarginOverlapFraction = 0.25
 
const double kHorizontalGapMergeFraction = 0.5
 
const double kMinNonNoiseFraction = 0.5
 
const double kMinGutterWidthGrid = 0.5
 
const double kMaxDistToPartSizeRatio = 1.5
 
bool textord_tabfind_show_initial_partitions = false
 
bool textord_tabfind_show_reject_blobs = false
 
int textord_tabfind_show_partitions = 0
 
bool textord_tabfind_show_columns = false
 
bool textord_tabfind_show_blocks = false
 
bool textord_tabfind_find_tables = true
 
const int kMaxPartnerDepth = 4
 
const double kMaxSpacingDrift = 1.0 / 72
 
const double kMaxTopSpacingFraction = 0.25
 
const double kMaxSameBlockLineSpacing = 3
 
const double kMaxSizeRatio = 1.5
 
const double kMaxLeaderGapFractionOfMax = 0.25
 
const double kMaxLeaderGapFractionOfMin = 0.5
 
const int kMinLeaderCount = 5
 
const int kLeaderCutCost = 8
 
const int kMinStrongTextValue = 6
 
const int kMinChainTextValue = 3
 
const int kHorzStrongTextlineCount = 8
 
const int kHorzStrongTextlineHeight = 10
 
const int kHorzStrongTextlineAspect = 5
 
const double kMaxBaselineError = 0.4375
 
const double kMinBaselineCoverage = 0.5
 
const int kMaxRMSColorNoise = 128
 
const int kMaxColorDistance = 900
 
const int kRGBRMSColors = 4
 
bool textord_tabfind_show_color_fit = false
 
const int kMaxPadFactor = 6
 
const int kMaxNeighbourDistFactor = 4
 
const int kMaxCaptionLines = 7
 
const double kMinCaptionGapRatio = 2.0
 
const double kMinCaptionGapHeightRatio = 0.5
 
const double kBigPartSizeRatio = 1.75
 
const double kStrokeWidthFractionTolerance = 0.25
 
const double kStrokeWidthConstantTolerance = 2.0
 
const double kTinyEnoughTextlineOverlapFraction = 0.25
 
const double kMaxPartitionSpacing = 1.75
 
const int kSmoothDecisionMargin = 4
 
const double kMinRectangularFraction = 0.125
 
const double kMaxRectangularFraction = 0.75
 
const double kMaxRectangularGradient = 0.1
 
const int kMinImageFindSize = 100
 
const double kRMSFitScaling = 8.0
 
const int kMinColorDifference = 16
 
const int kThinLineFraction = 20
 Denominator of resolution makes max pixel width to allow thin lines. More...
 
const int kMinLineLengthFraction = 4
 Denominator of resolution makes min pixels to demand line lengths to be. More...
 
const int kCrackSpacing = 100
 Spacing of cracks across the page to break up tall vertical lines. More...
 
const int kLineFindGridSize = 50
 Grid size used by line finder. Not very critical. More...
 
const int kMinThickLineWidth = 12
 
const int kMaxLineResidue = 6
 
const double kThickLengthMultiple = 0.75
 
const double kMaxNonLineDensity = 0.25
 
const double kMaxStaveHeight = 1.0
 
const double kMinMusicPixelFraction = 0.75
 
int textord_tabfind_show_strokewidths = 0
 
bool textord_tabfind_only_strokewidths = false
 
bool textord_tabfind_vertical_text = true
 
bool textord_tabfind_force_vertical_text = false
 
bool textord_tabfind_vertical_horizontal_mix = true
 
double textord_tabfind_vertical_text_ratio = 0.5
 
const double kStrokeWidthTolerance = 1.5
 
const double kStrokeWidthFractionCJK = 0.25
 
const double kStrokeWidthCJK = 2.0
 
const int kCJKRadius = 2
 
const double kCJKBrokenDistanceFraction = 0.25
 
const int kCJKMaxComponents = 8
 
const double kCJKAspectRatio = 1.25
 
const double kCJKAspectRatioIncrease = 1.0625
 
const int kMaxCJKSizeRatio = 5
 
const double kBrokenCJKIterationFraction = 0.125
 
const double kDiacriticXPadRatio = 7.0
 
const double kDiacriticYPadRatio = 1.75
 
const double kMinDiacriticSizeRatio = 1.0625
 
const double kMaxDiacriticDistanceRatio = 1.25
 
const double kMaxDiacriticGapToBaseCharHeight = 1.0
 
const int kSearchRadius = 2
 
const int kLineTrapLongest = 4
 
const int kLineTrapShortest = 2
 
const int kMostlyOneDirRatio = 3
 
const double kLineResidueAspectRatio = 8.0
 
const int kLineResiduePadRatio = 3
 
const double kLineResidueSizeRatio = 1.75
 
const float kSizeRatioToReject = 2.0
 
const int kMaxLargeOverlaps = 3
 
const double kNeighbourSearchFactor = 2.5
 
const int kTabRadiusFactor = 5
 
const int kMinVerticalSearch = 3
 
const int kMaxVerticalSearch = 12
 
const int kMaxRaggedSearch = 25
 
const int kMinLinesInColumn = 10
 
const double kMinFractionalLinesInColumn = 0.125
 
const double kMinGutterWidthAbsolute = 0.02
 
const double kMaxGutterWidthAbsolute = 2.00
 
const int kRaggedGutterMultiple = 5
 
const double kLineFragmentAspectRatio = 10.0
 
const double kSmoothFactor = 0.25
 
const double kCharVerticalOverlapFraction = 0.375
 
const double kMaxHorizontalGap = 3.0
 
const int kMinEvaluatedTabs = 3
 
const int kMaxTextLineBlobRatio = 5
 
const int kMinTextLineBlobRatio = 3
 
const double kMinImageArea = 0.5
 
const double kCosMaxSkewAngle = 0.866025
 
bool textord_tabfind_show_initialtabs = false
 
bool textord_tabfind_show_finaltabs = false
 
double textord_tabfind_aligned_gap_fraction = 0.75
 
const int kColumnWidthFactor = 20
 
const int kMaxVerticalSpacing = 500
 
const int kMaxBlobWidth = 500
 
const double kSplitPartitionSize = 2.0
 
const double kAllowTextHeight = 0.5
 
const double kAllowTextWidth = 0.6
 
const double kAllowTextArea = 0.8
 
const double kAllowBlobHeight = 0.3
 
const double kAllowBlobWidth = 0.4
 
const double kAllowBlobArea = 0.05
 
const int kMinBoxesInTextPartition = 10
 
const int kMaxBoxesInDataPartition = 20
 
const double kMaxGapInTextPartition = 4.0
 
const double kMinMaxGapInTextPartition = 0.5
 
const double kMaxBlobOverlapFactor = 4.0
 
const double kMaxTableCellXheight = 2.0
 
const int kMaxColumnHeaderDistance = 4
 
const double kTableColumnThreshold = 3.0
 
const int kRulingVerticalMargin = 3
 
const double kMinOverlapWithTable = 0.6
 
const int kSideSpaceMargin = 10
 
const double kSmallTableProjectionThreshold = 0.35
 
const double kLargeTableProjectionThreshold = 0.45
 
const int kLargeTableRowCount = 6
 
const int kMinRowsInTable = 3
 
const double kRequiredFullJustifiedSpacing = 4.0
 
const int kAdjacentLeaderSearchPadding = 2
 
const double kParagraphEndingPreviousLineRatio = 1.3
 
const double kMaxParagraphEndingLeftSpaceMultiple = 3.0
 
const double kMinParagraphEndingTextToWhitespaceRatio = 3.0
 
const double kMaxXProjectionGapFactor = 2.0
 
const double kStrokeWidthFractionalTolerance = 0.25
 
bool textord_dump_table_images = false
 
bool textord_show_tables = false
 
bool textord_tablefind_show_mark = false
 
bool textord_tablefind_show_stats = false
 
bool textord_tablefind_recognize_tables = false
 
const double kHorizontalSpacing = 0.30
 
const double kVerticalSpacing = -0.2
 
const int kCellSplitRowThreshold = 0
 
const int kCellSplitColumnThreshold = 0
 
const int kLinedTableMinVerticalLines = 3
 
const int kLinedTableMinHorizontalLines = 3
 
const double kRequiredColumns = 0.7
 
const double kMarginFactor = 1.1
 
const double kMaxRowSize = 2.5
 
const double kGoodRowNumberOfColumnsSmall [] = { 2, 2, 2, 2, 2, 3, 3 }
 
const int kGoodRowNumberOfColumnsSmallSize
 
const double kGoodRowNumberOfColumnsLarge = 0.7
 
const double kMinFilledArea = 0.35
 
const int kGutterMultiple = 4
 
const int kGutterToNeighbourRatio = 3
 
const int kSimilarVectorDist = 10
 
const int kSimilarRaggedDist = 50
 
const int kMaxFillinMultiple = 11
 
const double kMinGutterFraction = 0.5
 
const double kLineCountReciprocal = 4.0
 
const double kMinAlignedGutter = 0.25
 
const double kMinRaggedGutter = 1.5
 
double textord_tabvector_vertical_gap_fraction = 0.5
 
double textord_tabvector_vertical_box_ratio = 0.5
 
const char * kAlignmentNames []
 

Detailed Description

recog_pseudo_word

Make a word from the selected blobs and run Tess on them.

Parameters
page_resrecognise blobs
selection_boxwithin this box

fp_eval_word_spacing() Evaluation function for fixed pitch word lists.

Basically, count the number of "nice" characters - those which are in tess acceptable words or in dict words and are not rejected. Penalise any potential noise chars

process_selected_words()

Walk the current block list applying the specified word processor function to each word that overlaps the selection_box.

build_menu()

Construct the menu tree used by the command window

process_cmd_win_event()

Process a command returned from the command window (Just call the appropriate command handler)

word_blank_and_set_display() Word processor

Blank display of word then redisplay word according to current display mode settings


Public Code


Include Files and Type Defines


Include Files and Type Defines

Public Code

Typedef Documentation

typedef GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> tesseract::BlobGridSearch

Definition at line 31 of file blobgrid.h.

typedef signed int tesseract::char_32

Definition at line 40 of file string_32.h.

typedef GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> tesseract::ColPartitionGridSearch

Definition at line 895 of file colpartition.h.

typedef BBGrid<ColSegment, ColSegment_CLIST, ColSegment_C_IT> tesseract::ColSegmentGrid

Definition at line 118 of file tablefind.h.

typedef GridSearch<ColSegment, ColSegment_CLIST, ColSegment_C_IT> tesseract::ColSegmentGridSearch

Definition at line 121 of file tablefind.h.

Definition at line 47 of file dict.h.

typedef int(Dict::* tesseract::DictFunc)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const

Definition at line 81 of file baseapi.h.

typedef void(Wordrec::* tesseract::FillLatticeFunc)(const MATRIX &ratings, const LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)

Definition at line 88 of file baseapi.h.

typedef unsigned char tesseract::LanguageModelFlagsType

Definition at line 37 of file language_model.h.

Definition at line 67 of file dawg.h.

typedef double(Dict::* tesseract::ProbabilityInContextFunc)(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)

Definition at line 83 of file baseapi.h.

Definition at line 94 of file paragraphs_internal.h.

typedef basic_string<char_32> tesseract::string_32

Definition at line 41 of file string_32.h.

Definition at line 68 of file dawg.h.

Definition at line 69 of file dawg.h.

Definition at line 92 of file baseapi.h.

typedef GenericVector<AmbigSpec_LIST *> tesseract::UnicharAmbigsVector

Definition at line 139 of file ambigs.h.

Definition at line 34 of file ambigs.h.

Definition at line 45 of file tabfind.h.

typedef void(Tesseract::* tesseract::WordRecognizer)(BLOCK *block, ROW *row, WERD_RES *word)

Definition at line 103 of file tesseractclass.h.

Enumeration Type Documentation

Enumerator
NOT_AMBIG 
REPLACE_AMBIG 
DEFINITE_AMBIG 
SIMILAR_AMBIG 
CASE_AMBIG 
AMBIG_TYPE_COUNT 

Definition at line 44 of file ambigs.h.

44  {
45  NOT_AMBIG, // the ngram pair is not ambiguous
46  REPLACE_AMBIG, // ocred ngram should always be substituted with correct
47  DEFINITE_AMBIG, // add correct ngram to the classifier results (1-1)
48  SIMILAR_AMBIG, // use pairwise classifier for ocred/correct pair (1-1)
49  CASE_AMBIG, // this is a case ambiguity (1-1)
50 
51  AMBIG_TYPE_COUNT // number of enum entries
52 };
Enumerator
CST_FRAGMENT 
CST_WHOLE 
CST_IMPROPER 
CST_NGRAM 

Definition at line 51 of file classify.h.

51  {
52  CST_FRAGMENT, // A partial character.
53  CST_WHOLE, // A correctly segmented character.
54  CST_IMPROPER, // More than one but less than 2 characters.
55  CST_NGRAM // Multiple characters.
56 };
Enumerator
ACTION_1_CMD_EVENT 
RECOG_WERDS 
RECOG_PSEUDO 
ACTION_2_CMD_EVENT 

Definition at line 437 of file tessedit.cpp.

Enumerator
COL_UNKNOWN 
COL_TEXT 
COL_TABLE 
COL_MIXED 
COL_COUNT 

Definition at line 30 of file tablefind.h.

Enumerator
CST_NOISE 
CST_FLOWING 
CST_HEADING 
CST_PULLOUT 
CST_COUNT 

Definition at line 47 of file colpartition.h.

47  {
48  CST_NOISE, // Strictly between columns.
49  CST_FLOWING, // Strictly within a single column.
50  CST_HEADING, // Spans multiple columns.
51  CST_PULLOUT, // Touches multiple columns, but doesn't span them.
52  CST_COUNT // Number of entries.
53 };
Enumerator
CT_SHAPE_TOP_CORRECT 
CT_SHAPE_TOP_ERR 
CT_FONT_ATTR_ERR 
CT_UNICHAR_TOP1_ERR 
CT_UNICHAR_TOP2_ERR 
CT_UNICHAR_TOPN_ERR 
CT_OK_MULTI_UNICHAR 
CT_REJECT 
CT_NUM_RESULTS 
CT_RANK 
CT_REJECTED_JUNK 
CT_ACCEPTED_JUNK 
CT_SIZE 

Definition at line 69 of file errorcounter.h.

69  {
70  CT_SHAPE_TOP_CORRECT, // Top shape id is actually correct.
71  CT_SHAPE_TOP_ERR, // Top shape id is not correct.
72  CT_FONT_ATTR_ERR, // Font attributes incorrect, ignoring unichar.
73  CT_UNICHAR_TOP1_ERR, // Top shape does not contain correct unichar id.
74  CT_UNICHAR_TOP2_ERR, // Top 2 shapes don't contain correct unichar id.
75  CT_UNICHAR_TOPN_ERR, // No output shape contains correct unichar id.
76  CT_OK_MULTI_UNICHAR, // Top shape id has correct unichar id, and others.
77  CT_REJECT, // Classifier hates this.
78  CT_NUM_RESULTS, // Number of answers produced.
79  CT_RANK, // Rank of correct answer.
80  CT_REJECTED_JUNK, // Junk that was correctly rejected.
81  CT_ACCEPTED_JUNK, // Junk that was incorrectly classified otherwise.
82 
83  CT_SIZE // Number of types for array sizing.
84 };
Enumerator
DAWG_TYPE_PUNCTUATION 
DAWG_TYPE_WORD 
DAWG_TYPE_NUMBER 
DAWG_TYPE_PATTERN 
DAWG_TYPE_COUNT 

Definition at line 71 of file dawg.h.

Enumerator
LR_LEFT 
LR_RIGHT 

Definition at line 39 of file strokewidth.h.

Enumerator
LT_START 
LT_BODY 
LT_UNKNOWN 
LT_MULTIPLE 

Definition at line 54 of file paragraphs_internal.h.

54  {
55  LT_START = 'S', // First line of a paragraph.
56  LT_BODY = 'C', // Continuation line of a paragraph.
57  LT_UNKNOWN = 'U', // No clues.
58  LT_MULTIPLE = 'M', // Matches for both LT_START and LT_BODY.
59 };
Enumerator
NPT_HTEXT 
NPT_VTEXT 
NPT_WEAK_HTEXT 
NPT_WEAK_VTEXT 
NPT_IMAGE 
NPT_COUNT 

Definition at line 1431 of file colpartitiongrid.cpp.

1431  {
1432  NPT_HTEXT, // Definite horizontal text.
1433  NPT_VTEXT, // Definite vertical text.
1434  NPT_WEAK_HTEXT, // Weakly horizontal text. Counts as HTEXT for HTEXT, but
1435  // image for image and VTEXT.
1436  NPT_WEAK_VTEXT, // Weakly vertical text. Counts as VTEXT for VTEXT, but
1437  // image for image and HTEXT.
1438  NPT_IMAGE, // Defininte non-text.
1439  NPT_COUNT // Number of array elements.
1440 };
Enumerator
NM_BASELINE 
NM_CHAR_ISOTROPIC 
NM_CHAR_ANISOTROPIC 

Definition at line 42 of file normalis.h.

42  {
43  NM_BASELINE = -3, // The original BL normalization mode.
44  NM_CHAR_ISOTROPIC = -2, // Character normalization but isotropic.
45  NM_CHAR_ANISOTROPIC = -1 // The original CN normalization mode.
46 };

When Tesseract/Cube is initialized we can choose to instantiate/load/run only the Tesseract part, only the Cube part or both along with the combiner. The preference of which engine to use is stored in tessedit_ocr_engine_mode.

ATTENTION: When modifying this enum, please make sure to make the appropriate changes to all the enums mirroring it (e.g. OCREngine in cityblock/workflow/detection/detection_storage.proto). Such enums will mention the connection to OcrEngineMode in the comments.

Enumerator
OEM_TESSERACT_ONLY 
OEM_CUBE_ONLY 
OEM_TESSERACT_CUBE_COMBINED 
OEM_DEFAULT 

Definition at line 234 of file publictypes.h.

234  {
235  OEM_TESSERACT_ONLY, // Run Tesseract only - fastest
236  OEM_CUBE_ONLY, // Run Cube only - better accuracy, but slower
237  OEM_TESSERACT_CUBE_COMBINED, // Run both and combine results - best accuracy
238  OEM_DEFAULT // Specify this mode when calling init_*(),
239  // to indicate that any of the above modes
240  // should be automatically inferred from the
241  // variables in the language-specific config,
242  // command-line configs, or if not specified
243  // in any of the above should be set to the
244  // default OEM_TESSERACT_ONLY.
245 };

+---------------—+ Orientation Example: | 1 Aaaa Aaaa Aaaa | ==================== | Aaa aa aaa aa | To left is a diagram of some (1) English and | aaaaaa A aa aaa. | (2) Chinese text and a (3) photo credit. | 2 | | ####### c c C | Upright Latin characters are represented as A and a. | ####### c c c | '<' represents a latin character rotated | < ####### c c c | anti-clockwise 90 degrees. | < ####### c c | | < ####### . c | Upright Chinese characters are represented C and c. | 3 ####### c | +---------------—+ NOTA BENE: enum values here should match goodoc.proto

If you orient your head so that "up" aligns with Orientation, then the characters will appear "right side up" and readable.

In the example above, both the English and Chinese paragraphs are oriented so their "up" is the top of the page (page up). The photo credit is read with one's head turned leftward ("up" is to page left).

The values of this enum match the convention of Tesseract's osdetect.h

Enumerator
ORIENTATION_PAGE_UP 
ORIENTATION_PAGE_RIGHT 
ORIENTATION_PAGE_DOWN 
ORIENTATION_PAGE_LEFT 

Definition at line 104 of file publictypes.h.

enum of the elements of the page hierarchy, used in ResultIterator to provide functions that operate on each level without having to have 5x as many functions.

Enumerator
RIL_BLOCK 
RIL_PARA 
RIL_TEXTLINE 
RIL_WORD 
RIL_SYMBOL 

Definition at line 185 of file publictypes.h.

185  {
186  RIL_BLOCK, // Block of text/image/separator line.
187  RIL_PARA, // Paragraph within a block.
188  RIL_TEXTLINE, // Line within a paragraph.
189  RIL_WORD, // Word within a textline.
190  RIL_SYMBOL // Symbol/character within a word.
191 };
Definition: capi.h:61
Definition: capi.h:61
Definition: capi.h:61

Possible modes for page layout analysis. These must be kept in order of decreasing amount of layout analysis to be done, except for OSD_ONLY, so that the inequality test macros below work.

Enumerator
PSM_OSD_ONLY 

Orientation and script detection only.

PSM_AUTO_OSD 

Automatic page segmentation with orientation and script detection. (OSD)

PSM_AUTO_ONLY 

Automatic page segmentation, but no OSD, or OCR.

PSM_AUTO 

Fully automatic page segmentation, but no OSD.

PSM_SINGLE_COLUMN 

Assume a single column of text of variable sizes.

PSM_SINGLE_BLOCK_VERT_TEXT 

Assume a single uniform block of vertically aligned text.

PSM_SINGLE_BLOCK 

Assume a single uniform block of text. (Default.)

PSM_SINGLE_LINE 

Treat the image as a single text line.

PSM_SINGLE_WORD 

Treat the image as a single word.

PSM_CIRCLE_WORD 

Treat the image as a single word in a circle.

PSM_SINGLE_CHAR 

Treat the image as a single character.

PSM_COUNT 

Number of enum entries.

Definition at line 147 of file publictypes.h.

JUSTIFICATION_UNKNONW The alignment is not clearly one of the other options. This could happen for example if there are only one or two lines of text or the text looks like source code or poetry.

NOTA BENE: Fully justified paragraphs (text aligned to both left and right margins) are marked by Tesseract with JUSTIFICATION_LEFT if their text is written with a left-to-right script and with JUSTIFICATION_RIGHT if their text is written in a right-to-left script.

Interpretation for text read in vertical lines: "Left" is wherever the starting reading position is.

JUSTIFICATION_LEFT Each line, except possibly the first, is flush to the same left tab stop.

JUSTIFICATION_CENTER The text lines of the paragraph are centered about a line going down through their middle of the text lines.

JUSTIFICATION_RIGHT Each line, except possibly the first, is flush to the same right tab stop.

Enumerator
JUSTIFICATION_UNKNOWN 
JUSTIFICATION_LEFT 
JUSTIFICATION_CENTER 
JUSTIFICATION_RIGHT 

Definition at line 217 of file publictypes.h.

Enumerator
PTRAIN_RAW_FEATURE_DICT_MATCH_TYPE 
PTRAIN_RAW_FEATURE_UNAMBIG_DICT_MATCH 
PTRAIN_RAW_FEATURE_SHAPE_COST 
PTRAIN_RAW_FEATURE_NGRAM_PROB 
PTRAIN_RAW_FEATURE_NUM_BAD_PUNC 
PTRAIN_RAW_FEATURE_NUM_BAD_CASE 
PTRAIN_RAW_FEATURE_NUM_BAD_CHAR_TYPE 
PTRAIN_RAW_FEATURE_NUM_BAD_SPACING 
PTRAIN_RAW_FEATURE_NUM_BAD_SCRIPT 
PTRAIN_RAW_FEATURE_NUM_BAD_FONT 
PTRAIN_RAW_FEATURE_WORST_CERT 
PTRAIN_RAW_FEATURE_RATING 
PTRAIN_RAW_FEATURE_ADAPTED 
PTRAIN_RAW_FEATURE_NUM_UNICHARS 
PTRAIN_RAW_FEATURE_OUTLINE_LEN 
PTRAIN_NUM_RAW_FEATURE_TYPES 

Definition at line 34 of file params_training_featdef.h.

34  {
35  // What dictionary (if any) was this hypothesis found in.
36  // See PermuterType enum in ccstruct/ratngs.h for interpretation.
38  // Boolean indicator of whether this hypothesis is ambiguous to a known
39  // dictionary word (or a valid number pattern).
41  // Shape cost of the segmentation path for this hypothesis.
43  // Character ngram probability of the string of unichars of this hypothesis.
45  // Number of bad/inconsistent spots in this hypothesis.
52  // Classifier-related features.
55  // Number of classifier results that came from adapted templates.
57  // Features potentially useful for normalization.
60 
62 };
Enumerator
SP_NORMAL 
SP_SUBSCRIPT 
SP_SUPERSCRIPT 
SP_DROPCAP 

Definition at line 38 of file boxword.h.

Enumerator
SET_PARAM_CONSTRAINT_NONE 
SET_PARAM_CONSTRAINT_DEBUG_ONLY 
SET_PARAM_CONSTRAINT_NON_DEBUG_ONLY 
SET_PARAM_CONSTRAINT_NON_INIT_ONLY 

Definition at line 36 of file params.h.

Enumerator
TA_LEFT_ALIGNED 
TA_LEFT_RAGGED 
TA_CENTER_JUSTIFIED 
TA_RIGHT_ALIGNED 
TA_RIGHT_RAGGED 
TA_SEPARATOR 
TA_COUNT 

Definition at line 43 of file tabvector.h.

Enumerator
TESSDATA_LANG_CONFIG 
TESSDATA_UNICHARSET 
TESSDATA_AMBIGS 
TESSDATA_INTTEMP 
TESSDATA_PFFMTABLE 
TESSDATA_NORMPROTO 
TESSDATA_PUNC_DAWG 
TESSDATA_SYSTEM_DAWG 
TESSDATA_NUMBER_DAWG 
TESSDATA_FREQ_DAWG 
TESSDATA_FIXED_LENGTH_DAWGS 
TESSDATA_CUBE_UNICHARSET 
TESSDATA_CUBE_SYSTEM_DAWG 
TESSDATA_SHAPE_TABLE 
TESSDATA_BIGRAM_DAWG 
TESSDATA_UNAMBIG_DAWG 
TESSDATA_PARAMS_TRAINING_MODEL 
TESSDATA_NUM_ENTRIES 

Definition at line 51 of file tessdatamanager.h.

51  {
54  TESSDATA_AMBIGS, // 2
55  TESSDATA_INTTEMP, // 3
56  TESSDATA_PFFMTABLE, // 4
57  TESSDATA_NORMPROTO, // 5
58  TESSDATA_PUNC_DAWG, // 6
61  TESSDATA_FREQ_DAWG, // 9
69 
71 };

The text lines are read in the given sequence.

In English, the order is top-to-bottom. In Chinese, vertical text lines are read right-to-left. Mongolian is written in vertical columns top to bottom like Chinese, but the lines order left-to right.

Note that only some combinations make sense. For example, WRITING_DIRECTION_LEFT_TO_RIGHT implies TEXTLINE_ORDER_TOP_TO_BOTTOM

Enumerator
TEXTLINE_ORDER_LEFT_TO_RIGHT 
TEXTLINE_ORDER_RIGHT_TO_LEFT 
TEXTLINE_ORDER_TOP_TO_BOTTOM 

Definition at line 136 of file publictypes.h.

The grapheme clusters within a line of text are laid out logically in this direction, judged when looking at the text line rotated so that its Orientation is "page up".

For English text, the writing direction is left-to-right. For the Chinese text in the above example, the writing direction is top-to-bottom.

Enumerator
WRITING_DIRECTION_LEFT_TO_RIGHT 
WRITING_DIRECTION_RIGHT_TO_LEFT 
WRITING_DIRECTION_TOP_TO_BOTTOM 

Definition at line 119 of file publictypes.h.

Function Documentation

bool tesseract::AsciiLikelyListItem ( const STRING word)

Definition at line 279 of file paragraphs.cpp.

279  {
280  return LikelyListMark(word) || LikelyListNumeral(word);
281 }
bool LikelyListMark(const STRING &word)
Definition: paragraphs.cpp:274
bool LikelyListNumeral(const STRING &word)
Definition: paragraphs.cpp:240
void tesseract::CalculateTabStops ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
int  tolerance,
GenericVector< Cluster > *  left_tabs,
GenericVector< Cluster > *  right_tabs 
)

Definition at line 703 of file paragraphs.cpp.

707  {
708  if (!AcceptableRowArgs(0, 1, __func__, rows, row_start, row_end))
709  return;
710  // First pass: toss all left and right indents into clusterers.
711  SimpleClusterer initial_lefts(tolerance);
712  SimpleClusterer initial_rights(tolerance);
713  GenericVector<Cluster> initial_left_tabs;
714  GenericVector<Cluster> initial_right_tabs;
715  for (int i = row_start; i < row_end; i++) {
716  initial_lefts.Add((*rows)[i].lindent_);
717  initial_rights.Add((*rows)[i].rindent_);
718  }
719  initial_lefts.GetClusters(&initial_left_tabs);
720  initial_rights.GetClusters(&initial_right_tabs);
721 
722  // Second pass: cluster only lines that are not "stray"
723  // An example of a stray line is a page number -- a line whose start
724  // and end tab-stops are far outside the typical start and end tab-stops
725  // for the block.
726  // Put another way, we only cluster data from lines whose start or end
727  // tab stop is frequent.
728  SimpleClusterer lefts(tolerance);
729  SimpleClusterer rights(tolerance);
730  int infrequent_enough_to_ignore = (row_end - row_start) / kStrayLinePer;
731  for (int i = row_start; i < row_end; i++) {
732  int lidx = ClosestCluster(initial_left_tabs, (*rows)[i].lindent_);
733  int ridx = ClosestCluster(initial_right_tabs, (*rows)[i].rindent_);
734  if (initial_left_tabs[lidx].count > infrequent_enough_to_ignore ||
735  initial_right_tabs[ridx].count > infrequent_enough_to_ignore) {
736  lefts.Add((*rows)[i].lindent_);
737  rights.Add((*rows)[i].rindent_);
738  }
739  }
740  lefts.GetClusters(left_tabs);
741  rights.GetClusters(right_tabs);
742 }
int ClosestCluster(const GenericVector< Cluster > &clusters, int value)
Definition: paragraphs.cpp:677
const int kStrayLinePer
Definition: paragraphs.cpp:46
int count(LIST var_list)
Definition: oldlist.cpp:108
void tesseract::CanonicalizeDetectionResults ( GenericVector< PARA * > *  row_owners,
PARA_LIST *  paragraphs 
)

Definition at line 2179 of file paragraphs.cpp.

2181  {
2182  GenericVector<PARA *> &rows = *row_owners;
2183  paragraphs->clear();
2184  PARA_IT out(paragraphs);
2185  PARA *formerly_null = NULL;
2186  for (int i = 0; i < rows.size(); i++) {
2187  if (rows[i] == NULL) {
2188  if (i == 0 || rows[i - 1] != formerly_null) {
2189  rows[i] = formerly_null = new PARA();
2190  } else {
2191  rows[i] = formerly_null;
2192  continue;
2193  }
2194  } else if (i > 0 && rows[i - 1] == rows[i]) {
2195  continue;
2196  }
2197  out.add_after_then_move(rows[i]);
2198  }
2199 }
virtual void clear()
#define NULL
Definition: host.h:144
Definition: ocrpara.h:29
int size() const
Definition: genericvector.h:59
TBOX tesseract::char_box_to_tbox ( Box *  char_box,
TBOX  word_box,
int  x_offset 
)

Definition at line 42 of file cube_control.cpp.

42  {
43  l_int32 left;
44  l_int32 top;
45  l_int32 width;
46  l_int32 height;
47  l_int32 right;
48  l_int32 bottom;
49 
50  boxGetGeometry(char_box, &left, &top, &width, &height);
51  left += word_box.left() - x_offset;
52  right = left + width;
53  top = word_box.bottom() + word_box.height() - top;
54  bottom = top - height;
55  return TBOX(left, bottom, right, top);
56 }
inT16 left() const
Definition: rect.h:67
Definition: rect.h:29
inT16 height() const
Definition: rect.h:97
inT16 bottom() const
Definition: rect.h:60
void tesseract::ClearFeatureSpaceWindow ( NORM_METHOD  norm_method,
ScrollView window 
)

Definition at line 1132 of file intproto.cpp.

1132  {
1133  window->Clear();
1134 
1135  window->Pen(ScrollView::GREY);
1136  // Draw the feature space limit rectangle.
1137  window->Rectangle(0, 0, INT_MAX_X, INT_MAX_Y);
1138  if (norm_method == baseline) {
1139  window->SetCursor(0, INT_DESCENDER);
1140  window->DrawTo(INT_MAX_X, INT_DESCENDER);
1141  window->SetCursor(0, INT_BASELINE);
1142  window->DrawTo(INT_MAX_X, INT_BASELINE);
1143  window->SetCursor(0, INT_XHEIGHT);
1144  window->DrawTo(INT_MAX_X, INT_XHEIGHT);
1145  window->SetCursor(0, INT_CAPHEIGHT);
1146  window->DrawTo(INT_MAX_X, INT_CAPHEIGHT);
1147  } else {
1150  }
1151 }
#define INT_XCENTER
Definition: intproto.cpp:60
#define INT_XRADIUS
Definition: intproto.cpp:62
#define INT_YRADIUS
Definition: intproto.cpp:63
void Clear()
Definition: scrollview.cpp:590
void SetCursor(int x, int y)
Definition: scrollview.cpp:520
void Pen(Color color)
Definition: scrollview.cpp:721
#define INT_CAPHEIGHT
Definition: intproto.cpp:58
#define INT_YCENTER
Definition: intproto.cpp:61
#define INT_XHEIGHT
Definition: intproto.cpp:57
#define INT_MAX_Y
Definition: intproto.cpp:67
void DrawTo(int x, int y)
Definition: scrollview.cpp:526
#define INT_BASELINE
Definition: intproto.cpp:56
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:601
#define INT_DESCENDER
Definition: intproto.cpp:55
#define INT_MAX_X
Definition: intproto.cpp:66
int tesseract::ClosestCluster ( const GenericVector< Cluster > &  clusters,
int  value 
)

Definition at line 677 of file paragraphs.cpp.

677  {
678  int best_index = 0;
679  for (int i = 0; i < clusters.size(); i++) {
680  if (abs(value - clusters[i].center) <
681  abs(value - clusters[best_index].center))
682  best_index = i;
683  }
684  return best_index;
685 }
int size() const
Definition: genericvector.h:59
template<typename T >
bool tesseract::cmp_eq ( T const &  t1,
T const &  t2 
)

Definition at line 285 of file genericvector.h.

285  {
286  return t1 == t2;
287 }
bool tesseract::CompareFontInfo ( const FontInfo &  fi1,
const FontInfo &  fi2 
)

Definition at line 25 of file fontinfo.cpp.

25  {
26  // The font properties are required to be the same for two font with the same
27  // name, so there is no need to test them.
28  // Consequently, querying the table with only its font name as information is
29  // enough to retrieve its properties.
30  return strcmp(fi1.name, fi2.name) == 0;
31 }
bool tesseract::CompareFontSet ( const FontSet &  fs1,
const FontSet &  fs2 
)

Definition at line 33 of file fontinfo.cpp.

33  {
34  if (fs1.size != fs2.size)
35  return false;
36  for (int i = 0; i < fs1.size; ++i) {
37  if (fs1.configs[i] != fs2.configs[i])
38  return false;
39  }
40  return true;
41 }
ICOORD tesseract::ComputeEndFromGradient ( const ICOORD start,
double  m 
)

Definition at line 124 of file detlinefit.cpp.

124  {
125  if (m > 1.0 || m < -1.0) {
126  // dy dominates. Force it to have the opposite sign of start.y() and
127  // compute dx based on dy being as large as possible
128  int dx = static_cast<int>(floor(MAX_INT16 / m));
129  if (dx < 0) ++dx; // Truncate towards 0.
130  if (start.y() > 0) dx = - dx; // Force dy to be opposite to start.y().
131  // Constrain dx so the result fits in an inT16.
132  while (start.x() + dx > MAX_INT16 || start.x() + dx < -MAX_INT16)
133  dx /= 2;
134  if (-1 <= dx && dx <= 1) {
135  return ICOORD(start.x(), start.y() + 1); // Too steep for anything else.
136  }
137  int y = start.y() + static_cast<int>(floor(dx * m + 0.5));
138  ASSERT_HOST(-MAX_INT16 <= y && y <= MAX_INT16);
139  return ICOORD(start.x() + dx, y);
140  } else {
141  // dx dominates. Force it to have the opposite sign of start.x() and
142  // compute dy based on dx being as large as possible.
143  int dy = static_cast<int>(floor(MAX_INT16 * m));
144  if (dy < 0) ++dy; // Truncate towards 0.
145  if (start.x() > 0) dy = - dy; // Force dx to be opposite to start.x().
146  // Constrain dy so the result fits in an inT16.
147  while (start.y() + dy > MAX_INT16 || start.y() + dy < -MAX_INT16)
148  dy /= 2;
149  if (-1 <= dy && dy <= 1) {
150  return ICOORD(start.x() + 1, start.y()); // Too flat for anything else.
151  }
152  int x = start.x() + static_cast<int>(floor(dy / m + 0.5));
153  ASSERT_HOST(-MAX_INT16 <= x && x <= MAX_INT16);
154  return ICOORD(x, start.y() + dy);
155  }
156 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
#define MAX_INT16
Definition: host.h:119
#define ASSERT_HOST(x)
Definition: errcode.h:84
void tesseract::ConvertHypothesizedModelRunsToParagraphs ( int  debug_level,
const GenericVector< RowScratchRegisters > &  rows,
GenericVector< PARA * > *  row_owners,
ParagraphTheory *  theory 
)

Definition at line 1988 of file paragraphs.cpp.

1992  {
1993  int end = rows.size();
1994  int start;
1995  for (; end > 0; end = start) {
1996  start = end - 1;
1997  const ParagraphModel *model = NULL;
1998  // TODO(eger): Be smarter about dealing with multiple hypotheses.
1999  bool single_line_paragraph = false;
2000  SetOfModels models;
2001  rows[start].NonNullHypotheses(&models);
2002  if (models.size() > 0) {
2003  model = models[0];
2004  if (rows[start].GetLineType(model) != LT_BODY)
2005  single_line_paragraph = true;
2006  }
2007  if (model && !single_line_paragraph) {
2008  // walk back looking for more body lines and then a start line.
2009  while (--start > 0 && rows[start].GetLineType(model) == LT_BODY) {
2010  // do nothing
2011  }
2012  if (start < 0 || rows[start].GetLineType(model) != LT_START) {
2013  model = NULL;
2014  }
2015  }
2016  if (model == NULL) {
2017  continue;
2018  }
2019  // rows[start, end) should be a paragraph.
2020  PARA *p = new PARA();
2021  if (model == kCrownLeft || model == kCrownRight) {
2023  // Crown paragraph.
2024  // If we can find an existing ParagraphModel that fits, use it,
2025  // else create a new one.
2026  for (int row = end; row < rows.size(); row++) {
2027  if ((*row_owners)[row] &&
2028  (ValidBodyLine(&rows, start, (*row_owners)[row]->model) &&
2029  (start == 0 ||
2030  ValidFirstLine(&rows, start, (*row_owners)[row]->model)))) {
2031  model = (*row_owners)[row]->model;
2032  break;
2033  }
2034  }
2035  if (model == kCrownLeft) {
2036  // No subsequent model fits, so cons one up.
2037  model = theory->AddModel(ParagraphModel(
2038  JUSTIFICATION_LEFT, rows[start].lmargin_ + rows[start].lindent_,
2039  0, 0, Epsilon(rows[start].ri_->average_interword_space)));
2040  } else if (model == kCrownRight) {
2041  // No subsequent model fits, so cons one up.
2042  model = theory->AddModel(ParagraphModel(
2043  JUSTIFICATION_RIGHT, rows[start].rmargin_ + rows[start].rmargin_,
2044  0, 0, Epsilon(rows[start].ri_->average_interword_space)));
2045  }
2046  }
2047  rows[start].SetUnknown();
2048  rows[start].AddStartLine(model);
2049  for (int i = start + 1; i < end; i++) {
2050  rows[i].SetUnknown();
2051  rows[i].AddBodyLine(model);
2052  }
2053  p->model = model;
2054  p->has_drop_cap = rows[start].ri_->has_drop_cap;
2055  p->is_list_item =
2057  ? rows[start].ri_->rword_indicates_list_item
2058  : rows[start].ri_->lword_indicates_list_item;
2059  for (int row = start; row < end; row++) {
2060  if ((*row_owners)[row] != NULL) {
2061  tprintf("Memory leak! ConvertHypothesizeModelRunsToParagraphs() called "
2062  "more than once!\n");
2063  }
2064  (*row_owners)[row] = p;
2065  }
2066  }
2067 }
const ParagraphModel * model
Definition: ocrpara.h:36
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
bool is_list_item
Definition: ocrpara.h:38
#define NULL
Definition: host.h:144
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
Definition: ocrpara.h:29
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
int size() const
Definition: genericvector.h:59
GenericVectorEqEq< const ParagraphModel * > SetOfModels
bool is_very_first_or_continuation
Definition: ocrpara.h:43
bool has_drop_cap
Definition: ocrpara.h:46
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
bool tesseract::CrownCompatible ( const GenericVector< RowScratchRegisters > *  rows,
int  a,
int  b,
const ParagraphModel model 
)

Definition at line 1237 of file paragraphs.cpp.

1238  {
1239  if (model != kCrownRight && model != kCrownLeft) {
1240  tprintf("CrownCompatible() should only be called with crown models!\n");
1241  return false;
1242  }
1243  RowScratchRegisters &row_a = (*rows)[a];
1244  RowScratchRegisters &row_b = (*rows)[b];
1245  if (model == kCrownRight) {
1246  return NearlyEqual(row_a.rindent_ + row_a.rmargin_,
1247  row_b.rindent_ + row_b.rmargin_,
1248  Epsilon(row_a.ri_->average_interword_space));
1249  }
1250  return NearlyEqual(row_a.lindent_ + row_a.lmargin_,
1251  row_b.lindent_ + row_b.lmargin_,
1252  Epsilon(row_a.ri_->average_interword_space));
1253 }
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:148
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
int tesseract::CubeAPITest ( Boxa *  boxa_blocks,
Pixa *  pixa_blocks,
Boxa *  boxa_words,
Pixa *  pixa_words,
const FCOORD reskew,
Pix *  page_pix,
PAGE_RES page_res 
)

Placeholder for call to Cube and test that the input data is correct. reskew is the direction of baselines in the skewed image in normalized (cos theta, sin theta) form, so (0.866, 0.5) would represent a 30 degree anticlockwise skew.

Definition at line 628 of file baseapi.cpp.

631  {
632  int block_count = boxaGetCount(boxa_blocks);
633  ASSERT_HOST(block_count == pixaGetCount(pixa_blocks));
634  // Write each block to the current directory as junk_write_display.nnn.png.
635  for (int i = 0; i < block_count; ++i) {
636  Pix* pix = pixaGetPix(pixa_blocks, i, L_CLONE);
637  pixDisplayWrite(pix, 1);
638  }
639  int word_count = boxaGetCount(boxa_words);
640  ASSERT_HOST(word_count == pixaGetCount(pixa_words));
641  int pr_word = 0;
642  PAGE_RES_IT page_res_it(page_res);
643  for (page_res_it.restart_page(); page_res_it.word () != NULL;
644  page_res_it.forward(), ++pr_word) {
645  WERD_RES *word = page_res_it.word();
646  WERD_CHOICE* choice = word->best_choice;
647  // Write the first 100 words to files names wordims/<wordstring>.tif.
648  if (pr_word < 100) {
649  STRING filename("wordims/");
650  if (choice != NULL) {
651  filename += choice->unichar_string();
652  } else {
653  char numbuf[32];
654  filename += "unclassified";
655  snprintf(numbuf, 32, "%03d", pr_word);
656  filename += numbuf;
657  }
658  filename += ".tif";
659  Pix* pix = pixaGetPix(pixa_words, pr_word, L_CLONE);
660  pixWrite(filename.string(), pix, IFF_TIFF_G4);
661  }
662  }
663  ASSERT_HOST(pr_word == word_count);
664  return 0;
665 }
const STRING & unichar_string() const
Definition: ratngs.h:395
#define NULL
Definition: host.h:144
WERD * word
Definition: pageres.h:334
Definition: strngs.h:40
#define ASSERT_HOST(x)
Definition: errcode.h:84
WERD_CHOICE * best_choice
Definition: pageres.h:359
template<typename T >
void tesseract::DeleteObject ( T *  object)

Definition at line 164 of file tablefind.cpp.

164  {
165  delete object;
166 }
void tesseract::DetectParagraphs ( int  debug_level,
GenericVector< RowInfo > *  row_infos,
GenericVector< PARA * > *  row_owners,
PARA_LIST *  paragraphs,
GenericVector< ParagraphModel * > *  models 
)

Definition at line 2211 of file paragraphs.cpp.

2215  {
2217  ParagraphTheory theory(models);
2218 
2219  // Initialize row_owners to be a bunch of NULL pointers.
2220  row_owners->init_to_size(row_infos->size(), NULL);
2221 
2222  // Set up row scratch registers for the main algorithm.
2223  rows.init_to_size(row_infos->size(), RowScratchRegisters());
2224  for (int i = 0; i < row_infos->size(); i++) {
2225  rows[i].Init((*row_infos)[i]);
2226  }
2227 
2228  // Pass 1:
2229  // Detect sequences of lines that all contain leader dots (.....)
2230  // These are likely Tables of Contents. If there are three text lines in
2231  // a row with leader dots, it's pretty safe to say the middle one should
2232  // be a paragraph of its own.
2233  SeparateSimpleLeaderLines(&rows, 0, rows.size(), &theory);
2234 
2235  DebugDump(debug_level > 1, "End of Pass 1", theory, rows);
2236 
2237  GenericVector<Interval> leftovers;
2238  LeftoverSegments(rows, &leftovers, 0, rows.size());
2239  for (int i = 0; i < leftovers.size(); i++) {
2240  // Pass 2a:
2241  // Find any strongly evidenced start-of-paragraph lines. If they're
2242  // followed by two lines that look like body lines, make a paragraph
2243  // model for that and see if that model applies throughout the text
2244  // (that is, "smear" it).
2245  StrongEvidenceClassify(debug_level, &rows,
2246  leftovers[i].begin, leftovers[i].end, &theory);
2247 
2248  // Pass 2b:
2249  // If we had any luck in pass 2a, we got part of the page and didn't
2250  // know how to classify a few runs of rows. Take the segments that
2251  // didn't find a model and reprocess them individually.
2252  GenericVector<Interval> leftovers2;
2253  LeftoverSegments(rows, &leftovers2, leftovers[i].begin, leftovers[i].end);
2254  bool pass2a_was_useful = leftovers2.size() > 1 ||
2255  (leftovers2.size() == 1 &&
2256  (leftovers2[0].begin != 0 || leftovers2[0].end != rows.size()));
2257  if (pass2a_was_useful) {
2258  for (int j = 0; j < leftovers2.size(); j++) {
2259  StrongEvidenceClassify(debug_level, &rows,
2260  leftovers2[j].begin, leftovers2[j].end,
2261  &theory);
2262  }
2263  }
2264  }
2265 
2266  DebugDump(debug_level > 1, "End of Pass 2", theory, rows);
2267 
2268  // Pass 3:
2269  // These are the dregs for which we didn't have enough strong textual
2270  // and geometric clues to form matching models for. Let's see if
2271  // the geometric clues are simple enough that we could just use those.
2272  LeftoverSegments(rows, &leftovers, 0, rows.size());
2273  for (int i = 0; i < leftovers.size(); i++) {
2274  GeometricClassify(debug_level, &rows,
2275  leftovers[i].begin, leftovers[i].end, &theory);
2276  }
2277  // Undo any flush models for which there's little evidence.
2278  DowngradeWeakestToCrowns(debug_level, &theory, &rows);
2279 
2280  DebugDump(debug_level > 1, "End of Pass 3", theory, rows);
2281 
2282  // Pass 4:
2283  // Take everything that's still not marked up well and clear all markings.
2284  LeftoverSegments(rows, &leftovers, 0, rows.size());
2285  for (int i = 0; i < leftovers.size(); i++) {
2286  for (int j = leftovers[i].begin; j < leftovers[i].end; j++) {
2287  rows[j].SetUnknown();
2288  }
2289  }
2290 
2291  DebugDump(debug_level > 1, "End of Pass 4", theory, rows);
2292 
2293  // Convert all of the unique hypothesis runs to PARAs.
2294  ConvertHypothesizedModelRunsToParagraphs(debug_level, rows, row_owners,
2295  &theory);
2296 
2297  DebugDump(debug_level > 0, "Final Paragraph Segmentation", theory, rows);
2298 
2299  // Finally, clean up any dangling NULL row paragraph parents.
2300  CanonicalizeDetectionResults(row_owners, paragraphs);
2301 }
void LeftoverSegments(const GenericVector< RowScratchRegisters > &rows, GenericVector< Interval > *to_fix, int row_start, int row_end)
#define NULL
Definition: host.h:144
void ConvertHypothesizedModelRunsToParagraphs(int debug_level, const GenericVector< RowScratchRegisters > &rows, GenericVector< PARA * > *row_owners, ParagraphTheory *theory)
void StrongEvidenceClassify(int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
void SeparateSimpleLeaderLines(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
int size() const
Definition: genericvector.h:59
void DowngradeWeakestToCrowns(int debug_level, ParagraphTheory *theory, GenericVector< RowScratchRegisters > *rows)
void GeometricClassify(int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
void CanonicalizeDetectionResults(GenericVector< PARA * > *row_owners, PARA_LIST *paragraphs)
void init_to_size(int size, T t)
void tesseract::DetectParagraphs ( int  debug_level,
bool  after_text_recognition,
const MutableIterator *  block_start,
GenericVector< ParagraphModel * > *  models 
)

Definition at line 2454 of file paragraphs.cpp.

2457  {
2458  // Clear out any preconceived notions.
2459  if (block_start->Empty(RIL_TEXTLINE)) {
2460  return;
2461  }
2462  BLOCK *block = block_start->PageResIt()->block()->block;
2463  block->para_list()->clear();
2464  bool is_image_block = block->poly_block() && !block->poly_block()->IsText();
2465 
2466  // Convert the Tesseract structures to RowInfos
2467  // for the paragraph detection algorithm.
2468  MutableIterator row(*block_start);
2469  if (row.Empty(RIL_TEXTLINE))
2470  return; // end of input already.
2471 
2472  GenericVector<RowInfo> row_infos;
2473  do {
2474  if (!row.PageResIt()->row())
2475  continue; // empty row.
2476  row.PageResIt()->row()->row->set_para(NULL);
2477  row_infos.push_back(RowInfo());
2478  RowInfo &ri = row_infos.back();
2479  InitializeRowInfo(after_text_recognition, row, &ri);
2480  } while (!row.IsAtFinalElement(RIL_BLOCK, RIL_TEXTLINE) &&
2481  row.Next(RIL_TEXTLINE));
2482 
2483  // If we're called before text recognition, we might not have
2484  // tight block bounding boxes, so trim by the minimum on each side.
2485  if (row_infos.size() > 0) {
2486  int min_lmargin = row_infos[0].pix_ldistance;
2487  int min_rmargin = row_infos[0].pix_rdistance;
2488  for (int i = 1; i < row_infos.size(); i++) {
2489  if (row_infos[i].pix_ldistance < min_lmargin)
2490  min_lmargin = row_infos[i].pix_ldistance;
2491  if (row_infos[i].pix_rdistance < min_rmargin)
2492  min_rmargin = row_infos[i].pix_rdistance;
2493  }
2494  if (min_lmargin > 0 || min_rmargin > 0) {
2495  for (int i = 0; i < row_infos.size(); i++) {
2496  row_infos[i].pix_ldistance -= min_lmargin;
2497  row_infos[i].pix_rdistance -= min_rmargin;
2498  }
2499  }
2500  }
2501 
2502  // Run the paragraph detection algorithm.
2503  GenericVector<PARA *> row_owners;
2504  GenericVector<PARA *> the_paragraphs;
2505  if (!is_image_block) {
2506  DetectParagraphs(debug_level, &row_infos, &row_owners, block->para_list(),
2507  models);
2508  } else {
2509  row_owners.init_to_size(row_infos.size(), NULL);
2510  CanonicalizeDetectionResults(&row_owners, block->para_list());
2511  }
2512 
2513  // Now stitch in the row_owners into the rows.
2514  row = *block_start;
2515  for (int i = 0; i < row_owners.size(); i++) {
2516  while (!row.PageResIt()->row())
2517  row.Next(RIL_TEXTLINE);
2518  row.PageResIt()->row()->row->set_para(row_owners[i]);
2519  row.Next(RIL_TEXTLINE);
2520  }
2521 }
void DetectParagraphs(int debug_level, bool after_text_recognition, const MutableIterator *block_start, GenericVector< ParagraphModel * > *models)
#define NULL
Definition: host.h:144
int push_back(T object)
PARA_LIST * para_list()
Definition: ocrblock.h:129
void InitializeRowInfo(bool after_recognition, const MutableIterator &it, RowInfo *info)
POLY_BLOCK * poly_block() const
Definition: pdblock.h:62
Definition: ocrblock.h:31
int size() const
Definition: genericvector.h:59
T & back() const
Definition: capi.h:61
bool IsText() const
Definition: polyblk.h:54
void CanonicalizeDetectionResults(GenericVector< PARA * > *row_owners, PARA_LIST *paragraphs)
void init_to_size(int size, T t)
void tesseract::DiscardUnusedModels ( const GenericVector< RowScratchRegisters > &  rows,
ParagraphTheory *  theory 
)

Definition at line 1404 of file paragraphs.cpp.

1405  {
1406  SetOfModels used_models;
1407  for (int i = 0; i < rows.size(); i++) {
1408  rows[i].StrongHypotheses(&used_models);
1409  }
1410  theory->DiscardUnusedModels(used_models);
1411 }
int size() const
Definition: genericvector.h:59
GenericVectorEqEq< const ParagraphModel * > SetOfModels
void tesseract::DowngradeWeakestToCrowns ( int  debug_level,
ParagraphTheory *  theory,
GenericVector< RowScratchRegisters > *  rows 
)

Definition at line 1437 of file paragraphs.cpp.

1439  {
1440  int start;
1441  for (int end = rows->size(); end > 0; end = start) {
1442  // Search back for a body line of a unique type.
1443  const ParagraphModel *model = NULL;
1444  while (end > 0 &&
1445  (model = (*rows)[end - 1].UniqueBodyHypothesis()) == NULL) {
1446  end--;
1447  }
1448  if (end == 0) break;
1449  start = end - 1;
1450  while (start >= 0 && (*rows)[start].UniqueBodyHypothesis() == model) {
1451  start--; // walk back to the first line that is not the same body type.
1452  }
1453  if (start >= 0 && (*rows)[start].UniqueStartHypothesis() == model &&
1454  StrongModel(model) &&
1455  NearlyEqual(model->first_indent(), model->body_indent(),
1456  model->tolerance())) {
1457  start--;
1458  }
1459  start++;
1460  // Now rows[start, end) is a sequence of unique body hypotheses of model.
1461  if (StrongModel(model) && model->justification() == JUSTIFICATION_CENTER)
1462  continue;
1463  if (!StrongModel(model)) {
1464  while (start > 0 &&
1465  CrownCompatible(rows, start - 1, start, model))
1466  start--;
1467  }
1468  if (start == 0 ||
1469  (!StrongModel(model)) ||
1470  (StrongModel(model) && !ValidFirstLine(rows, start - 1, model))) {
1471  // crownify rows[start, end)
1472  const ParagraphModel *crown_model = model;
1473  if (StrongModel(model)) {
1474  if (model->justification() == JUSTIFICATION_LEFT)
1475  crown_model = kCrownLeft;
1476  else
1477  crown_model = kCrownRight;
1478  }
1479  (*rows)[start].SetUnknown();
1480  (*rows)[start].AddStartLine(crown_model);
1481  for (int row = start + 1; row < end; row++) {
1482  (*rows)[row].SetUnknown();
1483  (*rows)[row].AddBodyLine(crown_model);
1484  }
1485  }
1486  }
1487  DiscardUnusedModels(*rows, theory);
1488 }
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
int body_indent() const
Definition: ocrpara.h:169
#define NULL
Definition: host.h:144
bool CrownCompatible(const GenericVector< RowScratchRegisters > *rows, int a, int b, const ParagraphModel *model)
int first_indent() const
Definition: ocrpara.h:168
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:148
void DiscardUnusedModels(const GenericVector< RowScratchRegisters > &rows, ParagraphTheory *theory)
int size() const
Definition: genericvector.h:59
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
int tolerance() const
Definition: ocrpara.h:170
tesseract::ELISTIZE ( ViterbiStateEntry  )
tesseract::ELISTIZE ( AmbigSpec  )
tesseract::ELISTIZEH ( AmbigSpec  )
tesseract::ELISTIZEH ( ViterbiStateEntry  )
BLOB_CHOICE* tesseract::find_choice_by_script ( BLOB_CHOICE_LIST *  blob_choices,
int  target_sid,
int  backup_sid,
int  secondary_sid 
)

Iterate through all the character choices (for a single blob) and return the first that matches the target script ID. If backup_sid is not 0, then a match on either the target or backup sid is allowed. Note that there is no preference between a target or backup sid. To search for another sid only if no target_sid matched, use secondary_sid. So for example, to find first Han or Common char choice, do find_choice_by_script(cchoice, han_sid, common_sid, 0); To find first Han choice, but allow Common if none is found, do find_choice_by_script(cchoice, han_sid, 0, common_sid);

Definition at line 206 of file permute.cpp.

210  {
211  BLOB_CHOICE_IT c_it(blob_choices);
212  for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
213  bool found = false;
214  if (c_it.data()->script_id() == 0) continue;
215  if (c_it.data()->script_id() == target_sid) found = true;
216  if (backup_sid > 0 && c_it.data()->script_id() == backup_sid) found = true;
217  if (found) return c_it.data();
218  }
219  if (secondary_sid > 0) {
220  c_it.set_to_list(blob_choices);
221  for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
222  if (c_it.data()->script_id() == 0) continue;
223  if (c_it.data()->script_id() == secondary_sid)
224  return c_it.data();
225  }
226  }
227  return NULL;
228 }
#define NULL
Definition: host.h:144
BLOB_CHOICE* tesseract::find_choice_by_type ( BLOB_CHOICE_LIST *  blob_choices,
char  target_type,
const UNICHARSET unicharset 
)

Iterate through all the character choices (for a single blob) and return the first that matches the given type, which is one of 'aA0px*', for lower, upper, digit, punctuation, other, and 'any', respectively. If not match is found, a NULL is returned.

Definition at line 181 of file permute.cpp.

184  {
185  BLOB_CHOICE_IT c_it(blob_choices);
186  for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
187  if (c_it.data() &&
188  unicharset.get_chartype(c_it.data()->unichar_id()) == target_type)
189  return c_it.data();
190  }
191  return NULL;
192 }
#define NULL
Definition: host.h:144
char get_chartype(UNICHAR_ID unichar_id) const
Definition: unicharset.cpp:502
int tesseract::find_choice_by_uid ( BLOB_CHOICE_LIST *  blob_list,
UNICHAR_ID  target_uid 
)

Returns the rank (starting at 0) of a given unichar ID in the char choice list, or -1 if not found.

Definition at line 110 of file permute.cpp.

110  {
111  BLOB_CHOICE_IT c_it(blob_list);
112  int pos = 0;
113  while (1) {
114  if (c_it.data()->unichar_id() == target_uid) return pos;
115  if (c_it.at_last()) break;
116  c_it.forward();
117  pos++;
118  }
119  return -1;
120 }
bool tesseract::FirstWordWouldHaveFit ( const RowScratchRegisters &  before,
const RowScratchRegisters &  after,
tesseract::ParagraphJustification  justification 
)

Definition at line 1568 of file paragraphs.cpp.

1570  {
1571  if (before.ri_->num_words == 0 || after.ri_->num_words == 0)
1572  return true;
1573 
1574  if (justification == JUSTIFICATION_UNKNOWN) {
1575  tprintf("Don't call FirstWordWouldHaveFit(r, s, JUSTIFICATION_UNKNOWN).\n");
1576  }
1577  int available_space;
1578  if (justification == JUSTIFICATION_CENTER) {
1579  available_space = before.lindent_ + before.rindent_;
1580  } else {
1581  available_space = before.OffsideIndent(justification);
1582  }
1583  available_space -= before.ri_->average_interword_space;
1584 
1585  if (before.ri_->ltr)
1586  return after.ri_->lword_box.width() < available_space;
1587  return after.ri_->rword_box.width() < available_space;
1588 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
bool tesseract::FirstWordWouldHaveFit ( const RowScratchRegisters &  before,
const RowScratchRegisters &  after 
)

Definition at line 1593 of file paragraphs.cpp.

1594  {
1595  if (before.ri_->num_words == 0 || after.ri_->num_words == 0)
1596  return true;
1597 
1598  int available_space = before.lindent_;
1599  if (before.rindent_ > available_space)
1600  available_space = before.rindent_;
1601  available_space -= before.ri_->average_interword_space;
1602 
1603  if (before.ri_->ltr)
1604  return after.ri_->lword_box.width() < available_space;
1605  return after.ri_->rword_box.width() < available_space;
1606 }
void tesseract::FontInfoDeleteCallback ( FontInfo  f)

Definition at line 44 of file fontinfo.cpp.

44  {
45  if (f.spacing_vec != NULL) {
46  f.spacing_vec->delete_data_pointers();
47  delete f.spacing_vec;
48  }
49  delete[] f.name;
50 }
#define NULL
Definition: host.h:144
#define f(xc, yc)
Definition: imgscale.cpp:39
void tesseract::FontSetDeleteCallback ( FontSet  fs)

Definition at line 51 of file fontinfo.cpp.

51  {
52  delete[] fs.configs;
53 }
void tesseract::GeometricClassify ( int  debug_level,
GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory *  theory 
)

Definition at line 1028 of file paragraphs.cpp.

1031  {
1032  if (!AcceptableRowArgs(debug_level, 4, __func__, rows, row_start, row_end))
1033  return;
1034  if (debug_level > 1) {
1035  tprintf("###############################################\n");
1036  tprintf("##### GeometricClassify( rows[%d:%d) ) ####\n",
1037  row_start, row_end);
1038  tprintf("###############################################\n");
1039  }
1040  RecomputeMarginsAndClearHypotheses(rows, row_start, row_end, 10);
1041 
1042  GeometricClassifierState s(debug_level, rows, row_start, row_end);
1043  if (s.left_tabs.size() > 2 && s.right_tabs.size() > 2) {
1044  s.Fail(2, "Too much variety for simple outline classification.");
1045  return;
1046  }
1047  if (s.left_tabs.size() <= 1 && s.right_tabs.size() <= 1) {
1048  s.Fail(1, "Not enough variety for simple outline classification.");
1049  return;
1050  }
1051  if (s.left_tabs.size() + s.right_tabs.size() == 3) {
1052  GeometricClassifyThreeTabStopTextBlock(debug_level, s, theory);
1053  return;
1054  }
1055 
1056  // At this point, we know that one side has at least two tab stops, and the
1057  // other side has one or two tab stops.
1058  // Left to determine:
1059  // (1) Which is the body indent and which is the first line indent?
1060  // (2) Is the text fully justified?
1061 
1062  // If one side happens to have three or more tab stops, assume that side
1063  // is opposite of the aligned side.
1064  if (s.right_tabs.size() > 2) {
1065  s.AssumeLeftJustification();
1066  } else if (s.left_tabs.size() > 2) {
1067  s.AssumeRightJustification();
1068  } else if (s.ltr) { // guess based on script direction
1069  s.AssumeLeftJustification();
1070  } else {
1071  s.AssumeRightJustification();
1072  }
1073 
1074  if (s.AlignTabs().size() == 2) {
1075  // For each tab stop on the aligned side, how many of them appear
1076  // to be paragraph start lines? [first lines]
1077  int firsts[2] = {0, 0};
1078  // Count the first line as a likely paragraph start line.
1079  firsts[s.AlignsideTabIndex(s.row_start)]++;
1080  // For each line, if the first word would have fit on the previous
1081  // line count it as a likely paragraph start line.
1082  for (int i = s.row_start + 1; i < s.row_end; i++) {
1083  if (s.FirstWordWouldHaveFit(i - 1, i)) {
1084  firsts[s.AlignsideTabIndex(i)]++;
1085  }
1086  }
1087  // Make an extra accounting for the last line of the paragraph just
1088  // in case it's the only short line in the block. That is, take its
1089  // first word as typical and see if this looks like the *last* line
1090  // of a paragraph. If so, mark the *other* indent as probably a first.
1091  if (s.FirstWordWouldHaveFit(s.row_end - 1, s.row_end - 1)) {
1092  firsts[1 - s.AlignsideTabIndex(s.row_end - 1)]++;
1093  }
1094 
1095  int percent0firsts, percent1firsts;
1096  percent0firsts = (100 * firsts[0]) / s.AlignTabs()[0].count;
1097  percent1firsts = (100 * firsts[1]) / s.AlignTabs()[1].count;
1098 
1099  // TODO(eger): Tune these constants if necessary.
1100  if ((percent0firsts < 20 && 30 < percent1firsts) ||
1101  percent0firsts + 30 < percent1firsts) {
1102  s.first_indent = s.AlignTabs()[1].center;
1103  s.body_indent = s.AlignTabs()[0].center;
1104  } else if ((percent1firsts < 20 && 30 < percent0firsts) ||
1105  percent1firsts + 30 < percent0firsts) {
1106  s.first_indent = s.AlignTabs()[0].center;
1107  s.body_indent = s.AlignTabs()[1].center;
1108  } else {
1109  // Ambiguous! Probably lineated (poetry)
1110  if (debug_level > 1) {
1111  tprintf("# Cannot determine %s indent likely to start paragraphs.\n",
1112  s.just == tesseract::JUSTIFICATION_LEFT ? "left" : "right");
1113  tprintf("# Indent of %d looks like a first line %d%% of the time.\n",
1114  s.AlignTabs()[0].center, percent0firsts);
1115  tprintf("# Indent of %d looks like a first line %d%% of the time.\n",
1116  s.AlignTabs()[1].center, percent1firsts);
1117  s.PrintRows();
1118  }
1119  return;
1120  }
1121  } else {
1122  // There's only one tab stop for the "aligned to" side.
1123  s.first_indent = s.body_indent = s.AlignTabs()[0].center;
1124  }
1125 
1126  // At this point, we have our model.
1127  const ParagraphModel *model = theory->AddModel(s.Model());
1128 
1129  // Now all we have to do is figure out if the text is fully justified or not.
1130  // eop_threshold: default to fully justified unless we see evidence below.
1131  // See description on MarkRowsWithModel()
1132  s.eop_threshold =
1133  (s.OffsideTabs()[0].center + s.OffsideTabs()[1].center) / 2;
1134  // If the text is not fully justified, re-set the eop_threshold to 0.
1135  if (s.AlignTabs().size() == 2) {
1136  // Paragraphs with a paragraph-start indent.
1137  for (int i = s.row_start; i < s.row_end - 1; i++) {
1138  if (ValidFirstLine(s.rows, i + 1, model) &&
1139  !NearlyEqual(s.OffsideTabs()[0].center,
1140  (*s.rows)[i].OffsideIndent(s.just), s.tolerance)) {
1141  // We found a non-end-of-paragraph short line: not fully justified.
1142  s.eop_threshold = 0;
1143  break;
1144  }
1145  }
1146  } else {
1147  // Paragraphs with no paragraph-start indent.
1148  for (int i = s.row_start; i < s.row_end - 1; i++) {
1149  if (!s.FirstWordWouldHaveFit(i, i + 1) &&
1150  !NearlyEqual(s.OffsideTabs()[0].center,
1151  (*s.rows)[i].OffsideIndent(s.just), s.tolerance)) {
1152  // We found a non-end-of-paragraph short line: not fully justified.
1153  s.eop_threshold = 0;
1154  break;
1155  }
1156  }
1157  }
1158  MarkRowsWithModel(rows, row_start, row_end, model, s.ltr, s.eop_threshold);
1159 }
void GeometricClassifyThreeTabStopTextBlock(int debug_level, GeometricClassifierState &s, ParagraphTheory *theory)
Definition: paragraphs.cpp:936
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:148
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void MarkRowsWithModel(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, const ParagraphModel *model, bool ltr, int eop_threshold)
Definition: paragraphs.cpp:763
void RecomputeMarginsAndClearHypotheses(GenericVector< RowScratchRegisters > *rows, int start, int end, int percentile)
void tesseract::GeometricClassifyThreeTabStopTextBlock ( int  debug_level,
GeometricClassifierState &  s,
ParagraphTheory *  theory 
)

Definition at line 936 of file paragraphs.cpp.

939  {
940  int num_rows = s.row_end - s.row_start;
941  int num_full_rows = 0;
942  int last_row_full = 0;
943  for (int i = s.row_start; i < s.row_end; i++) {
944  if (s.IsFullRow(i)) {
945  num_full_rows++;
946  if (i == s.row_end - 1) last_row_full++;
947  }
948  }
949 
950  if (num_full_rows < 0.7 * num_rows) {
951  s.Fail(1, "Not enough full lines to know which lines start paras.");
952  return;
953  }
954 
955  // eop_threshold gets set if we're fully justified; see MarkRowsWithModel()
956  s.eop_threshold = 0;
957 
958  if (s.ltr) {
959  s.AssumeLeftJustification();
960  } else {
961  s.AssumeRightJustification();
962  }
963 
964  if (debug_level > 0) {
965  tprintf("# Not enough variety for clear outline classification. "
966  "Guessing these are %s aligned based on script.\n",
967  s.ltr ? "left" : "right");
968  s.PrintRows();
969  }
970 
971  if (s.AlignTabs().size() == 2) { // case A1 or A2
972  s.first_indent = s.AlignTabs()[1].center;
973  s.body_indent = s.AlignTabs()[0].center;
974  } else { // case B1 or B2
975  if (num_rows - 1 == num_full_rows - last_row_full) {
976  // case B2
977  const ParagraphModel *model = s.ltr ? kCrownLeft : kCrownRight;
978  (*s.rows)[s.row_start].AddStartLine(model);
979  for (int i = s.row_start + 1; i < s.row_end; i++) {
980  (*s.rows)[i].AddBodyLine(model);
981  }
982  return;
983  } else {
984  // case B1
985  s.first_indent = s.body_indent = s.AlignTabs()[0].center;
986  s.eop_threshold = (s.OffsideTabs()[0].center +
987  s.OffsideTabs()[1].center) / 2;
988  }
989  }
990  const ParagraphModel *model = theory->AddModel(s.Model());
991  MarkRowsWithModel(s.rows, s.row_start, s.row_end, model,
992  s.ltr, s.eop_threshold);
993  return;
994 }
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
int first_indent() const
Definition: ocrpara.h:168
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void MarkRowsWithModel(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, const ParagraphModel *model, bool ltr, int eop_threshold)
Definition: paragraphs.cpp:763
WERD_CHOICE* tesseract::get_best_delete_other ( WERD_CHOICE choice1,
WERD_CHOICE choice2 
)

get_best_delete_other

Returns the best of two choices and deletes the other (worse) choice. A choice is better if it has a non-empty string and has a lower rating than the other choice. If the ratings are the same, choice2 is preferred over choice1.

Definition at line 74 of file permute.cpp.

75  {
76  if (!choice1) return choice2;
77  if (!choice2) return choice1;
78  if (choice1->rating() < choice2->rating() || choice2->length() == 0) {
79  delete choice2;
80  return choice1;
81  } else {
82  delete choice1;
83  return choice2;
84  }
85 }
int length() const
Definition: ratngs.h:214
float rating() const
Definition: ratngs.h:231
WERD_CHOICE* tesseract::get_choice_from_posstr ( const UNICHARSET unicharset,
const BLOB_CHOICE_LIST_VECTOR char_choices,
int  start_pos,
const char *  pos_str,
float *  certainties 
)

Returns a WERD formed by taking the specified position (nth choice) string from char_choices starting at the given position. For example, if start_pos=2, pos_str="0121" will form a word using the 1st choice of char 3, 2nd choice of char 4, 3rd choice of char 5, 2nd choice of char 6. If n > number of choice, the closest (last) one is used.

Definition at line 129 of file permute.cpp.

133  {
134  int pos_str_len = strlen(pos_str);
135  WERD_CHOICE* wchoice = new WERD_CHOICE(unicharset);
136  if (start_pos + pos_str_len > char_choices.length()) {
137  wchoice->make_bad();
138  return wchoice;
139  }
140  for (int x = 0; x < pos_str_len; x++) {
141  int pos = pos_str[x]-'0';
142  if (pos < 0) pos = 0; // use the top choice by default, eg. '.'
143  if (pos >= 10)
144  tprintf("PosStr[%d](%d)=%c %d\n", x, pos_str_len, pos_str[x], pos);
145  ASSERT_HOST(pos < 10);
146  BLOB_CHOICE* blob_it = get_nth_choice(char_choices.get(start_pos+x), pos);
147  wchoice->set_permuter(NO_PERM);
148  wchoice->append_unichar_id(blob_it->unichar_id(), 1,
149  blob_it->rating(),
150  blob_it->certainty());
151  if (certainties != NULL) certainties[x] = blob_it->certainty();
152  }
153  return wchoice;
154 }
void append_unichar_id(UNICHAR_ID unichar_id, char fragment_length, float rating, float certainty)
Definition: ratngs.cpp:313
void make_bad()
Set the fields in this choice to be default (bad) values.
Definition: ratngs.h:321
BLOB_CHOICE * get_nth_choice(BLOB_CHOICE_LIST *blob_list, int n)
Definition: permute.cpp:91
#define NULL
Definition: host.h:144
T & get(int index) const
UNICHAR_ID unichar_id() const
Definition: ratngs.h:59
float certainty() const
Definition: ratngs.h:65
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
int length() const
Definition: genericvector.h:63
#define ASSERT_HOST(x)
Definition: errcode.h:84
void set_permuter(uinT8 perm)
Definition: ratngs.h:261
float rating() const
Definition: ratngs.h:62
BLOB_CHOICE* tesseract::get_nth_choice ( BLOB_CHOICE_LIST *  blob_list,
int  n 
)

Returns the n-th choice in the given blob_list (top-K choices). If n > K, the last choice is returned.

Definition at line 91 of file permute.cpp.

91  {
92  BLOB_CHOICE_IT c_it(blob_list);
93  while (n-- > 0 && !c_it.at_last())
94  c_it.forward();
95  return c_it.data();
96 }
void tesseract::get_posstr_from_choice ( const BLOB_CHOICE_LIST_VECTOR char_choices,
WERD_CHOICE word_choice,
int  start_pos,
char *  pos_str 
)

Given a WERD_CHOICE, find the corresponding position string from char_choices. Pos_str must have been allocated already. This is the reverse of get_choice_from_posstr.

Definition at line 161 of file permute.cpp.

164  {
165  for (int i = 0; i < word_choice->length(); i++) {
166  UNICHAR_ID target_id = word_choice->unichar_id(i);
167  BLOB_CHOICE_LIST* blob_choice_list = char_choices.get(start_pos + i);
168  int pos = find_choice_by_uid(blob_choice_list, target_id);
169  if (pos < 0) pos = 0;
170  pos_str[i] = pos + '0';
171  }
172  pos_str[word_choice->length()] = '\0';
173 }
int length() const
Definition: ratngs.h:214
int find_choice_by_uid(BLOB_CHOICE_LIST *blob_list, UNICHAR_ID target_uid)
Definition: permute.cpp:110
int UNICHAR_ID
Definition: unichar.h:31
T & get(int index) const
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
UNICHAR_ID tesseract::get_top_choice_uid ( BLOB_CHOICE_LIST *  blob_list)

Returns the top choice char id. A helper function to make code cleaner.

Definition at line 99 of file permute.cpp.

99  {
100  if (!blob_list) return INVALID_UNICHAR_ID;
101  BLOB_CHOICE_IT blob_choice_it(blob_list);
102  return (blob_choice_it.data()) ? blob_choice_it.data()->unichar_id()
103  : INVALID_UNICHAR_ID;
104 }
Pix* tesseract::GridReducedPix ( const TBOX box,
int  gridsize,
ICOORD  bleft,
int *  left,
int *  bottom 
)

Definition at line 212 of file bbgrid.cpp.

213  {
214  // Compute grid bounds of the outline and pad all round by 1.
215  int grid_left = (box.left() - bleft.x()) / gridsize - 1;
216  int grid_bottom = (box.bottom() - bleft.y()) / gridsize - 1;
217  int grid_right = (box.right() - bleft.x()) / gridsize + 1;
218  int grid_top = (box.top() - bleft.y()) / gridsize + 1;
219  *left = grid_left;
220  *bottom = grid_bottom;
221  return pixCreate(grid_right - grid_left + 1,
222  grid_top - grid_bottom + 1,
223  1);
224 }
inT16 x() const
access function
Definition: points.h:52
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 y() const
access_function
Definition: points.h:56
inT16 top() const
Definition: rect.h:53
inT16 bottom() const
Definition: rect.h:60
void tesseract::HistogramRect ( const unsigned char *  imagedata,
int  bytes_per_pixel,
int  bytes_per_line,
int  left,
int  top,
int  width,
int  height,
int *  histogram 
)

Definition at line 93 of file otsuthr.cpp.

96  {
97  int bottom = top + height;
98  memset(histogram, 0, sizeof(*histogram) * kHistogramSize);
99  const unsigned char* pixels = imagedata +
100  top * bytes_per_line +
101  left * bytes_per_pixel;
102  for (int y = top; y < bottom; ++y) {
103  for (int x = 0; x < width; ++x) {
104  ++histogram[pixels[x * bytes_per_pixel]];
105  }
106  pixels += bytes_per_line;
107  }
108 }
const int kHistogramSize
Definition: otsuthr.h:25
void tesseract::InitializeRowInfo ( bool  after_recognition,
const MutableIterator &  it,
RowInfo *  info 
)

Definition at line 2356 of file paragraphs.cpp.

2358  {
2359  if (it.PageResIt()->row() != NULL) {
2360  ROW *row = it.PageResIt()->row()->row;
2361  info->pix_ldistance = row->lmargin();
2362  info->pix_rdistance = row->rmargin();
2363  info->average_interword_space =
2364  row->space() > 0 ? row->space() : MAX(row->x_height(), 1);
2365  info->pix_xheight = row->x_height();
2366  info->has_leaders = false;
2367  info->has_drop_cap = row->has_drop_cap();
2368  info->ltr = true; // set below depending on word scripts
2369  } else {
2370  info->pix_ldistance = info->pix_rdistance = 0;
2371  info->average_interword_space = 1;
2372  info->pix_xheight = 1.0;
2373  info->has_leaders = false;
2374  info->has_drop_cap = false;
2375  info->ltr = true;
2376  }
2377 
2378  info->num_words = 0;
2379  info->lword_indicates_list_item = false;
2380  info->lword_likely_starts_idea = false;
2381  info->lword_likely_ends_idea = false;
2382  info->rword_indicates_list_item = false;
2383  info->rword_likely_starts_idea = false;
2384  info->rword_likely_ends_idea = false;
2385  info->has_leaders = false;
2386  info->ltr = 1;
2387 
2388  if (!after_recognition) {
2390  return;
2391  }
2392  info->text = "";
2393  char *text = it.GetUTF8Text(RIL_TEXTLINE);
2394  int trailing_ws_idx = strlen(text); // strip trailing space
2395  while (trailing_ws_idx > 0 &&
2396  // isspace() only takes ASCII
2397  ((text[trailing_ws_idx - 1] & 0x80) == 0) &&
2398  isspace(text[trailing_ws_idx - 1]))
2399  trailing_ws_idx--;
2400  if (trailing_ws_idx > 0) {
2401  int lspaces = info->pix_ldistance / info->average_interword_space;
2402  for (int i = 0; i < lspaces; i++)
2403  info->text += ' ';
2404  for (int i = 0; i < trailing_ws_idx; i++)
2405  info->text += text[i];
2406  }
2407  delete []text;
2408 
2409  if (info->text.size() == 0) {
2410  return;
2411  }
2412 
2413  PAGE_RES_IT page_res_it = *it.PageResIt();
2415  WERD_RES *word_res = page_res_it.restart_row();
2416  ROW_RES *this_row = page_res_it.row();
2417  int num_leaders = 0;
2418  int ltr = 0;
2419  int rtl = 0;
2420  do {
2421  if (word_res && word_res->best_choice->unichar_string().length() > 0) {
2422  werds.push_back(word_res);
2423  ltr += word_res->AnyLtrCharsInWord() ? 1 : 0;
2424  rtl += word_res->AnyRtlCharsInWord() ? 1 : 0;
2425  if (word_res->word->flag(W_REP_CHAR)) num_leaders++;
2426  }
2427  word_res = page_res_it.forward();
2428  } while (page_res_it.row() == this_row);
2429  info->ltr = ltr >= rtl;
2430  info->has_leaders = num_leaders > 3;
2431  info->num_words = werds.size();
2432  if (werds.size() > 0) {
2433  WERD_RES *lword = werds[0], *rword = werds[werds.size() - 1];
2434  info->lword_text = lword->best_choice->unichar_string().string();
2435  info->rword_text = rword->best_choice->unichar_string().string();
2436  info->lword_box = lword->word->bounding_box();
2437  info->rword_box = rword->word->bounding_box();
2438  LeftWordAttributes(lword->uch_set, lword->best_choice,
2439  info->lword_text,
2440  &info->lword_indicates_list_item,
2441  &info->lword_likely_starts_idea,
2442  &info->lword_likely_ends_idea);
2443  RightWordAttributes(rword->uch_set, rword->best_choice,
2444  info->rword_text,
2445  &info->rword_indicates_list_item,
2446  &info->rword_likely_starts_idea,
2447  &info->rword_likely_ends_idea);
2448  }
2449 }
const STRING & unichar_string() const
Definition: ratngs.h:395
TBOX bounding_box()
Definition: werd.cpp:164
ROW_RES * row() const
Definition: pageres.h:760
inT32 length() const
Definition: strngs.cpp:151
inT16 rmargin() const
Definition: ocrrow.h:98
void LeftWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd, const STRING &utf8, bool *is_list, bool *starts_idea, bool *ends_idea)
Definition: paragraphs.cpp:406
#define NULL
Definition: host.h:144
int push_back(T object)
inT16 lmargin() const
Definition: ocrrow.h:95
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:122
WERD_RES * restart_row()
Definition: pageres.cpp:1100
inT32 space() const
Definition: ocrrow.h:76
WERD * word
Definition: pageres.h:334
const UNICHARSET * uch_set
Definition: pageres.h:348
Definition: ocrrow.h:32
const char * string() const
Definition: strngs.cpp:156
void RightWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd, const STRING &utf8, bool *is_list, bool *starts_idea, bool *ends_idea)
Definition: paragraphs.cpp:453
bool has_drop_cap() const
Definition: ocrrow.h:105
WERD_RES * forward()
Definition: pageres.h:737
float x_height() const
Definition: ocrrow.h:61
bool AnyLtrCharsInWord() const
Definition: pageres.h:523
int size() const
Definition: genericvector.h:59
bool AnyRtlCharsInWord() const
Definition: pageres.h:506
#define MAX(x, y)
Definition: ndminx.h:24
WERD_CHOICE * best_choice
Definition: pageres.h:359
void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, RowInfo *info)
void tesseract::InitializeTextAndBoxesPreRecognition ( const MutableIterator &  it,
RowInfo *  info 
)

Definition at line 2305 of file paragraphs.cpp.

2306  {
2307  // Set up text, lword_text, and rword_text (mostly for debug printing).
2308  STRING fake_text;
2309  PageIterator pit(static_cast<const PageIterator&>(it));
2310  bool first_word = true;
2311  if (!pit.Empty(RIL_WORD)) {
2312  do {
2313  fake_text += "x";
2314  if (first_word) info->lword_text += "x";
2315  info->rword_text += "x";
2316  if (pit.IsAtFinalElement(RIL_WORD, RIL_SYMBOL) &&
2317  !pit.IsAtFinalElement(RIL_TEXTLINE, RIL_SYMBOL)) {
2318  fake_text += " ";
2319  info->rword_text = "";
2320  first_word = false;
2321  }
2322  } while (!pit.IsAtFinalElement(RIL_TEXTLINE, RIL_SYMBOL) &&
2323  pit.Next(RIL_SYMBOL));
2324  }
2325  if (fake_text.size() == 0) return;
2326 
2327  int lspaces = info->pix_ldistance / info->average_interword_space;
2328  for (int i = 0; i < lspaces; i++) {
2329  info->text += ' ';
2330  }
2331  info->text += fake_text;
2332 
2333  // Set up lword_box, rword_box, and num_words.
2334  PAGE_RES_IT page_res_it = *it.PageResIt();
2335  WERD_RES *word_res = page_res_it.restart_row();
2336  ROW_RES *this_row = page_res_it.row();
2337 
2338  WERD_RES *lword = NULL;
2339  WERD_RES *rword = NULL;
2340  info->num_words = 0;
2341  do {
2342  if (word_res) {
2343  if (!lword) lword = word_res;
2344  if (rword != word_res) info->num_words++;
2345  rword = word_res;
2346  }
2347  word_res = page_res_it.forward();
2348  } while (page_res_it.row() == this_row);
2349  info->lword_box = lword->word->bounding_box();
2350  info->rword_box = rword->word->bounding_box();
2351 }
TBOX bounding_box()
Definition: werd.cpp:164
ROW_RES * row() const
Definition: pageres.h:760
#define NULL
Definition: host.h:144
WERD_RES * restart_row()
Definition: pageres.cpp:1100
WERD * word
Definition: pageres.h:334
inT32 size() const
Definition: strngs.h:56
WERD_RES * forward()
Definition: pageres.h:737
Definition: strngs.h:40
Definition: capi.h:61
ParagraphModel tesseract::InternalParagraphModelByOutline ( const GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
int  tolerance,
bool *  consistent 
)

Definition at line 1639 of file paragraphs.cpp.

1641  {
1642  int ltr_line_count = 0;
1643  for (int i = start; i < end; i++) {
1644  ltr_line_count += static_cast<int>((*rows)[i].ri_->ltr);
1645  }
1646  bool ltr = (ltr_line_count >= (end - start) / 2);
1647 
1648  *consistent = true;
1649  if (!AcceptableRowArgs(0, 2, __func__, rows, start, end))
1650  return ParagraphModel();
1651 
1652  // Ensure the caller only passed us a region with a common rmargin and
1653  // lmargin.
1654  int lmargin = (*rows)[start].lmargin_;
1655  int rmargin = (*rows)[start].rmargin_;
1656  int lmin, lmax, rmin, rmax, cmin, cmax;
1657  lmin = lmax = (*rows)[start + 1].lindent_;
1658  rmin = rmax = (*rows)[start + 1].rindent_;
1659  cmin = cmax = 0;
1660  for (int i = start + 1; i < end; i++) {
1661  if ((*rows)[i].lmargin_ != lmargin || (*rows)[i].rmargin_ != rmargin) {
1662  tprintf("Margins don't match! Software error.\n");
1663  *consistent = false;
1664  return ParagraphModel();
1665  }
1666  UpdateRange((*rows)[i].lindent_, &lmin, &lmax);
1667  UpdateRange((*rows)[i].rindent_, &rmin, &rmax);
1668  UpdateRange((*rows)[i].rindent_ - (*rows)[i].lindent_, &cmin, &cmax);
1669  }
1670  int ldiff = lmax - lmin;
1671  int rdiff = rmax - rmin;
1672  int cdiff = cmax - cmin;
1673  if (rdiff > tolerance && ldiff > tolerance) {
1674  if (cdiff < tolerance * 2) {
1675  if (end - start < 3)
1676  return ParagraphModel();
1677  return ParagraphModel(JUSTIFICATION_CENTER, 0, 0, 0, tolerance);
1678  }
1679  *consistent = false;
1680  return ParagraphModel();
1681  }
1682  if (end - start < 3) // Don't return a model for two line paras.
1683  return ParagraphModel();
1684 
1685  // These booleans keep us from saying something is aligned left when the body
1686  // left variance is too large.
1687  bool body_admits_left_alignment = ldiff < tolerance;
1688  bool body_admits_right_alignment = rdiff < tolerance;
1689 
1690  ParagraphModel left_model =
1691  ParagraphModel(JUSTIFICATION_LEFT, lmargin, (*rows)[start].lindent_,
1692  (lmin + lmax) / 2, tolerance);
1693  ParagraphModel right_model =
1694  ParagraphModel(JUSTIFICATION_RIGHT, rmargin, (*rows)[start].rindent_,
1695  (rmin + rmax) / 2, tolerance);
1696 
1697  // These booleans keep us from having an indent on the "wrong side" for the
1698  // first line.
1699  bool text_admits_left_alignment = ltr || left_model.is_flush();
1700  bool text_admits_right_alignment = !ltr || right_model.is_flush();
1701 
1702  // At least one of the edges is less than tolerance in variance.
1703  // If the other is obviously ragged, it can't be the one aligned to.
1704  // [Note the last line is included in this raggedness.]
1705  if (tolerance < rdiff) {
1706  if (body_admits_left_alignment && text_admits_left_alignment)
1707  return left_model;
1708  *consistent = false;
1709  return ParagraphModel();
1710  }
1711  if (tolerance < ldiff) {
1712  if (body_admits_right_alignment && text_admits_right_alignment)
1713  return right_model;
1714  *consistent = false;
1715  return ParagraphModel();
1716  }
1717 
1718  // At this point, we know the body text doesn't vary much on either side.
1719 
1720  // If the first line juts out oddly in one direction or the other,
1721  // that likely indicates the side aligned to.
1722  int first_left = (*rows)[start].lindent_;
1723  int first_right = (*rows)[start].rindent_;
1724 
1725  if (ltr && body_admits_left_alignment &&
1726  (first_left < lmin || first_left > lmax))
1727  return left_model;
1728  if (!ltr && body_admits_right_alignment &&
1729  (first_right < rmin || first_right > rmax))
1730  return right_model;
1731 
1732  *consistent = false;
1733  return ParagraphModel();
1734 }
bool is_flush() const
Definition: ocrpara.h:171
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:74
int tesseract::InterwordSpace ( const GenericVector< RowScratchRegisters > &  rows,
int  row_start,
int  row_end 
)

Definition at line 1547 of file paragraphs.cpp.

1548  {
1549  if (row_end < row_start + 1) return 1;
1550  bool legit = false;
1551  int natural_space = rows[row_start].ri_->average_interword_space;
1552  for (int i = row_start; i < row_end; i++) {
1553  if (rows[i].ri_->num_words > 1) {
1554  if (!legit) {
1555  natural_space = rows[i].ri_->average_interword_space;
1556  legit = true;
1557  } else {
1558  if (rows[i].ri_->average_interword_space < natural_space)
1559  natural_space = rows[i].ri_->average_interword_space;
1560  }
1561  }
1562  }
1563  return natural_space;
1564 }
bool tesseract::IsDigitLike ( int  ch)

Definition at line 209 of file paragraphs.cpp.

209  {
210  return ch == 'o' || ch == 'O' || ch == 'l' || ch == 'I';
211 }
bool tesseract::IsLatinLetter ( int  ch)

Definition at line 205 of file paragraphs.cpp.

205  {
206  return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
207 }
bool tesseract::IsLeftIndented ( const EquationDetect::IndentType  type)
inline

Definition at line 95 of file equationdetect.cpp.

95  {
96  return type == EquationDetect::LEFT_INDENT ||
97  type == EquationDetect::BOTH_INDENT;
98 }
bool tesseract::IsOpeningPunct ( int  ch)

Definition at line 213 of file paragraphs.cpp.

213  {
214  return strchr("'\"({[", ch) != NULL;
215 }
#define NULL
Definition: host.h:144
bool tesseract::IsRightIndented ( const EquationDetect::IndentType  type)
inline

Definition at line 100 of file equationdetect.cpp.

100  {
101  return type == EquationDetect::RIGHT_INDENT ||
102  type == EquationDetect::BOTH_INDENT;
103 }
bool tesseract::IsTerminalPunct ( int  ch)

Definition at line 217 of file paragraphs.cpp.

217  {
218  return strchr(":'\".?!]})", ch) != NULL;
219 }
#define NULL
Definition: host.h:144
bool tesseract::IsTextOrEquationType ( PolyBlockType  type)
inline

Definition at line 91 of file equationdetect.cpp.

91  {
92  return PTIsTextType(type) || type == PT_EQUATION;
93 }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70
void tesseract::LeftoverSegments ( const GenericVector< RowScratchRegisters > &  rows,
GenericVector< Interval > *  to_fix,
int  row_start,
int  row_end 
)

Definition at line 2128 of file paragraphs.cpp.

2130  {
2131  to_fix->clear();
2132  for (int i = row_start; i < row_end; i++) {
2133  bool needs_fixing = false;
2134 
2135  SetOfModels models;
2136  SetOfModels models_w_crowns;
2137  rows[i].StrongHypotheses(&models);
2138  rows[i].NonNullHypotheses(&models_w_crowns);
2139  if (models.empty() && models_w_crowns.size() > 0) {
2140  // Crown paragraph. Is it followed by a modeled line?
2141  for (int end = i + 1; end < rows.size(); end++) {
2142  SetOfModels end_models;
2143  SetOfModels strong_end_models;
2144  rows[end].NonNullHypotheses(&end_models);
2145  rows[end].StrongHypotheses(&strong_end_models);
2146  if (end_models.size() == 0) {
2147  needs_fixing = true;
2148  break;
2149  } else if (strong_end_models.size() > 0) {
2150  needs_fixing = false;
2151  break;
2152  }
2153  }
2154  } else if (models.empty() && rows[i].ri_->num_words > 0) {
2155  // No models at all.
2156  needs_fixing = true;
2157  }
2158 
2159  if (!needs_fixing && !models.empty()) {
2160  needs_fixing = RowIsStranded(rows, i);
2161  }
2162 
2163  if (needs_fixing) {
2164  if (!to_fix->empty() && to_fix->back().end == i - 1)
2165  to_fix->back().end = i;
2166  else
2167  to_fix->push_back(Interval(i, i));
2168  }
2169  }
2170  // Convert inclusive intervals to half-open intervals.
2171  for (int i = 0; i < to_fix->size(); i++) {
2172  (*to_fix)[i].end = (*to_fix)[i].end + 1;
2173  }
2174 }
virtual void clear()
bool RowIsStranded(const GenericVector< RowScratchRegisters > &rows, int row)
int push_back(T object)
bool empty() const
Definition: genericvector.h:68
int size() const
Definition: genericvector.h:59
T & back() const
GenericVectorEqEq< const ParagraphModel * > SetOfModels
void tesseract::LeftWordAttributes ( const UNICHARSET unicharset,
const WERD_CHOICE werd,
const STRING utf8,
bool *  is_list,
bool *  starts_idea,
bool *  ends_idea 
)

Definition at line 406 of file paragraphs.cpp.

408  {
409  *is_list = false;
410  *starts_idea = false;
411  *ends_idea = false;
412  if (utf8.size() == 0 || (werd != NULL && werd->length() == 0)) { // Empty
413  *ends_idea = true;
414  return;
415  }
416 
417  if (unicharset && werd) { // We have a proper werd and unicharset so use it.
418  if (UniLikelyListItem(unicharset, werd)) {
419  *is_list = true;
420  *starts_idea = true;
421  *ends_idea = true;
422  }
423  if (unicharset->get_isupper(werd->unichar_id(0))) {
424  *starts_idea = true;
425  }
426  if (unicharset->get_ispunctuation(werd->unichar_id(0))) {
427  *starts_idea = true;
428  *ends_idea = true;
429  }
430  } else { // Assume utf8 is mostly ASCII
431  if (AsciiLikelyListItem(utf8)) {
432  *is_list = true;
433  *starts_idea = true;
434  }
435  int start_letter = utf8[0];
436  if (IsOpeningPunct(start_letter)) {
437  *starts_idea = true;
438  }
439  if (IsTerminalPunct(start_letter)) {
440  *ends_idea = true;
441  }
442  if (start_letter >= 'A' && start_letter <= 'Z') {
443  *starts_idea = true;
444  }
445  }
446 }
int length() const
Definition: ratngs.h:214
bool UniLikelyListItem(const UNICHARSET *u, const WERD_CHOICE *werd)
Definition: paragraphs.cpp:369
bool IsOpeningPunct(int ch)
Definition: paragraphs.cpp:213
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:420
#define NULL
Definition: host.h:144
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:406
bool IsTerminalPunct(int ch)
Definition: paragraphs.cpp:217
inT32 size() const
Definition: strngs.h:56
bool AsciiLikelyListItem(const STRING &word)
Definition: paragraphs.cpp:279
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
bool tesseract::LikelyListMark ( const STRING word)

Definition at line 274 of file paragraphs.cpp.

274  {
275  const char *kListMarks = "0Oo*.,+.";
276  return word.size() == 1 && strchr(kListMarks, word[0]) != NULL;
277 }
#define NULL
Definition: host.h:144
inT32 size() const
Definition: strngs.h:56
bool tesseract::LikelyListMarkUnicode ( int  ch)

Definition at line 340 of file paragraphs.cpp.

340  {
341  if (ch < 0x80) {
342  STRING single_ch;
343  single_ch += ch;
344  return LikelyListMark(single_ch);
345  }
346  switch (ch) {
347  // TODO(eger) expand this list of unicodes as needed.
348  case 0x00B0: // degree sign
349  case 0x2022: // bullet
350  case 0x25E6: // white bullet
351  case 0x00B7: // middle dot
352  case 0x25A1: // white square
353  case 0x25A0: // black square
354  case 0x25AA: // black small square
355  case 0x2B1D: // black very small square
356  case 0x25BA: // black right-pointing pointer
357  case 0x25CF: // black circle
358  case 0x25CB: // white circle
359  return true;
360  default:
361  break; // fall through
362  }
363  return false;
364 }
Definition: strngs.h:40
bool LikelyListMark(const STRING &word)
Definition: paragraphs.cpp:274
bool tesseract::LikelyListNumeral ( const STRING word)

Definition at line 240 of file paragraphs.cpp.

240  {
241  const char *kRomans = "ivxlmdIVXLMD";
242  const char *kDigits = "012345789";
243  const char *kOpen = "[{(";
244  const char *kSep = ":;-.,";
245  const char *kClose = "]})";
246 
247  int num_segments = 0;
248  const char *pos = word.string();
249  while (*pos != '\0' && num_segments < 3) {
250  // skip up to two open parens.
251  const char *numeral_start = SkipOne(SkipOne(pos, kOpen), kOpen);
252  const char *numeral_end = SkipChars(numeral_start, kRomans);
253  if (numeral_end != numeral_start) {
254  // Got Roman Numeral. Great.
255  } else {
256  numeral_end = SkipChars(numeral_start, kDigits);
257  if (numeral_end == numeral_start) {
258  // If there's a single latin letter, we can use that.
259  numeral_end = SkipChars(numeral_start, IsLatinLetter);
260  if (numeral_end - numeral_start != 1)
261  break;
262  }
263  }
264  // We got some sort of numeral.
265  num_segments++;
266  // Skip any trailing parens or punctuation.
267  pos = SkipChars(SkipChars(numeral_end, kClose), kSep);
268  if (pos == numeral_end)
269  break;
270  }
271  return *pos == '\0';
272 }
const char * SkipOne(const char *str, const char *toskip)
Definition: paragraphs.cpp:232
const char * string() const
Definition: strngs.cpp:156
const char * SkipChars(const char *str, bool(*skip)(int))
Definition: paragraphs.cpp:227
bool IsLatinLetter(int ch)
Definition: paragraphs.cpp:205
bool tesseract::LikelyParagraphStart ( const RowScratchRegisters &  before,
const RowScratchRegisters &  after 
)

Definition at line 1619 of file paragraphs.cpp.

1620  {
1621  return before.ri_->num_words == 0 ||
1622  (FirstWordWouldHaveFit(before, after) &&
1623  TextSupportsBreak(before, after));
1624 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool TextSupportsBreak(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool tesseract::LikelyParagraphStart ( const RowScratchRegisters &  before,
const RowScratchRegisters &  after,
tesseract::ParagraphJustification  j 
)

Definition at line 1626 of file paragraphs.cpp.

1628  {
1629  return before.ri_->num_words == 0 ||
1630  (FirstWordWouldHaveFit(before, after, j) &&
1631  TextSupportsBreak(before, after));
1632 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool TextSupportsBreak(const RowScratchRegisters &before, const RowScratchRegisters &after)
ShapeTable * tesseract::LoadShapeTable ( const STRING file_prefix)

Definition at line 183 of file commontraining.cpp.

183  {
184  ShapeTable* shape_table = NULL;
185  STRING shape_table_file = file_prefix;
186  shape_table_file += kShapeTableFileSuffix;
187  FILE* shape_fp = fopen(shape_table_file.string(), "rb");
188  if (shape_fp != NULL) {
189  shape_table = new ShapeTable;
190  if (!shape_table->DeSerialize(false, shape_fp)) {
191  delete shape_table;
192  shape_table = NULL;
193  tprintf("Error: Failed to read shape table %s\n",
194  shape_table_file.string());
195  } else {
196  int num_shapes = shape_table->NumShapes();
197  tprintf("Read shape table %s of %d shapes\n",
198  shape_table_file.string(), num_shapes);
199  }
200  fclose(shape_fp);
201  } else {
202  tprintf("Warning: No shape table file present: %s\n",
203  shape_table_file.string());
204  }
205  return shape_table;
206 }
int NumShapes() const
Definition: shapetable.h:140
#define NULL
Definition: host.h:144
const char * string() const
Definition: strngs.cpp:156
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
bool DeSerialize(bool swap, FILE *fp)
Definition: shapetable.cpp:188
Definition: strngs.h:40
MasterTrainer * tesseract::LoadTrainingData ( int  argc,
const char *const *  argv,
bool  replication,
ShapeTable **  shape_table,
STRING file_prefix 
)

Definition at line 238 of file commontraining.cpp.

241  {
243  InitIntegerFX();
244  *file_prefix = "";
245  if (!FLAGS_D.empty()) {
246  *file_prefix += FLAGS_D.c_str();
247  *file_prefix += "/";
248  }
249  // If we are shape clustering (NULL shape_table) or we successfully load
250  // a shape_table written by a previous shape clustering, then
251  // shape_analysis will be true, meaning that the MasterTrainer will replace
252  // some members of the unicharset with their fragments.
253  bool shape_analysis = false;
254  if (shape_table != NULL) {
255  *shape_table = LoadShapeTable(*file_prefix);
256  if (*shape_table != NULL)
257  shape_analysis = true;
258  } else {
259  shape_analysis = true;
260  }
261  MasterTrainer* trainer = new MasterTrainer(NM_CHAR_ANISOTROPIC,
262  shape_analysis,
263  replication,
264  FLAGS_debug_level);
265  if (FLAGS_input_trainer.empty()) {
266  trainer->LoadUnicharset(FLAGS_U.c_str());
267  // Get basic font information from font_properties.
268  if (!FLAGS_F.empty()) {
269  if (!trainer->LoadFontInfo(FLAGS_F.c_str())) {
270  delete trainer;
271  return NULL;
272  }
273  }
274  if (!FLAGS_X.empty()) {
275  if (!trainer->LoadXHeights(FLAGS_X.c_str())) {
276  delete trainer;
277  return NULL;
278  }
279  }
280  IntFeatureSpace fs;
282  trainer->SetFeatureSpace(fs);
283  const char* page_name;
284  // Load training data from .tr files on the command line.
285  while ((page_name = GetNextFilename(argc, argv)) != NULL) {
286  tprintf("Reading %s ...\n", page_name);
287  FILE* fp = Efopen(page_name, "rb");
288  trainer->ReadTrainingSamples(fp, feature_defs, false);
289  fclose(fp);
290 
291  // If there is a file with [lang].[fontname].exp[num].fontinfo present,
292  // read font spacing information in to fontinfo_table.
293  int pagename_len = strlen(page_name);
294  char *fontinfo_file_name = new char[pagename_len + 7];
295  strncpy(fontinfo_file_name, page_name, pagename_len - 2); // remove "tr"
296  strcpy(fontinfo_file_name + pagename_len - 2, "fontinfo"); // +"fontinfo"
297  trainer->AddSpacingInfo(fontinfo_file_name);
298  delete[] fontinfo_file_name;
299 
300  // Load the images into memory if required by the classifier.
301  if (FLAGS_load_images) {
302  STRING image_name = page_name;
303  // Chop off the tr and replace with tif. Extension must be tif!
304  image_name.truncate_at(image_name.length() - 2);
305  image_name += "tif";
306  trainer->LoadPageImages(image_name.string());
307  }
308  }
309  trainer->PostLoadCleanup();
310  // Write the master trainer if required.
311  if (!FLAGS_output_trainer.empty()) {
312  FILE* fp = fopen(FLAGS_output_trainer.c_str(), "wb");
313  if (fp == NULL) {
314  tprintf("Can't create saved trainer data!\n");
315  } else {
316  trainer->Serialize(fp);
317  fclose(fp);
318  }
319  }
320  } else {
321  bool success = false;
322  tprintf("Loading master trainer from file:%s\n",
323  FLAGS_input_trainer.c_str());
324  FILE* fp = fopen(FLAGS_input_trainer.c_str(), "rb");
325  if (fp == NULL) {
326  tprintf("Can't read file %s to initialize master trainer\n",
327  FLAGS_input_trainer.c_str());
328  } else {
329  success = trainer->DeSerialize(false, fp);
330  fclose(fp);
331  }
332  if (!success) {
333  tprintf("Deserialize of master trainer failed!\n");
334  delete trainer;
335  return NULL;
336  }
337  }
338  trainer->PreTrainingSetup();
339  if (!FLAGS_O.empty() &&
340  !trainer->unicharset().save_to_file(FLAGS_O.c_str())) {
341  fprintf(stderr, "Failed to save unicharset to file %s\n", FLAGS_O.c_str());
342  delete trainer;
343  return NULL;
344  }
345  if (shape_table != NULL) {
346  // If we previously failed to load a shapetable, then shape clustering
347  // wasn't run so make a flat one now.
348  if (*shape_table == NULL) {
349  *shape_table = new ShapeTable;
350  trainer->SetupFlatShapeTable(*shape_table);
351  tprintf("Flat shape table summary: %s\n",
352  (*shape_table)->SummaryStr().string());
353  }
354  (*shape_table)->set_unicharset(trainer->unicharset());
355  }
356  return trainer;
357 }
void truncate_at(inT32 index)
Definition: strngs.cpp:223
ShapeTable * LoadShapeTable(const STRING &file_prefix)
inT32 length() const
Definition: strngs.cpp:151
void InitIntegerFX()
Definition: intfx.cpp:74
#define NULL
Definition: host.h:144
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs)
Definition: featdefs.cpp:121
FILE * Efopen(const char *Name, const char *Mode)
Definition: efio.cpp:32
const int kBoostDirBuckets
const int kBoostXYBuckets
const char * string() const
Definition: strngs.cpp:156
void Init(uinT8 xbuckets, uinT8 ybuckets, uinT8 thetabuckets)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
Definition: strngs.h:40
const char * GetNextFilename(int argc, const char *const *argv)
FEATURE_DEFS_STRUCT feature_defs
TBLOB* tesseract::make_tesseract_blob ( float  baseline,
float  xheight,
float  descender,
float  ascender,
bool  numeric_mode,
Pix *  pix 
)

Return a TBLOB * from the whole pix. To be freed later with delete.

Definition at line 1916 of file baseapi.cpp.

1918  {
1919  TBLOB *tblob = TessBaseAPI::MakeTBLOB(pix);
1920 
1921  // Normalize TBLOB
1922  ROW *row =
1923  TessBaseAPI::MakeTessOCRRow(baseline, xheight, descender, ascender);
1924  TessBaseAPI::NormalizeTBLOB(tblob, row, numeric_mode, NULL);
1925  delete row;
1926  return tblob;
1927 }
#define NULL
Definition: host.h:144
Definition: ocrrow.h:32
Definition: blobs.h:174
void tesseract::MarkRowsWithModel ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
const ParagraphModel model,
bool  ltr,
int  eop_threshold 
)

Definition at line 763 of file paragraphs.cpp.

767  {
768  if (!AcceptableRowArgs(0, 0, __func__, rows, row_start, row_end))
769  return;
770  for (int row = row_start; row < row_end; row++) {
771  bool valid_first = ValidFirstLine(rows, row, model);
772  bool valid_body = ValidBodyLine(rows, row, model);
773  if (valid_first && !valid_body) {
774  (*rows)[row].AddStartLine(model);
775  } else if (valid_body && !valid_first) {
776  (*rows)[row].AddBodyLine(model);
777  } else if (valid_body && valid_first) {
778  bool after_eop = (row == row_start);
779  if (row > row_start) {
780  if (eop_threshold > 0) {
781  if (model->justification() == JUSTIFICATION_LEFT) {
782  after_eop = (*rows)[row - 1].rindent_ > eop_threshold;
783  } else {
784  after_eop = (*rows)[row - 1].lindent_ > eop_threshold;
785  }
786  } else {
787  after_eop = FirstWordWouldHaveFit((*rows)[row - 1], (*rows)[row],
788  model->justification());
789  }
790  }
791  if (after_eop) {
792  (*rows)[row].AddStartLine(model);
793  } else {
794  (*rows)[row].AddBodyLine(model);
795  }
796  } else {
797  // Do nothing. Stray row.
798  }
799  }
800 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
void tesseract::MarkStrongEvidence ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end 
)

Definition at line 1777 of file paragraphs.cpp.

1778  {
1779  // Record patently obvious body text.
1780  for (int i = row_start + 1; i < row_end; i++) {
1781  const RowScratchRegisters &prev = (*rows)[i - 1];
1782  RowScratchRegisters &curr = (*rows)[i];
1783  tesseract::ParagraphJustification typical_justification =
1784  prev.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1785  if (!curr.ri_->rword_likely_starts_idea &&
1786  !curr.ri_->lword_likely_starts_idea &&
1787  !FirstWordWouldHaveFit(prev, curr, typical_justification)) {
1788  curr.SetBodyLine();
1789  }
1790  }
1791 
1792  // Record patently obvious start paragraph lines.
1793  //
1794  // It's an extremely good signal of the start of a paragraph that
1795  // the first word would have fit on the end of the previous line.
1796  // However, applying just that signal would have us mark random
1797  // start lines of lineated text (poetry and source code) and some
1798  // centered headings as paragraph start lines. Therefore, we use
1799  // a second qualification for a paragraph start: Not only should
1800  // the first word of this line have fit on the previous line,
1801  // but also, this line should go full to the right of the block,
1802  // disallowing a subsequent word from having fit on this line.
1803 
1804  // First row:
1805  {
1806  RowScratchRegisters &curr = (*rows)[row_start];
1807  RowScratchRegisters &next = (*rows)[row_start + 1];
1809  curr.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1810  if (curr.GetLineType() == LT_UNKNOWN &&
1811  !FirstWordWouldHaveFit(curr, next, j) &&
1812  (curr.ri_->lword_likely_starts_idea ||
1813  curr.ri_->rword_likely_starts_idea)) {
1814  curr.SetStartLine();
1815  }
1816  }
1817  // Middle rows
1818  for (int i = row_start + 1; i < row_end - 1; i++) {
1819  RowScratchRegisters &prev = (*rows)[i - 1];
1820  RowScratchRegisters &curr = (*rows)[i];
1821  RowScratchRegisters &next = (*rows)[i + 1];
1823  curr.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1824  if (curr.GetLineType() == LT_UNKNOWN &&
1825  !FirstWordWouldHaveFit(curr, next, j) &&
1826  LikelyParagraphStart(prev, curr, j)) {
1827  curr.SetStartLine();
1828  }
1829  }
1830  // Last row
1831  { // the short circuit at the top means we have at least two lines.
1832  RowScratchRegisters &prev = (*rows)[row_end - 2];
1833  RowScratchRegisters &curr = (*rows)[row_end - 1];
1835  curr.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1836  if (curr.GetLineType() == LT_UNKNOWN &&
1837  !FirstWordWouldHaveFit(curr, curr, j) &&
1838  LikelyParagraphStart(prev, curr, j)) {
1839  curr.SetStartLine();
1840  }
1841  }
1842 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool LikelyParagraphStart(const RowScratchRegisters &before, const RowScratchRegisters &after, tesseract::ParagraphJustification j)
ParagraphJustification
Definition: publictypes.h:217
void tesseract::ModelStrongEvidence ( int  debug_level,
GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
bool  allow_flush_models,
ParagraphTheory *  theory 
)

Definition at line 1847 of file paragraphs.cpp.

1851  {
1852  if (!AcceptableRowArgs(debug_level, 2, __func__, rows, row_start, row_end))
1853  return;
1854 
1855  int start = row_start;
1856  while (start < row_end) {
1857  while (start < row_end && (*rows)[start].GetLineType() != LT_START)
1858  start++;
1859  if (start >= row_end - 1)
1860  break;
1861 
1862  int tolerance = Epsilon((*rows)[start + 1].ri_->average_interword_space);
1863  int end = start;
1864  ParagraphModel last_model;
1865  bool next_consistent;
1866  do {
1867  ++end;
1868  // rows[row, end) was consistent.
1869  // If rows[row, end + 1) is not consistent,
1870  // just model rows[row, end)
1871  if (end < row_end - 1) {
1872  RowScratchRegisters &next = (*rows)[end];
1873  LineType lt = next.GetLineType();
1874  next_consistent = lt == LT_BODY ||
1875  (lt == LT_UNKNOWN &&
1876  !FirstWordWouldHaveFit((*rows)[end - 1], (*rows)[end]));
1877  } else {
1878  next_consistent = false;
1879  }
1880  if (next_consistent) {
1882  rows, start, end + 1, tolerance, &next_consistent);
1883  if (((*rows)[start].ri_->ltr &&
1884  last_model.justification() == JUSTIFICATION_LEFT &&
1885  next_model.justification() != JUSTIFICATION_LEFT) ||
1886  (!(*rows)[start].ri_->ltr &&
1887  last_model.justification() == JUSTIFICATION_RIGHT &&
1888  next_model.justification() != JUSTIFICATION_RIGHT)) {
1889  next_consistent = false;
1890  }
1891  last_model = next_model;
1892  } else {
1893  next_consistent = false;
1894  }
1895  } while (next_consistent && end < row_end);
1896  // At this point, rows[start, end) looked like it could have been a
1897  // single paragraph. If we can make a good ParagraphModel for it,
1898  // do so and mark this sequence with that model.
1899  if (end > start + 1) {
1900  // emit a new paragraph if we have more than one line.
1901  const ParagraphModel *model = NULL;
1903  debug_level, rows, start, end,
1904  Epsilon(InterwordSpace(*rows, start, end)));
1905  if (new_model.justification() == JUSTIFICATION_UNKNOWN) {
1906  // couldn't create a good model, oh well.
1907  } else if (new_model.is_flush()) {
1908  if (end == start + 2) {
1909  // It's very likely we just got two paragraph starts in a row.
1910  end = start + 1;
1911  } else if (start == row_start) {
1912  // Mark this as a Crown.
1913  if (new_model.justification() == JUSTIFICATION_LEFT) {
1914  model = kCrownLeft;
1915  } else {
1916  model = kCrownRight;
1917  }
1918  } else if (allow_flush_models) {
1919  model = theory->AddModel(new_model);
1920  }
1921  } else {
1922  model = theory->AddModel(new_model);
1923  }
1924  if (model) {
1925  (*rows)[start].AddStartLine(model);
1926  for (int i = start + 1; i < end; i++) {
1927  (*rows)[i].AddBodyLine(model);
1928  }
1929  }
1930  }
1931  start = end;
1932  }
1933 }
bool is_flush() const
Definition: ocrpara.h:171
ParagraphModel InternalParagraphModelByOutline(const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance, bool *consistent)
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
int InterwordSpace(const GenericVector< RowScratchRegisters > &rows, int row_start, int row_end)
#define NULL
Definition: host.h:144
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
ParagraphModel ParagraphModelByOutline(int debug_level, const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance)
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
int tesseract::OtsuStats ( const int *  histogram,
int *  H_out,
int *  omega0_out 
)

Definition at line 113 of file otsuthr.cpp.

113  {
114  int H = 0;
115  double mu_T = 0.0;
116  for (int i = 0; i < kHistogramSize; ++i) {
117  H += histogram[i];
118  mu_T += static_cast<double>(i) * histogram[i];
119  }
120 
121  // Now maximize sig_sq_B over t.
122  // http://www.ctie.monash.edu.au/hargreave/Cornall_Terry_328.pdf
123  int best_t = -1;
124  int omega_0, omega_1;
125  int best_omega_0 = 0;
126  double best_sig_sq_B = 0.0;
127  double mu_0, mu_1, mu_t;
128  omega_0 = 0;
129  mu_t = 0.0;
130  for (int t = 0; t < kHistogramSize - 1; ++t) {
131  omega_0 += histogram[t];
132  mu_t += t * static_cast<double>(histogram[t]);
133  if (omega_0 == 0)
134  continue;
135  omega_1 = H - omega_0;
136  if (omega_1 == 0)
137  break;
138  mu_0 = mu_t / omega_0;
139  mu_1 = (mu_T - mu_t) / omega_1;
140  double sig_sq_B = mu_1 - mu_0;
141  sig_sq_B *= sig_sq_B * omega_0 * omega_1;
142  if (best_t < 0 || sig_sq_B > best_sig_sq_B) {
143  best_sig_sq_B = sig_sq_B;
144  best_t = t;
145  best_omega_0 = omega_0;
146  }
147  }
148  if (H_out != NULL) *H_out = H;
149  if (omega0_out != NULL) *omega0_out = best_omega_0;
150  return best_t;
151 }
#define NULL
Definition: host.h:144
const int kHistogramSize
Definition: otsuthr.h:25
void tesseract::OtsuThreshold ( const unsigned char *  imagedata,
int  bytes_per_pixel,
int  bytes_per_line,
int  left,
int  top,
int  width,
int  height,
int **  thresholds,
int **  hi_values 
)

Definition at line 32 of file otsuthr.cpp.

35  {
36  // Of all channels with no good hi_value, keep the best so we can always
37  // produce at least one answer.
38  int best_hi_value = 1;
39  int best_hi_index = 0;
40  bool any_good_hivalue = false;
41  double best_hi_dist = 0.0;
42  *thresholds = new int[bytes_per_pixel];
43  *hi_values = new int[bytes_per_pixel];
44 
45  for (int ch = 0; ch < bytes_per_pixel; ++ch) {
46  (*thresholds)[ch] = -1;
47  (*hi_values)[ch] = -1;
48  // Compute the histogram of the image rectangle.
49  int histogram[kHistogramSize];
50  HistogramRect(imagedata + ch, bytes_per_pixel, bytes_per_line,
51  left, top, width, height, histogram);
52  int H;
53  int best_omega_0;
54  int best_t = OtsuStats(histogram, &H, &best_omega_0);
55  if (best_omega_0 == 0 || best_omega_0 == H) {
56  // This channel is empty.
57  continue;
58  }
59  // To be a convincing foreground we must have a small fraction of H
60  // or to be a convincing background we must have a large fraction of H.
61  // In between we assume this channel contains no thresholding information.
62  int hi_value = best_omega_0 < H * 0.5;
63  (*thresholds)[ch] = best_t;
64  if (best_omega_0 > H * 0.75) {
65  any_good_hivalue = true;
66  (*hi_values)[ch] = 0;
67  } else if (best_omega_0 < H * 0.25) {
68  any_good_hivalue = true;
69  (*hi_values)[ch] = 1;
70  } else {
71  // In case all channels are like this, keep the best of the bad lot.
72  double hi_dist = hi_value ? (H - best_omega_0) : best_omega_0;
73  if (hi_dist > best_hi_dist) {
74  best_hi_dist = hi_dist;
75  best_hi_value = hi_value;
76  best_hi_index = ch;
77  }
78  }
79  }
80  if (!any_good_hivalue) {
81  // Use the best of the ones that were not good enough.
82  (*hi_values)[best_hi_index] = best_hi_value;
83  }
84 }
int OtsuStats(const int *histogram, int *H_out, int *omega0_out)
Definition: otsuthr.cpp:113
const int kHistogramSize
Definition: otsuthr.h:25
void HistogramRect(const unsigned char *imagedata, int bytes_per_pixel, int bytes_per_line, int left, int top, int width, int height, int *histogram)
Definition: otsuthr.cpp:93
ParagraphModel tesseract::ParagraphModelByOutline ( int  debug_level,
const GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
int  tolerance 
)

Definition at line 1740 of file paragraphs.cpp.

1743  {
1744  bool unused_consistent;
1746  rows, start, end, tolerance, &unused_consistent);
1747  if (debug_level >= 2 && retval.justification() == JUSTIFICATION_UNKNOWN) {
1748  tprintf("Could not determine a model for this paragraph:\n");
1749  PrintRowRange(*rows, start, end);
1750  }
1751  return retval;
1752 }
ParagraphModel InternalParagraphModelByOutline(const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance, bool *consistent)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
bool tesseract::read_info ( FILE *  f,
FontInfo *  fi,
bool  swap 
)

Definition at line 57 of file fontinfo.cpp.

57  {
58  inT32 size;
59  if (fread(&size, sizeof(size), 1, f) != 1) return false;
60  if (swap)
61  Reverse32(&size);
62  char* font_name = new char[size + 1];
63  fi->name = font_name;
64  if (fread(font_name, sizeof(*font_name), size, f) != size) return false;
65  font_name[size] = '\0';
66  if (fread(&fi->properties, sizeof(fi->properties), 1, f) != 1) return false;
67  if (swap)
68  Reverse32(&fi->properties);
69  return true;
70 }
void Reverse32(void *ptr)
Definition: helpers.h:142
int inT32
Definition: host.h:102
#define f(xc, yc)
Definition: imgscale.cpp:39
bool tesseract::read_set ( FILE *  f,
FontSet *  fs,
bool  swap 
)

Definition at line 140 of file fontinfo.cpp.

140  {
141  if (fread(&fs->size, sizeof(fs->size), 1, f) != 1) return false;
142  if (swap)
143  Reverse32(&fs->size);
144  fs->configs = new int[fs->size];
145  for (int i = 0; i < fs->size; ++i) {
146  if (fread(&fs->configs[i], sizeof(fs->configs[i]), 1, f) != 1) return false;
147  if (swap)
148  Reverse32(&fs->configs[i]);
149  }
150  return true;
151 }
void Reverse32(void *ptr)
Definition: helpers.h:142
#define f(xc, yc)
Definition: imgscale.cpp:39
bool tesseract::read_spacing_info ( FILE *  f,
FontInfo *  fi,
bool  swap 
)

Definition at line 80 of file fontinfo.cpp.

80  {
81  inT32 vec_size, kern_size;
82  if (fread(&vec_size, sizeof(vec_size), 1, f) != 1) return false;
83  if (swap) Reverse32(&vec_size);
84  ASSERT_HOST(vec_size >= 0);
85  if (vec_size == 0) return true;
86  fi->init_spacing(vec_size);
87  for (int i = 0; i < vec_size; ++i) {
88  FontSpacingInfo *fs = new FontSpacingInfo();
89  if (fread(&fs->x_gap_before, sizeof(fs->x_gap_before), 1, f) != 1 ||
90  fread(&fs->x_gap_after, sizeof(fs->x_gap_after), 1, f) != 1 ||
91  fread(&kern_size, sizeof(kern_size), 1, f) != 1) {
92  return false;
93  }
94  if (swap) {
95  ReverseN(&(fs->x_gap_before), sizeof(fs->x_gap_before));
96  ReverseN(&(fs->x_gap_after), sizeof(fs->x_gap_after));
97  Reverse32(&kern_size);
98  }
99  if (kern_size < 0) { // indication of a NULL entry in fi->spacing_vec
100  delete fs;
101  continue;
102  }
103  if (kern_size > 0 && (!fs->kerned_unichar_ids.DeSerialize(swap, f) ||
104  !fs->kerned_x_gaps.DeSerialize(swap, f))) {
105  return false;
106  }
107  fi->add_spacing(i, fs);
108  }
109  return true;
110 }
void Reverse32(void *ptr)
Definition: helpers.h:142
void ReverseN(void *ptr, int num_bytes)
Definition: helpers.h:126
int inT32
Definition: host.h:102
#define f(xc, yc)
Definition: imgscale.cpp:39
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool tesseract::read_t ( PAGE_RES_IT page_res_it,
TBOX tbox 
)

Definition at line 58 of file recogtraining.cpp.

58  {
59  while (page_res_it->block() != NULL) {
60  if (page_res_it->word() != NULL)
61  break;
62  page_res_it->forward();
63  }
64 
65  if (page_res_it->word() != NULL) {
66  *tbox = page_res_it->word()->word->bounding_box();
67  page_res_it->forward();
68 
69  // If tbox->left() is negative, the training image has vertical text and
70  // all the coordinates of bounding boxes of page_res are rotated by 90
71  // degrees in a counterclockwise direction. We need to rotate the TBOX back
72  // in order to compare with the TBOXes of box files.
73  if (tbox->left() < 0) {
74  tbox->rotate(FCOORD(0.0, -1.0));
75  }
76 
77  return true;
78  } else {
79  return false;
80  }
81 }
TBOX bounding_box()
Definition: werd.cpp:164
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
WERD_RES * word() const
Definition: pageres.h:757
BLOCK_RES * block() const
Definition: pageres.h:763
WERD * word
Definition: pageres.h:334
WERD_RES * forward()
Definition: pageres.h:737
Definition: points.h:189
void rotate(const FCOORD &vec)
Definition: rect.h:182
void tesseract::RecomputeMarginsAndClearHypotheses ( GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
int  percentile 
)

Definition at line 1507 of file paragraphs.cpp.

1509  {
1510  if (!AcceptableRowArgs(0, 0, __func__, rows, start, end))
1511  return;
1512 
1513  int lmin, lmax, rmin, rmax;
1514  lmin = lmax = (*rows)[start].lmargin_ + (*rows)[start].lindent_;
1515  rmin = rmax = (*rows)[start].rmargin_ + (*rows)[start].rindent_;
1516  for (int i = start; i < end; i++) {
1517  RowScratchRegisters &sr = (*rows)[i];
1518  sr.SetUnknown();
1519  if (sr.ri_->num_words == 0)
1520  continue;
1521  UpdateRange(sr.lmargin_ + sr.lindent_, &lmin, &lmax);
1522  UpdateRange(sr.rmargin_ + sr.rindent_, &rmin, &rmax);
1523  }
1524  STATS lefts(lmin, lmax + 1);
1525  STATS rights(rmin, rmax + 1);
1526  for (int i = start; i < end; i++) {
1527  RowScratchRegisters &sr = (*rows)[i];
1528  if (sr.ri_->num_words == 0)
1529  continue;
1530  lefts.add(sr.lmargin_ + sr.lindent_, 1);
1531  rights.add(sr.rmargin_ + sr.rindent_, 1);
1532  }
1533  int ignorable_left = lefts.ile(ClipToRange(percentile, 0, 100) / 100.0);
1534  int ignorable_right = rights.ile(ClipToRange(percentile, 0, 100) / 100.0);
1535  for (int i = start; i < end; i++) {
1536  RowScratchRegisters &sr = (*rows)[i];
1537  int ldelta = ignorable_left - sr.lmargin_;
1538  sr.lmargin_ += ldelta;
1539  sr.lindent_ -= ldelta;
1540  int rdelta = ignorable_right - sr.rmargin_;
1541  sr.rmargin_ += rdelta;
1542  sr.rindent_ -= rdelta;
1543  }
1544 }
Definition: statistc.h:29
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:74
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:64
void tesseract::RightWordAttributes ( const UNICHARSET unicharset,
const WERD_CHOICE werd,
const STRING utf8,
bool *  is_list,
bool *  starts_idea,
bool *  ends_idea 
)

Definition at line 453 of file paragraphs.cpp.

455  {
456  *is_list = false;
457  *starts_idea = false;
458  *ends_idea = false;
459  if (utf8.size() == 0 || (werd != NULL && werd->length() == 0)) { // Empty
460  *ends_idea = true;
461  return;
462  }
463 
464  if (unicharset && werd) { // We have a proper werd and unicharset so use it.
465  if (UniLikelyListItem(unicharset, werd)) {
466  *is_list = true;
467  *starts_idea = true;
468  }
469  UNICHAR_ID last_letter = werd->unichar_id(werd->length() - 1);
470  if (unicharset->get_ispunctuation(last_letter)) {
471  *ends_idea = true;
472  }
473  } else { // Assume utf8 is mostly ASCII
474  if (AsciiLikelyListItem(utf8)) {
475  *is_list = true;
476  *starts_idea = true;
477  }
478  int last_letter = utf8[utf8.size() - 1];
479  if (IsOpeningPunct(last_letter) || IsTerminalPunct(last_letter)) {
480  *ends_idea = true;
481  }
482  }
483 }
int length() const
Definition: ratngs.h:214
int UNICHAR_ID
Definition: unichar.h:31
bool UniLikelyListItem(const UNICHARSET *u, const WERD_CHOICE *werd)
Definition: paragraphs.cpp:369
bool IsOpeningPunct(int ch)
Definition: paragraphs.cpp:213
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:420
#define NULL
Definition: host.h:144
bool IsTerminalPunct(int ch)
Definition: paragraphs.cpp:217
inT32 size() const
Definition: strngs.h:56
bool AsciiLikelyListItem(const STRING &word)
Definition: paragraphs.cpp:279
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
bool tesseract::RowIsStranded ( const GenericVector< RowScratchRegisters > &  rows,
int  row 
)

Definition at line 2086 of file paragraphs.cpp.

2086  {
2087  SetOfModels row_models;
2088  rows[row].StrongHypotheses(&row_models);
2089 
2090  for (int m = 0; m < row_models.size(); m++) {
2091  bool all_starts = rows[row].GetLineType();
2092  int run_length = 1;
2093  bool continues = true;
2094  for (int i = row - 1; i >= 0 && continues; i--) {
2095  SetOfModels models;
2096  rows[i].NonNullHypotheses(&models);
2097  switch (rows[i].GetLineType(row_models[m])) {
2098  case LT_START: run_length++; break;
2099  case LT_MULTIPLE: // explicit fall-through
2100  case LT_BODY: run_length++; all_starts = false; break;
2101  case LT_UNKNOWN: // explicit fall-through
2102  default: continues = false;
2103  }
2104  }
2105  continues = true;
2106  for (int i = row + 1; i < rows.size() && continues; i++) {
2107  SetOfModels models;
2108  rows[i].NonNullHypotheses(&models);
2109  switch (rows[i].GetLineType(row_models[m])) {
2110  case LT_START: run_length++; break;
2111  case LT_MULTIPLE: // explicit fall-through
2112  case LT_BODY: run_length++; all_starts = false; break;
2113  case LT_UNKNOWN: // explicit fall-through
2114  default: continues = false;
2115  }
2116  }
2117  if (run_length > 2 || (!all_starts && run_length > 1)) return false;
2118  }
2119  return true;
2120 }
int size() const
Definition: genericvector.h:59
GenericVectorEqEq< const ParagraphModel * > SetOfModels
bool tesseract::RowsFitModel ( const GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
const ParagraphModel model 
)

Definition at line 1755 of file paragraphs.cpp.

1756  {
1757  if (!AcceptableRowArgs(0, 1, __func__, rows, start, end))
1758  return false;
1759  if (!ValidFirstLine(rows, start, model)) return false;
1760  for (int i = start + 1 ; i < end; i++) {
1761  if (!ValidBodyLine(rows, i, model)) return false;
1762  }
1763  return true;
1764 }
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
STRING tesseract::RtlEmbed ( const STRING word,
bool  rtlify 
)

Definition at line 133 of file paragraphs.cpp.

133  {
134  if (rtlify)
135  return STRING(kRLE) + word + STRING(kPDF);
136  return word;
137 }
const char * kRLE
Definition: unicodes.cpp:29
const char * kPDF
Definition: unicodes.cpp:30
Definition: strngs.h:40
void tesseract::SeparateSimpleLeaderLines ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory *  theory 
)

Definition at line 1972 of file paragraphs.cpp.

1974  {
1975  for (int i = row_start + 1; i < row_end - 1; i++) {
1976  if ((*rows)[i - 1].ri_->has_leaders &&
1977  (*rows)[i].ri_->has_leaders &&
1978  (*rows)[i + 1].ri_->has_leaders) {
1979  const ParagraphModel *model = theory->AddModel(
1980  ParagraphModel(JUSTIFICATION_UNKNOWN, 0, 0, 0, 0));
1981  (*rows)[i].AddStartLine(model);
1982  }
1983  }
1984 }
template<typename T >
void tesseract::SimpleSwap ( T &  a,
T &  b 
)

Definition at line 62 of file paragraphs.cpp.

62  {
63  T c = a;
64  a = b;
65  b = c;
66 }
const char* tesseract::SkipChars ( const char *  str,
const char *  toskip 
)

Definition at line 222 of file paragraphs.cpp.

222  {
223  while (*str != '\0' && strchr(toskip, *str)) { str++; }
224  return str;
225 }
const char* tesseract::SkipChars ( const char *  str,
bool(*)(int)  skip 
)

Definition at line 227 of file paragraphs.cpp.

227  {
228  while (*str != '\0' && skip(*str)) { str++; }
229  return str;
230 }
const char* tesseract::SkipOne ( const char *  str,
const char *  toskip 
)

Definition at line 232 of file paragraphs.cpp.

232  {
233  if (*str != '\0' && strchr(toskip, *str)) return str + 1;
234  return str;
235 }
template<typename T >
int tesseract::sort_cmp ( const void *  t1,
const void *  t2 
)

Definition at line 294 of file genericvector.h.

294  {
295  const T* a = static_cast<const T *> (t1);
296  const T* b = static_cast<const T *> (t2);
297  if (*a < *b) {
298  return -1;
299  } else if (*b < *a) {
300  return 1;
301  } else {
302  return 0;
303  }
304 }
template<typename T >
int tesseract::sort_ptr_cmp ( const void *  t1,
const void *  t2 
)

Definition at line 311 of file genericvector.h.

311  {
312  const T* a = *reinterpret_cast<T * const *>(t1);
313  const T* b = *reinterpret_cast<T * const *>(t2);
314  if (*a < *b) {
315  return -1;
316  } else if (*b < *a) {
317  return 1;
318  } else {
319  return 0;
320  }
321 }
template<class BBC >
int tesseract::SortByBoxBottom ( const void *  void1,
const void *  void2 
)

Definition at line 405 of file bbgrid.h.

405  {
406  // The void*s are actually doubly indirected, so get rid of one level.
407  const BBC* p1 = *reinterpret_cast<const BBC* const *>(void1);
408  const BBC* p2 = *reinterpret_cast<const BBC* const *>(void2);
409  int result = p1->bounding_box().bottom() - p2->bounding_box().bottom();
410  if (result != 0)
411  return result;
412  result = p1->bounding_box().top() - p2->bounding_box().top();
413  if (result != 0)
414  return result;
415  result = p1->bounding_box().left() - p2->bounding_box().left();
416  if (result != 0)
417  return result;
418  return p1->bounding_box().right() - p2->bounding_box().right();
419 }
template<class BBC >
int tesseract::SortByBoxLeft ( const void *  void1,
const void *  void2 
)

Definition at line 369 of file bbgrid.h.

369  {
370  // The void*s are actually doubly indirected, so get rid of one level.
371  const BBC* p1 = *reinterpret_cast<const BBC* const *>(void1);
372  const BBC* p2 = *reinterpret_cast<const BBC* const *>(void2);
373  int result = p1->bounding_box().left() - p2->bounding_box().left();
374  if (result != 0)
375  return result;
376  result = p1->bounding_box().right() - p2->bounding_box().right();
377  if (result != 0)
378  return result;
379  result = p1->bounding_box().bottom() - p2->bounding_box().bottom();
380  if (result != 0)
381  return result;
382  return p1->bounding_box().top() - p2->bounding_box().top();
383 }
template<class BLOB_CHOICE >
int tesseract::SortByRating ( const void *  void1,
const void *  void2 
)

Definition at line 116 of file pieces.cpp.

116  {
117  const BLOB_CHOICE *p1 = *reinterpret_cast<const BLOB_CHOICE * const *>(void1);
118  const BLOB_CHOICE *p2 = *reinterpret_cast<const BLOB_CHOICE * const *>(void2);
119 
120  if (p1->rating() < p2->rating())
121  return 1;
122  return -1;
123 }
float rating() const
Definition: ratngs.h:62
template<class BLOB_CHOICE >
int tesseract::SortByUnicharID ( const void *  void1,
const void *  void2 
)

Definition at line 108 of file pieces.cpp.

108  {
109  const BLOB_CHOICE *p1 = *reinterpret_cast<const BLOB_CHOICE * const *>(void1);
110  const BLOB_CHOICE *p2 = *reinterpret_cast<const BLOB_CHOICE * const *>(void2);
111 
112  return p1->unichar_id() - p2->unichar_id();
113 }
UNICHAR_ID unichar_id() const
Definition: ratngs.h:59
template<class BBC >
int tesseract::SortRightToLeft ( const void *  void1,
const void *  void2 
)

Definition at line 387 of file bbgrid.h.

387  {
388  // The void*s are actually doubly indirected, so get rid of one level.
389  const BBC* p1 = *reinterpret_cast<const BBC* const *>(void1);
390  const BBC* p2 = *reinterpret_cast<const BBC* const *>(void2);
391  int result = p2->bounding_box().right() - p1->bounding_box().right();
392  if (result != 0)
393  return result;
394  result = p2->bounding_box().left() - p1->bounding_box().left();
395  if (result != 0)
396  return result;
397  result = p1->bounding_box().bottom() - p2->bounding_box().bottom();
398  if (result != 0)
399  return result;
400  return p1->bounding_box().top() - p2->bounding_box().top();
401 }
void tesseract::StrongEvidenceClassify ( int  debug_level,
GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory *  theory 
)

Definition at line 1942 of file paragraphs.cpp.

1945  {
1946  if (!AcceptableRowArgs(debug_level, 2, __func__, rows, row_start, row_end))
1947  return;
1948 
1949  if (debug_level > 1) {
1950  tprintf("#############################################\n");
1951  tprintf("# StrongEvidenceClassify( rows[%d:%d) )\n", row_start, row_end);
1952  tprintf("#############################################\n");
1953  }
1954 
1955  RecomputeMarginsAndClearHypotheses(rows, row_start, row_end, 10);
1956  MarkStrongEvidence(rows, row_start, row_end);
1957 
1958  DebugDump(debug_level > 2, "Initial strong signals.", *theory, *rows);
1959 
1960  // Create paragraph models.
1961  ModelStrongEvidence(debug_level, rows, row_start, row_end, false, theory);
1962 
1963  DebugDump(debug_level > 2, "Unsmeared hypotheses.s.", *theory, *rows);
1964 
1965  // At this point, some rows are marked up as paragraphs with model numbers,
1966  // and some rows are marked up as either LT_START or LT_BODY. Now let's
1967  // smear any good paragraph hypotheses forward and backward.
1968  ParagraphModelSmearer smearer(rows, row_start, row_end, theory);
1969  smearer.Smear();
1970 }
void MarkStrongEvidence(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end)
void ModelStrongEvidence(int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, bool allow_flush_models, ParagraphTheory *theory)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void RecomputeMarginsAndClearHypotheses(GenericVector< RowScratchRegisters > *rows, int start, int end, int percentile)
bool tesseract::StrongModel ( const ParagraphModel model)
inline

Definition at line 75 of file paragraphs_internal.h.

75  {
76  return model != NULL && model != kCrownLeft && model != kCrownRight;
77 }
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
#define NULL
Definition: host.h:144
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
bool tesseract::TextSupportsBreak ( const RowScratchRegisters &  before,
const RowScratchRegisters &  after 
)

Definition at line 1608 of file paragraphs.cpp.

1609  {
1610  if (before.ri_->ltr) {
1611  return before.ri_->rword_likely_ends_idea &&
1612  after.ri_->lword_likely_starts_idea;
1613  } else {
1614  return before.ri_->lword_likely_ends_idea &&
1615  after.ri_->rword_likely_starts_idea;
1616  }
1617 }
Pix * tesseract::TraceBlockOnReducedPix ( BLOCK block,
int  gridsize,
ICOORD  bleft,
int *  left,
int *  bottom 
)

Definition at line 258 of file bbgrid.cpp.

259  {
260  TBOX box = block->bounding_box();
261  Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
262  int wpl = pixGetWpl(pix);
263  l_uint32* data = pixGetData(pix);
264  ICOORDELT_IT it(block->poly_block()->points());
265  for (it.mark_cycle_pt(); !it.cycled_list();) {
266  ICOORD pos = *it.data();
267  it.forward();
268  ICOORD next_pos = *it.data();
269  ICOORD line_vector = next_pos - pos;
270  int major, minor;
271  ICOORD major_step, minor_step;
272  line_vector.setup_render(&major_step, &minor_step, &major, &minor);
273  int accumulator = major / 2;
274  while (pos != next_pos) {
275  int grid_x = (pos.x() - bleft.x()) / gridsize - *left;
276  int grid_y = (pos.y() - bleft.y()) / gridsize - *bottom;
277  SET_DATA_BIT(data + grid_y * wpl, grid_x);
278  pos += major_step;
279  accumulator += minor;
280  if (accumulator >= major) {
281  accumulator -= major;
282  pos += minor_step;
283  }
284  }
285  }
286  return pix;
287 }
inT16 x() const
access function
Definition: points.h:52
Definition: rect.h:29
inT16 y() const
access_function
Definition: points.h:56
Pix * GridReducedPix(const TBOX &box, int gridsize, ICOORD bleft, int *left, int *bottom)
Definition: bbgrid.cpp:212
POLY_BLOCK * poly_block() const
Definition: pdblock.h:62
void setup_render(ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
Definition: points.cpp:83
integer coordinate
Definition: points.h:30
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:70
ICOORDELT_LIST * points()
Definition: polyblk.h:44
Pix * tesseract::TraceOutlineOnReducedPix ( C_OUTLINE outline,
int  gridsize,
ICOORD  bleft,
int *  left,
int *  bottom 
)

Definition at line 232 of file bbgrid.cpp.

233  {
234  TBOX box = outline->bounding_box();
235  Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
236  int wpl = pixGetWpl(pix);
237  l_uint32* data = pixGetData(pix);
238  int length = outline->pathlength();
239  ICOORD pos = outline->start_pos();
240  for (int i = 0; i < length; ++i) {
241  int grid_x = (pos.x() - bleft.x()) / gridsize - *left;
242  int grid_y = (pos.y() - bleft.y()) / gridsize - *bottom;
243  SET_DATA_BIT(data + grid_y * wpl, grid_x);
244  pos += outline->step(i);
245  }
246  return pix;
247 }
inT16 x() const
access function
Definition: points.h:52
const ICOORD & start_pos() const
Definition: coutln.h:108
ICOORD step(inT16 index) const
Definition: coutln.h:120
const TBOX & bounding_box() const
Definition: coutln.h:85
Definition: rect.h:29
inT16 y() const
access_function
Definition: points.h:56
Pix * GridReducedPix(const TBOX &box, int gridsize, ICOORD bleft, int *left, int *bottom)
Definition: bbgrid.cpp:212
inT32 pathlength() const
Definition: coutln.h:111
integer coordinate
Definition: points.h:30
int tesseract::UnicodeFor ( const UNICHARSET u,
const WERD_CHOICE werd,
int  pos 
)

Definition at line 286 of file paragraphs.cpp.

286  {
287  if (!u || !werd || pos > werd->length())
288  return 0;
289  return UNICHAR(u->id_to_unichar(werd->unichar_id(pos)), -1).first_uni();
290 }
int length() const
Definition: ratngs.h:214
const char *const id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:233
int first_uni() const
Definition: unichar.cpp:94
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
bool tesseract::UniLikelyListItem ( const UNICHARSET u,
const WERD_CHOICE werd 
)

Definition at line 369 of file paragraphs.cpp.

369  {
370  if (werd->length() == 1 && LikelyListMarkUnicode(UnicodeFor(u, werd, 0)))
371  return true;
372 
373  UnicodeSpanSkipper m(u, werd);
374  int num_segments = 0;
375  int pos = 0;
376  while (pos < werd->length() && num_segments < 3) {
377  int numeral_start = m.SkipPunc(pos);
378  if (numeral_start > pos + 1) break;
379  int numeral_end = m.SkipRomans(numeral_start);
380  if (numeral_end == numeral_start) {
381  numeral_end = m.SkipDigits(numeral_start);
382  if (numeral_end == numeral_start) {
383  // If there's a single latin letter, we can use that.
384  numeral_end = m.SkipAlpha(numeral_start);
385  if (numeral_end - numeral_start != 1)
386  break;
387  }
388  }
389  // We got some sort of numeral.
390  num_segments++;
391  // Skip any trailing punctuation.
392  pos = m.SkipPunc(numeral_end);
393  if (pos == numeral_end)
394  break;
395  }
396  return pos == werd->length();
397 }
int length() const
Definition: ratngs.h:214
int UnicodeFor(const UNICHARSET *u, const WERD_CHOICE *werd, int pos)
Definition: paragraphs.cpp:286
bool LikelyListMarkUnicode(int ch)
Definition: paragraphs.cpp:340
bool tesseract::ValidBodyLine ( const GenericVector< RowScratchRegisters > *  rows,
int  row,
const ParagraphModel model 
)

Definition at line 1226 of file paragraphs.cpp.

1227  {
1228  if (!StrongModel(model)) {
1229  tprintf("ValidBodyLine() should only be called with strong models!\n");
1230  }
1231  return StrongModel(model) &&
1232  model->ValidBodyLine(
1233  (*rows)[row].lmargin_, (*rows)[row].lindent_,
1234  (*rows)[row].rindent_, (*rows)[row].rmargin_);
1235 }
bool ValidBodyLine(int lmargin, int lindent, int rindent, int rmargin) const
Definition: ocrpara.cpp:63
bool StrongModel(const ParagraphModel *model)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
bool tesseract::ValidFirstLine ( const GenericVector< RowScratchRegisters > *  rows,
int  row,
const ParagraphModel model 
)

Definition at line 1215 of file paragraphs.cpp.

1216  {
1217  if (!StrongModel(model)) {
1218  tprintf("ValidFirstLine() should only be called with strong models!\n");
1219  }
1220  return StrongModel(model) &&
1221  model->ValidFirstLine(
1222  (*rows)[row].lmargin_, (*rows)[row].lindent_,
1223  (*rows)[row].rindent_, (*rows)[row].rmargin_);
1224 }
bool ValidFirstLine(int lmargin, int lindent, int rindent, int rmargin) const
Definition: ocrpara.cpp:46
bool StrongModel(const ParagraphModel *model)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
bool tesseract::write_info ( FILE *  f,
const FontInfo &  fi 
)

Definition at line 72 of file fontinfo.cpp.

72  {
73  inT32 size = strlen(fi.name);
74  if (fwrite(&size, sizeof(size), 1, f) != 1) return false;
75  if (fwrite(fi.name, sizeof(*fi.name), size, f) != size) return false;
76  if (fwrite(&fi.properties, sizeof(fi.properties), 1, f) != 1) return false;
77  return true;
78 }
int inT32
Definition: host.h:102
#define f(xc, yc)
Definition: imgscale.cpp:39
bool tesseract::write_set ( FILE *  f,
const FontSet &  fs 
)

Definition at line 153 of file fontinfo.cpp.

153  {
154  if (fwrite(&fs.size, sizeof(fs.size), 1, f) != 1) return false;
155  for (int i = 0; i < fs.size; ++i) {
156  if (fwrite(&fs.configs[i], sizeof(fs.configs[i]), 1, f) != 1) return false;
157  }
158  return true;
159 }
#define f(xc, yc)
Definition: imgscale.cpp:39
bool tesseract::write_spacing_info ( FILE *  f,
const FontInfo &  fi 
)

Definition at line 112 of file fontinfo.cpp.

112  {
113  inT32 vec_size = (fi.spacing_vec == NULL) ? 0 : fi.spacing_vec->size();
114  if (fwrite(&vec_size, sizeof(vec_size), 1, f) != 1) return false;
115  inT16 x_gap_invalid = -1;
116  for (int i = 0; i < vec_size; ++i) {
117  FontSpacingInfo *fs = fi.spacing_vec->get(i);
118  inT32 kern_size = (fs == NULL) ? -1 : fs->kerned_x_gaps.size();
119  if (fs == NULL) {
120  if (fwrite(&(x_gap_invalid), sizeof(x_gap_invalid), 1, f) != 1 ||
121  fwrite(&(x_gap_invalid), sizeof(x_gap_invalid), 1, f) != 1 ||
122  fwrite(&kern_size, sizeof(kern_size), 1, f) != 1) {
123  return false;
124  }
125  } else {
126  if (fwrite(&(fs->x_gap_before), sizeof(fs->x_gap_before), 1, f) != 1 ||
127  fwrite(&(fs->x_gap_after), sizeof(fs->x_gap_after), 1, f) != 1 ||
128  fwrite(&kern_size, sizeof(kern_size), 1, f) != 1) {
129  return false;
130  }
131  }
132  if (kern_size > 0 && (!fs->kerned_unichar_ids.Serialize(f) ||
133  !fs->kerned_x_gaps.Serialize(f))) {
134  return false;
135  }
136  }
137  return true;
138 }
#define NULL
Definition: host.h:144
int inT32
Definition: host.h:102
#define f(xc, yc)
Definition: imgscale.cpp:39
short inT16
Definition: host.h:100
void tesseract::WriteShapeTable ( const STRING file_prefix,
const ShapeTable shape_table 
)

Definition at line 209 of file commontraining.cpp.

209  {
210  STRING shape_table_file = file_prefix;
211  shape_table_file += kShapeTableFileSuffix;
212  FILE* fp = fopen(shape_table_file.string(), "wb");
213  if (fp != NULL) {
214  if (!shape_table.Serialize(fp)) {
215  fprintf(stderr, "Error writing shape table: %s\n",
216  shape_table_file.string());
217  }
218  fclose(fp);
219  } else {
220  fprintf(stderr, "Error creating shape table: %s\n",
221  shape_table_file.string());
222  }
223 }
#define NULL
Definition: host.h:144
bool Serialize(FILE *fp) const
Definition: shapetable.cpp:182
const char * string() const
Definition: strngs.cpp:156
Definition: strngs.h:40

Variable Documentation

const int tesseract::case_state_table[6][4]
Initial value:
= { {
0, 1, 5, 4
},
{
0, 3, 2, 4
},
{
0, -1, 2, -1
},
{
0, 3, -1, 4
},
{
0, -1, -1, 4
},
{
5, -1, 2, -1
},
}

Definition at line 35 of file context.cpp.

const int tesseract::kAdjacentLeaderSearchPadding = 2

Definition at line 124 of file tablefind.cpp.

const double tesseract::kAlignedFraction = 0.03125

Definition at line 40 of file alignedblob.cpp.

const double tesseract::kAlignedGapFraction = 0.75

Definition at line 44 of file alignedblob.cpp.

const char* tesseract::kAlignmentNames[]
Initial value:
= {
"Left Aligned",
"Left Ragged",
"Center",
"Right Aligned",
"Right Ragged",
"Separator"
}

Definition at line 516 of file tabvector.cpp.

const double tesseract::kAllowBlobArea = 0.05

Definition at line 60 of file tablefind.cpp.

const double tesseract::kAllowBlobHeight = 0.3

Definition at line 58 of file tablefind.cpp.

const double tesseract::kAllowBlobWidth = 0.4

Definition at line 59 of file tablefind.cpp.

const double tesseract::kAllowTextArea = 0.8

Definition at line 53 of file tablefind.cpp.

const double tesseract::kAllowTextHeight = 0.5

Definition at line 51 of file tablefind.cpp.

const double tesseract::kAllowTextWidth = 0.6

Definition at line 52 of file tablefind.cpp.

const char * tesseract::kApostropheLikeUTF8
Initial value:
= {
"'",
"`",
"\u2018",
"\u2019",
"\u2032",
NULL,
}
#define NULL
Definition: host.h:144

Definition at line 48 of file unicodes.cpp.

const double tesseract::kBigPartSizeRatio = 1.75

Definition at line 47 of file colpartitiongrid.cpp.

const int tesseract::kBoxClipTolerance = 2

Definition at line 31 of file boxword.cpp.

const double tesseract::kBrokenCJKIterationFraction = 0.125

Definition at line 79 of file strokewidth.cpp.

const int tesseract::kBytesPer64BitNumber = 20

Max bytes in the decimal representation of inT64.

Definition at line 1178 of file baseapi.cpp.

const int tesseract::kBytesPerBlob = kNumbersPerBlob * (kBytesPerNumber + 1) + 1

Multiplier for max expected textlength assumes (kBytesPerNumber + space)

  • kNumbersPerBlob plus the newline. Add to this the original UTF8 characters, and one kMaxBytesPerLine for safety.

Definition at line 1175 of file baseapi.cpp.

const int tesseract::kBytesPerBoxFileLine = (kBytesPerNumber + 1) * kNumbersPerBlob + 1

Definition at line 1176 of file baseapi.cpp.

const int tesseract::kBytesPerNumber = 5

The number of bytes taken by each number. Since we use inT16 for ICOORD, assume only 5 digits max.

Definition at line 1169 of file baseapi.cpp.

const int tesseract::kCellSplitColumnThreshold = 0

Definition at line 36 of file tablerecog.cpp.

const int tesseract::kCellSplitRowThreshold = 0

Definition at line 35 of file tablerecog.cpp.

const double tesseract::kCharVerticalOverlapFraction = 0.375

Definition at line 63 of file tabfind.cpp.

const double tesseract::kCJKAspectRatio = 1.25

Definition at line 73 of file strokewidth.cpp.

const double tesseract::kCJKAspectRatioIncrease = 1.0625

Definition at line 75 of file strokewidth.cpp.

const double tesseract::kCJKBrokenDistanceFraction = 0.25

Definition at line 69 of file strokewidth.cpp.

const int tesseract::kCJKMaxComponents = 8

Definition at line 71 of file strokewidth.cpp.

const int tesseract::kCJKRadius = 2

Definition at line 67 of file strokewidth.cpp.

const int tesseract::kColumnWidthFactor = 20

Pixel resolution of column width estimates.

Definition at line 51 of file tabfind.h.

const double tesseract::kCosMaxSkewAngle = 0.866025

Definition at line 82 of file tabfind.cpp.

const int tesseract::kCrackSpacing = 100

Spacing of cracks across the page to break up tall vertical lines.

Definition at line 44 of file linefind.cpp.

const ParagraphModel * tesseract::kCrownLeft = reinterpret_cast<ParagraphModel *>(0xDEAD111F)

Definition at line 50 of file paragraphs.cpp.

const ParagraphModel * tesseract::kCrownRight = reinterpret_cast<ParagraphModel *>(0xDEAD888F)

Definition at line 52 of file paragraphs.cpp.

const int tesseract::kDefaultResolution = 300

Default resolution used if input in not believable.

Definition at line 58 of file pagesegmain.cpp.

const double tesseract::kDiacriticXPadRatio = 7.0

Definition at line 82 of file strokewidth.cpp.

const double tesseract::kDiacriticYPadRatio = 1.75

Definition at line 85 of file strokewidth.cpp.

const char tesseract::kDoNotReverse[] = "RRP_DO_NO_REVERSE"

Definition at line 43 of file trie.cpp.

const float tesseract::kFontMergeDistance = 0.025

Definition at line 49 of file mastertrainer.cpp.

const char tesseract::kForceReverse[] = "RRP_FORCE_REVERSE"

Definition at line 45 of file trie.cpp.

const double tesseract::kGoodRowNumberOfColumnsLarge = 0.7

Definition at line 54 of file tablerecog.cpp.

const double tesseract::kGoodRowNumberOfColumnsSmall[] = { 2, 2, 2, 2, 2, 3, 3 }

Definition at line 50 of file tablerecog.cpp.

const int tesseract::kGoodRowNumberOfColumnsSmallSize
Initial value:
=
sizeof(kGoodRowNumberOfColumnsSmall) / sizeof(double) - 1
const double kGoodRowNumberOfColumnsSmall[]
Definition: tablerecog.cpp:50

Definition at line 51 of file tablerecog.cpp.

const int tesseract::kGutterMultiple = 4

Definition at line 39 of file tabvector.cpp.

const int tesseract::kGutterToNeighbourRatio = 3

Definition at line 41 of file tabvector.cpp.

const int tesseract::kHistogramSize = 256

Definition at line 25 of file otsuthr.h.

const double tesseract::kHorizontalGapMergeFraction = 0.5

Definition at line 57 of file colfind.cpp.

const double tesseract::kHorizontalSpacing = 0.30

Definition at line 29 of file tablerecog.cpp.

const int tesseract::kHorzStrongTextlineAspect = 5

Definition at line 70 of file colpartition.cpp.

const int tesseract::kHorzStrongTextlineCount = 8

Definition at line 66 of file colpartition.cpp.

const int tesseract::kHorzStrongTextlineHeight = 10

Definition at line 68 of file colpartition.cpp.

const char * tesseract::kHyphenLikeUTF8
Initial value:
= {
"-",
"\u05BE",
"\u2010",
"\u2011",
"\u2012",
"\u2013",
"\u2014",
"\u2015",
"\u2212",
"\uFE58",
"\uFE63",
"\uFF0D",
NULL,
}
#define NULL
Definition: host.h:144

Definition at line 32 of file unicodes.cpp.

const float tesseract::kInfiniteDist = 999.0f

Definition at line 896 of file mastertrainer.cpp.

const char* tesseract::kInputFile = "noname.tif"

Filename used for input image file, from which to derive a name to search for a possible UNLV zone file, if none is specified by SetInputName.

Definition at line 88 of file baseapi.cpp.

const double tesseract::kLargeTableProjectionThreshold = 0.45

Definition at line 109 of file tablefind.cpp.

const int tesseract::kLargeTableRowCount = 6

Definition at line 111 of file tablefind.cpp.

const int tesseract::kLatinChs[]
Initial value:
= {
0x00a2, 0x0022, 0x0022, 0x0027, 0x0027, 0x00b7, 0x002d, 0
}

Latin chars corresponding to the unicode chars above.

Definition at line 1239 of file baseapi.cpp.

const int tesseract::kLeaderCutCost = 8

Definition at line 60 of file colpartition.cpp.

const int tesseract::kLeftIndentAlignmentCountTh = 1

Definition at line 88 of file equationdetect.cpp.

const double tesseract::kLineCountReciprocal = 4.0

Definition at line 52 of file tabvector.cpp.

const int tesseract::kLinedTableMinHorizontalLines = 3

Definition at line 39 of file tablerecog.cpp.

const int tesseract::kLinedTableMinVerticalLines = 3

Definition at line 38 of file tablerecog.cpp.

const int tesseract::kLineFindGridSize = 50

Grid size used by line finder. Not very critical.

Definition at line 46 of file linefind.cpp.

const double tesseract::kLineFragmentAspectRatio = 10.0

Definition at line 57 of file tabfind.cpp.

const double tesseract::kLineResidueAspectRatio = 8.0

Definition at line 108 of file strokewidth.cpp.

const int tesseract::kLineResiduePadRatio = 3

Definition at line 110 of file strokewidth.cpp.

const double tesseract::kLineResidueSizeRatio = 1.75

Definition at line 112 of file strokewidth.cpp.

const int tesseract::kLineTrapLongest = 4

Definition at line 101 of file strokewidth.cpp.

const int tesseract::kLineTrapShortest = 2

Definition at line 103 of file strokewidth.cpp.

const char * tesseract::kLRM = "\u200E"

Definition at line 27 of file unicodes.cpp.

const double tesseract::kMarginFactor = 1.1

Definition at line 44 of file tablerecog.cpp.

const double tesseract::kMarginOverlapFraction = 0.25

Definition at line 54 of file colfind.cpp.

const float tesseract::kMathDigitDensityTh1 = 0.25

Definition at line 83 of file equationdetect.cpp.

const float tesseract::kMathDigitDensityTh2 = 0.1

Definition at line 84 of file equationdetect.cpp.

const float tesseract::kMathItalicDensityTh = 0.5

Definition at line 85 of file equationdetect.cpp.

const double tesseract::kMaxBaselineError = 0.4375

Definition at line 73 of file colpartition.cpp.

const double tesseract::kMaxBlobOverlapFactor = 4.0

Definition at line 79 of file tablefind.cpp.

const int tesseract::kMaxBlobWidth = 500

Definition at line 42 of file tablefind.cpp.

const inT16 tesseract::kMaxBoxEdgeDiff = 2

Definition at line 33 of file recogtraining.cpp.

const int tesseract::kMaxBoxesInDataPartition = 20

Definition at line 68 of file tablefind.cpp.

const int tesseract::kMaxBytesPerLine
Initial value:
const int kNumbersPerBlob
Definition: baseapi.cpp:1164
const int kBytesPer64BitNumber
Definition: baseapi.cpp:1178
#define UNICHAR_LEN
Definition: unichar.h:28

A maximal single box could occupy kNumbersPerBlob numbers at kBytesPer64BitNumber digits (if someone sneaks in a 64 bit value) and a space plus the newline and the maximum length of a UNICHAR. Test against this on each iteration for safety.

Definition at line 1185 of file baseapi.cpp.

const int tesseract::kMaxCaptionLines = 7

Definition at line 39 of file colpartitiongrid.cpp.

const int tesseract::kMaxCharTopRange = 48

Definition at line 61 of file fixxht.cpp.

const int tesseract::kMaxCircleErosions = 8

Definition at line 60 of file pagesegmain.cpp.

const int tesseract::kMaxCJKSizeRatio = 5

Definition at line 77 of file strokewidth.cpp.

const int tesseract::kMaxColorDistance = 900

Definition at line 80 of file colpartition.cpp.

const int tesseract::kMaxColumnHeaderDistance = 4

Definition at line 87 of file tablefind.cpp.

const int tesseract::kMaxCredibleResolution = 2400

Maximum believable resolution.

Definition at line 99 of file baseapi.cpp.

const double tesseract::kMaxDiacriticDistanceRatio = 1.25

Definition at line 91 of file strokewidth.cpp.

const double tesseract::kMaxDiacriticGapToBaseCharHeight = 1.0

Definition at line 94 of file strokewidth.cpp.

const double tesseract::kMaxDistToPartSizeRatio = 1.5

Definition at line 64 of file colfind.cpp.

const int tesseract::kMaxDropCapBottom = -128

Definition at line 37 of file boxword.cpp.

const int tesseract::kMaxFillinMultiple = 11

Definition at line 48 of file tabvector.cpp.

const double tesseract::kMaxGapInTextPartition = 4.0

Definition at line 71 of file tablefind.cpp.

const double tesseract::kMaxGutterWidthAbsolute = 2.00

Definition at line 52 of file tabfind.cpp.

const double tesseract::kMaxHorizontalGap = 3.0

Definition at line 65 of file tabfind.cpp.

const int tesseract::kMaxIncompatibleColumnCount = 2

Definition at line 52 of file colfind.cpp.

const int tesseract::kMaxIntSize = 22

Max string length of an int.

Definition at line 92 of file baseapi.cpp.

const int tesseract::kMaxLargeOverlaps = 3

Definition at line 117 of file strokewidth.cpp.

const int tesseract::kMaxLargeOverlapsWithMedium = 12

Definition at line 40 of file ccnontextdetect.cpp.

const int tesseract::kMaxLargeOverlapsWithSmall = 3

Definition at line 31 of file ccnontextdetect.cpp.

const double tesseract::kMaxLeaderGapFractionOfMax = 0.25

Definition at line 54 of file colpartition.cpp.

const double tesseract::kMaxLeaderGapFractionOfMin = 0.5

Definition at line 56 of file colpartition.cpp.

const int tesseract::kMaxLineResidue = 6

Definition at line 52 of file linefind.cpp.

const int tesseract::kMaxMediumOverlapsWithSmall = 12

Definition at line 36 of file ccnontextdetect.cpp.

const int tesseract::kMaxNeighbourDistFactor = 4

Definition at line 33 of file colpartitiongrid.cpp.

const double tesseract::kMaxNonLineDensity = 0.25

Definition at line 57 of file linefind.cpp.

const int tesseract::kMaxOffsetDist = 32

Definition at line 32 of file intfeaturemap.cpp.

const int tesseract::kMaxPadFactor = 6

Definition at line 30 of file colpartitiongrid.cpp.

const double tesseract::kMaxParagraphEndingLeftSpaceMultiple = 3.0

Definition at line 133 of file tablefind.cpp.

const double tesseract::kMaxPartitionSpacing = 1.75

Definition at line 66 of file colpartitiongrid.cpp.

const int tesseract::kMaxPartnerDepth = 4

Definition at line 42 of file colpartition.cpp.

const int tesseract::kMaxRaggedSearch = 25

Definition at line 40 of file tabfind.cpp.

const double tesseract::kMaxRectangularFraction = 0.75

Definition at line 47 of file imagefind.cpp.

const double tesseract::kMaxRectangularGradient = 0.1

Definition at line 50 of file imagefind.cpp.

const int tesseract::kMaxRMSColorNoise = 128

Definition at line 77 of file colpartition.cpp.

const double tesseract::kMaxRowSize = 2.5

Definition at line 47 of file tablerecog.cpp.

const double tesseract::kMaxSameBlockLineSpacing = 3

Definition at line 50 of file colpartition.cpp.

const double tesseract::kMaxSizeRatio = 1.5

Definition at line 52 of file colpartition.cpp.

const int tesseract::kMaxSkewFactor = 15

Definition at line 66 of file alignedblob.cpp.

const double tesseract::kMaxSmallNeighboursPerPix = 1.0 / 32

Definition at line 28 of file ccnontextdetect.cpp.

const double tesseract::kMaxSpacingDrift = 1.0 / 72

Definition at line 44 of file colpartition.cpp.

const double tesseract::kMaxStaveHeight = 1.0

Definition at line 59 of file linefind.cpp.

const double tesseract::kMaxTableCellXheight = 2.0

Definition at line 83 of file tablefind.cpp.

const int tesseract::kMaxTextLineBlobRatio = 5

Definition at line 73 of file tabfind.cpp.

const double tesseract::kMaxTopSpacingFraction = 0.25

Definition at line 47 of file colpartition.cpp.

const int tesseract::kMaxUnicharsPerCluster = 2000

Definition at line 47 of file mastertrainer.cpp.

const int tesseract::kMaxVerticalSearch = 12

Definition at line 39 of file tabfind.cpp.

const int tesseract::kMaxVerticalSpacing = 500

Definition at line 40 of file tablefind.cpp.

const double tesseract::kMaxXProjectionGapFactor = 2.0

Definition at line 143 of file tablefind.cpp.

const double tesseract::kMinAlignedGutter = 0.25

Definition at line 54 of file tabvector.cpp.

const int tesseract::kMinAlignedTabs = 4

Definition at line 56 of file alignedblob.cpp.

const double tesseract::kMinBaselineCoverage = 0.5

Definition at line 75 of file colpartition.cpp.

const int tesseract::kMinBoxesInTextPartition = 10

Definition at line 65 of file tablefind.cpp.

const double tesseract::kMinCaptionGapHeightRatio = 0.5

Definition at line 43 of file colpartitiongrid.cpp.

const double tesseract::kMinCaptionGapRatio = 2.0

Definition at line 41 of file colpartitiongrid.cpp.

const int tesseract::kMinChainTextValue = 3

Definition at line 64 of file colpartition.cpp.

const int tesseract::kMinClusteredShapes = 1

Definition at line 45 of file mastertrainer.cpp.

const int tesseract::kMinColorDifference = 16

Definition at line 56 of file imagefind.cpp.

const int tesseract::kMinColumnWidth = 100

Definition at line 49 of file colfind.cpp.

const int tesseract::kMinCredibleResolution = 70

Minimum believable resolution.

Minimum believable resolution. Used as a default if there is no other information, as it is safer to under-estimate than over-estimate.

Definition at line 97 of file baseapi.cpp.

const double tesseract::kMinDiacriticSizeRatio = 1.0625

Definition at line 88 of file strokewidth.cpp.

const int tesseract::kMinEvaluatedTabs = 3

Definition at line 70 of file tabfind.cpp.

const double tesseract::kMinFilledArea = 0.35

Definition at line 57 of file tablerecog.cpp.

const double tesseract::kMinFractionalLinesInColumn = 0.125

Definition at line 46 of file tabfind.cpp.

const double tesseract::kMinGoodTextPARatio = 1.5

Definition at line 56 of file ccnontextdetect.cpp.

const double tesseract::kMinGutterFraction = 0.5

Definition at line 50 of file tabvector.cpp.

const double tesseract::kMinGutterWidthAbsolute = 0.02

Definition at line 50 of file tabfind.cpp.

const double tesseract::kMinGutterWidthGrid = 0.5

Definition at line 61 of file colfind.cpp.

const double tesseract::kMinImageArea = 0.5

Definition at line 78 of file tabfind.cpp.

const int tesseract::kMinImageFindSize = 100

Definition at line 52 of file imagefind.cpp.

const int tesseract::kMinLeaderCount = 5

Definition at line 58 of file colpartition.cpp.

const int tesseract::kMinLineLengthFraction = 4

Denominator of resolution makes min pixels to demand line lengths to be.

Definition at line 42 of file linefind.cpp.

const int tesseract::kMinLinesInColumn = 10

Definition at line 42 of file tabfind.cpp.

const double tesseract::kMinMaxGapInTextPartition = 0.5

Definition at line 75 of file tablefind.cpp.

const double tesseract::kMinMusicPixelFraction = 0.75

Definition at line 61 of file linefind.cpp.

const double tesseract::kMinNonNoiseFraction = 0.5

Definition at line 59 of file colfind.cpp.

const int tesseract::kMinOutlierSamples = 5

Definition at line 37 of file trainingsampleset.cpp.

const double tesseract::kMinOverlapWithTable = 0.6

Definition at line 99 of file tablefind.cpp.

const double tesseract::kMinParagraphEndingTextToWhitespaceRatio = 3.0

Definition at line 139 of file tablefind.cpp.

const double tesseract::kMinPCLengthIncrease = 1.0 / 1024

Definition at line 33 of file intfeaturemap.cpp.

const double tesseract::kMinRaggedGutter = 1.5

Definition at line 56 of file tabvector.cpp.

const int tesseract::kMinRaggedTabs = 5

Definition at line 54 of file alignedblob.cpp.

const double tesseract::kMinRectangularFraction = 0.125

Definition at line 45 of file imagefind.cpp.

const int tesseract::kMinRectSize = 10

Minimum sensible image size to be worth running tesseract.

Definition at line 77 of file baseapi.cpp.

const int tesseract::kMinRowsInTable = 3

Definition at line 114 of file tablefind.cpp.

const int tesseract::kMinStrongTextValue = 6

Definition at line 62 of file colpartition.cpp.

const int tesseract::kMinSubscriptOffset = 20

Definition at line 33 of file boxword.cpp.

const int tesseract::kMinSuperscriptOffset = 20

Definition at line 35 of file boxword.cpp.

const double tesseract::kMinTabGradient = 4.0

Definition at line 62 of file alignedblob.cpp.

const int tesseract::kMinTextLineBlobRatio = 3

Definition at line 76 of file tabfind.cpp.

const int tesseract::kMinThickLineWidth = 12

Definition at line 48 of file linefind.cpp.

const int tesseract::kMinVerticalSearch = 3

Definition at line 38 of file tabfind.cpp.

const int tesseract::kMostlyOneDirRatio = 3

Definition at line 106 of file strokewidth.cpp.

const double tesseract::kNeighbourSearchFactor = 2.5

Definition at line 119 of file strokewidth.cpp.

const int tesseract::kNoisePadding = 4

Definition at line 47 of file ccnontextdetect.cpp.

const int tesseract::kNumbersPerBlob = 5

The 5 numbers output for each box (the usual 4 and a page number.)

Definition at line 1164 of file baseapi.cpp.

const int tesseract::kNumEndPoints = 3

Definition at line 27 of file detlinefit.cpp.

const int tesseract::kNumLiteralCnt = 5

Definition at line 36 of file tess_lang_model.h.

const char* tesseract::kOldVarsFile = "failed_vars.txt"

Temp file used for storing current parameters before applying retry values.

Definition at line 90 of file baseapi.cpp.

const int tesseract::kOriginalNoiseMultiple = 8

Definition at line 43 of file ccnontextdetect.cpp.

const double tesseract::kParagraphEndingPreviousLineRatio = 1.3

Definition at line 129 of file tablefind.cpp.

const char * tesseract::kPDF = "\u202C"

Definition at line 30 of file unicodes.cpp.

const double tesseract::kPhotoOffsetFraction = 0.375

Definition at line 50 of file ccnontextdetect.cpp.

const int tesseract::kPrime1 = 17

Definition at line 34 of file trainingsampleset.cpp.

const int tesseract::kPrime2 = 13

Definition at line 35 of file trainingsampleset.cpp.

const double tesseract::kRaggedFraction = 2.5

Definition at line 42 of file alignedblob.cpp.

const double tesseract::kRaggedGapFraction = 1.0

Definition at line 46 of file alignedblob.cpp.

const int tesseract::kRaggedGutterMultiple = 5

Definition at line 54 of file tabfind.cpp.

const int tesseract::kRandomizingCenter = 128

Definition at line 35 of file trainingsample.cpp.

const double tesseract::kRequiredColumns = 0.7

Definition at line 42 of file tablerecog.cpp.

const double tesseract::kRequiredFullJustifiedSpacing = 4.0

Definition at line 119 of file tablefind.cpp.

const char tesseract::kReverseIfHasRTL[] = "RRP_REVERSE_IF_HAS_RTL"

Definition at line 44 of file trie.cpp.

const int tesseract::kRGBRMSColors = 4

Definition at line 36 of file colpartition.h.

const char * tesseract::kRLE = "\u202A"

Definition at line 29 of file unicodes.cpp.

const char * tesseract::kRLM = "\u200F"

Definition at line 28 of file unicodes.cpp.

const double tesseract::kRMSFitScaling = 8.0

Definition at line 54 of file imagefind.cpp.

const int tesseract::kRulingVerticalMargin = 3

Definition at line 95 of file tablefind.cpp.

const int tesseract::kSearchRadius = 2

Definition at line 96 of file strokewidth.cpp.

const int tesseract::kSeedBlobsCountTh = 10

Definition at line 87 of file equationdetect.cpp.

const int tesseract::kSideSpaceMargin = 10

Definition at line 104 of file tablefind.cpp.

const int tesseract::kSimilarRaggedDist = 50

Definition at line 46 of file tabvector.cpp.

const int tesseract::kSimilarVectorDist = 10

Definition at line 43 of file tabvector.cpp.

const float tesseract::kSizeRatioToReject = 2.0

Definition at line 114 of file strokewidth.cpp.

const double tesseract::kSmallTableProjectionThreshold = 0.35

Definition at line 108 of file tablefind.cpp.

const int tesseract::kSmoothDecisionMargin = 4

Definition at line 69 of file colpartitiongrid.cpp.

const double tesseract::kSmoothFactor = 0.25

Definition at line 59 of file tabfind.cpp.

const double tesseract::kSplitPartitionSize = 2.0

Definition at line 46 of file tablefind.cpp.

const int tesseract::kSquareLimit = 25

Definition at line 32 of file trainingsampleset.cpp.

const int tesseract::kStateCnt = 4

Definition at line 35 of file tess_lang_model.h.

const int tesseract::kStrayLinePer = 6

Definition at line 46 of file paragraphs.cpp.

const double tesseract::kStrokeWidthCJK = 2.0

Definition at line 64 of file strokewidth.cpp.

const double tesseract::kStrokeWidthConstantTolerance = 2.0

Definition at line 51 of file colpartitiongrid.cpp.

const double tesseract::kStrokeWidthFractionalTolerance = 0.25

Definition at line 147 of file tablefind.cpp.

const double tesseract::kStrokeWidthFractionCJK = 0.25

Definition at line 63 of file strokewidth.cpp.

const double tesseract::kStrokeWidthFractionTolerance = 0.25

Allowed proportional change in stroke width to be the same font.

Definition at line 49 of file colpartitiongrid.cpp.

const double tesseract::kStrokeWidthTolerance = 1.5

Allowed constant change in stroke width to be the same font. Really 1.5 pixels.

Definition at line 61 of file strokewidth.cpp.

const double tesseract::kTableColumnThreshold = 3.0

Definition at line 91 of file tablefind.cpp.

const int tesseract::kTabRadiusFactor = 5

Definition at line 36 of file tabfind.cpp.

const char tesseract::kTesseractReject = '~'

Character returned when Tesseract couldn't recognize as anything.

Definition at line 79 of file baseapi.cpp.

const int tesseract::kTestChar = -1

Definition at line 30 of file trainingsampleset.cpp.

const char* tesseract::kTextordDebugPix = "psdebug_pix"

Definition at line 69 of file alignedblob.cpp.

const double tesseract::kThickLengthMultiple = 0.75

Definition at line 55 of file linefind.cpp.

const int tesseract::kThinLineFraction = 20

Denominator of resolution makes max pixel width to allow thin lines.

Definition at line 40 of file linefind.cpp.

const double tesseract::kTinyEnoughTextlineOverlapFraction = 0.25

Definition at line 53 of file colpartitiongrid.cpp.

const float tesseract::kUnclearDensityTh = 0.25

Definition at line 86 of file equationdetect.cpp.

const int tesseract::kUniChs[]
Initial value:
= {
0x20ac, 0x201c, 0x201d, 0x2018, 0x2019, 0x2022, 0x2014, 0
}

Conversion table for non-latin characters. Maps characters out of the latin set into the latin set. TODO(rays) incorporate this translation into unicharset.

Definition at line 1235 of file baseapi.cpp.

const char tesseract::kUNLVReject = '~'

Character used by UNLV error counter as a reject.

Definition at line 81 of file baseapi.cpp.

const char tesseract::kUNLVSuspect = '^'

Character used by UNLV as a suspect marker.

Definition at line 83 of file baseapi.cpp.

const char * tesseract::kUTF8LineSeparator = "\u2028"

Definition at line 25 of file unicodes.cpp.

const char * tesseract::kUTF8ParagraphSeparator = "\u2029"

Definition at line 26 of file unicodes.cpp.

const double tesseract::kVerticalSpacing = -0.2

Definition at line 32 of file tablerecog.cpp.

const int tesseract::kVLineAlignment = 3

Definition at line 48 of file alignedblob.cpp.

const int tesseract::kVLineGutter = 1

Definition at line 50 of file alignedblob.cpp.

const int tesseract::kVLineMinLength = 500

Definition at line 58 of file alignedblob.cpp.

const int tesseract::kVLineSearchSize = 150

Definition at line 52 of file alignedblob.cpp.

const char* const tesseract::RTLReversePolicyNames[]
Initial value:
= {
}
const char kForceReverse[]
Definition: trie.cpp:45
const char kReverseIfHasRTL[]
Definition: trie.cpp:44
const char kDoNotReverse[]
Definition: trie.cpp:43

Definition at line 47 of file trie.cpp.

bool tesseract::textord_dump_table_images = false

"Paint table detection output"

Definition at line 150 of file tablefind.cpp.

bool tesseract::textord_show_tables = false

"Show table regions"

Definition at line 151 of file tablefind.cpp.

double tesseract::textord_tabfind_aligned_gap_fraction = 0.75

"Fraction of height used as a minimum gap for aligned blobs."

Definition at line 87 of file tabfind.cpp.

bool tesseract::textord_tabfind_find_tables = true

"run table detection"

Definition at line 74 of file colfind.cpp.

bool tesseract::textord_tabfind_force_vertical_text = false

"Force using vertical text page mode"

Definition at line 49 of file strokewidth.cpp.

bool tesseract::textord_tabfind_only_strokewidths = false

"Only run stroke widths"

Definition at line 46 of file strokewidth.cpp.

bool tesseract::textord_tabfind_show_blocks = false

"Show final block bounds"

Definition at line 73 of file colfind.cpp.

bool tesseract::textord_tabfind_show_color_fit = false

"Show stroke widths"

Definition at line 26 of file colpartitiongrid.cpp.

bool tesseract::textord_tabfind_show_columns = false

"Show column bounds"

Definition at line 72 of file colfind.cpp.

bool tesseract::textord_tabfind_show_finaltabs = false

"Show tab vectors"

Definition at line 85 of file tabfind.cpp.

bool tesseract::textord_tabfind_show_initial_partitions = false

"Show partition bounds"

Definition at line 67 of file colfind.cpp.

bool tesseract::textord_tabfind_show_initialtabs = false

"Show tab candidates"

Definition at line 84 of file tabfind.cpp.

int tesseract::textord_tabfind_show_partitions = 0

"Show partition bounds, waiting if >1"

Definition at line 71 of file colfind.cpp.

bool tesseract::textord_tabfind_show_reject_blobs = false

"Show blobs rejected as noise"

Definition at line 69 of file colfind.cpp.

int tesseract::textord_tabfind_show_strokewidths = 0

"Show stroke widths"

Definition at line 45 of file strokewidth.cpp.

bool tesseract::textord_tabfind_vertical_horizontal_mix = true

"find horizontal lines such as headers in vertical page mode"

Definition at line 51 of file strokewidth.cpp.

bool tesseract::textord_tabfind_vertical_text = true

"Enable vertical detection"

Definition at line 47 of file strokewidth.cpp.

double tesseract::textord_tabfind_vertical_text_ratio = 0.5

"Fraction of textlines deemed vertical to use vertical page mode"

Definition at line 53 of file strokewidth.cpp.

bool tesseract::textord_tablefind_recognize_tables = false

"Enables the table recognizer for table layout and filtering."

Definition at line 157 of file tablefind.cpp.

bool tesseract::textord_tablefind_show_mark = false

"Debug table marking steps in detail"

Definition at line 153 of file tablefind.cpp.

bool tesseract::textord_tablefind_show_stats = false

"Show page stats used in table finding"

Definition at line 155 of file tablefind.cpp.

double tesseract::textord_tabvector_vertical_box_ratio = 0.5

"Fraction of box matches required to declare a line vertical"

Definition at line 62 of file tabvector.cpp.

double tesseract::textord_tabvector_vertical_gap_fraction = 0.5

"max fraction of mean blob width allowed for vertical gaps in vertical text"

"Max fraction of mean blob width allowed for vertical gaps in vertical text"

Definition at line 59 of file tabvector.cpp.

CCUtilMutex tesseract::tprintfMutex

Definition at line 51 of file ccutil.cpp.