tesseract  4.00.00dev
tesseract Namespace Reference

Classes

class  AlignedBlob
 
struct  AlignedBlobParams
 
class  AmbigSpec
 
struct  AssociateStats
 
class  AssociateUtils
 
class  BaselineBlock
 
class  BaselineDetect
 
class  BaselineRow
 
class  BBGrid
 
struct  BestChoiceBundle
 Bundle together all the things pertaining to the best choice/state. More...
 
class  BitVector
 
struct  BlobData
 
class  BlobGrid
 
struct  BlockGroup
 
class  BoolParam
 
class  BoxChar
 
struct  BoxCharPtrSort
 
class  BoxWord
 
class  CCNonTextDetect
 
class  CCStruct
 
class  CCUtil
 
class  CCUtilMutex
 
class  ChoiceIterator
 
class  Classify
 
class  ClassPruner
 
struct  ClipFFunc
 
struct  ClipFPrime
 
struct  ClipGFunc
 
struct  ClipGPrime
 
struct  Cluster
 
class  ColPartition
 
class  ColPartitionGrid
 
class  ColPartitionSet
 
class  ColSegment
 
class  ColumnFinder
 
class  Convolve
 
class  CTC
 
class  CUtil
 
class  Dawg
 
struct  DawgArgs
 
class  DawgCache
 
struct  DawgLoader
 
struct  DawgPosition
 
class  DawgPositionVector
 
class  DebugPixa
 
class  DetLineFit
 
class  Dict
 
struct  DocQualCallbacks
 
class  DocumentCache
 
class  DocumentData
 
class  DoubleParam
 
class  DoublePtr
 
class  DPPoint
 
class  EquationDetect
 
class  EquationDetectBase
 
class  ErrorCounter
 
struct  FFunc
 
class  File
 
struct  FloatWordFeature
 
struct  FontInfo
 
class  FontInfoTable
 
struct  FontSet
 
struct  FontSpacingInfo
 
class  FontUtils
 
struct  FPrime
 
class  FRAGMENT
 
class  FullyConnected
 
class  GenericHeap
 
struct  GeometricClassifierState
 
struct  GFunc
 
struct  GPrime
 
class  GridBase
 
class  GridSearch
 
struct  HFunc
 
struct  HPrime
 
class  IcuErrorCode
 
struct  IdentityFunc
 
class  ImageData
 
class  ImageFind
 
class  ImageThresholder
 
class  IndexMap
 
class  IndexMapBiDi
 
class  Input
 
class  InputBuffer
 
struct  Interval
 
class  IntFeatureDist
 
class  IntFeatureMap
 
class  IntFeatureSpace
 
class  IntGrid
 
class  IntParam
 
class  IntSimdMatrix
 
class  IntSimdMatrixAVX2
 
class  IntSimdMatrixSSE
 
struct  KDPair
 
struct  KDPairDec
 
struct  KDPairInc
 
class  KDPtrPair
 
struct  KDPtrPairDec
 
struct  KDPtrPairInc
 
class  KDVector
 
class  LanguageModel
 
struct  LanguageModelDawgInfo
 
struct  LanguageModelNgramInfo
 
struct  LanguageModelState
 Struct to store information maintained by various language model components. More...
 
class  LigatureTable
 
class  LineFinder
 
struct  LineHypothesis
 
struct  LMConsistencyInfo
 
class  LMPainPoints
 
class  LSTM
 
class  LSTMRecognizer
 
class  LSTMTester
 
class  LSTMTrainer
 
class  LTRResultIterator
 
class  MasterTrainer
 
class  Maxpool
 
class  MutableIterator
 
class  Network
 
class  NetworkBuilder
 
class  NetworkIO
 
class  NetworkScratch
 
struct  NodeChild
 
class  ObjectCache
 
class  OutputBuffer
 
class  PageIterator
 
class  PangoFontInfo
 
class  ParagraphModelSmearer
 
class  ParagraphTheory
 
class  Parallel
 
class  Param
 
class  ParamsModel
 
class  ParamsTrainingBundle
 
struct  ParamsTrainingHypothesis
 
struct  ParamsVectors
 
class  ParamUtils
 
class  PixelHistogram
 
class  Plumbing
 
class  PointerVector
 
struct  PtrHash
 
class  RecodeBeamSearch
 
class  RecodedCharID
 
struct  RecodeNode
 
class  Reconfig
 
struct  Relu
 
struct  ReluPrime
 
class  ResultIterator
 
class  Reversed
 
class  RowInfo
 
class  RowScratchRegisters
 
class  SampleIterator
 
struct  ScoredFont
 
class  SegSearchPending
 
class  Series
 
class  Shape
 
class  ShapeClassifier
 
struct  ShapeDist
 
struct  ShapeQueueEntry
 
struct  ShapeRating
 
class  ShapeTable
 
class  ShiroRekhaSplitter
 
class  SimpleClusterer
 
struct  SpacingProperties
 
class  SquishedDawg
 
class  StaticShape
 
class  StrideMap
 
class  StringParam
 
class  StringRenderer
 
class  StrokeWidth
 
class  StructuredTable
 
class  TabConstraint
 
class  TabEventHandler
 
class  TabFind
 
class  TableFinder
 
class  TableRecognizer
 
class  TabVector
 
struct  TESS_CHAR
 
class  TessBaseAPI
 
class  TessBoxTextRenderer
 
class  TessClassifier
 
class  TessdataManager
 
class  Tesseract
 
struct  TesseractStats
 
class  TessHOcrRenderer
 
class  TessOsdRenderer
 
class  TessPDFRenderer
 
class  TessResultRenderer
 
class  TessTextRenderer
 
class  TessTsvRenderer
 
class  TessUnlvRenderer
 
class  TextlineProjection
 
class  Textord
 
class  TFile
 
class  TrainingSample
 
class  TrainingSampleSet
 
class  TRand
 
class  TransposedArray
 
class  Trie
 
class  UNICHAR
 
class  UnicharAmbigs
 
struct  UnicharAndFonts
 
class  UnicharCompress
 
class  UnicharIdArrayUtils
 
struct  UnicharRating
 
class  UnicodeSpanSkipper
 
struct  UnityFunc
 
class  ValidateGrapheme
 
class  ValidateIndic
 
class  ValidateKhmer
 
class  ValidateMyanmar
 
class  Validator
 
struct  ViterbiStateEntry
 
class  WeightMatrix
 
struct  WordData
 
class  WordFeature
 
class  Wordrec
 
class  WordWithBox
 
class  WorkingPartSet
 

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 float(Dict::* ParamsModelClassifyFunc) (const char *lang, void *path)
 
typedef void(Wordrec::* FillLatticeFunc) (const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, BlamerBundle *blamer_bundle)
 
typedef TessCallback4< const UNICHARSET &, int, PageIterator *, Pix * > TruthCallback
 
typedef GenericVectorEqEq< const ParagraphModel * > SetOfModels
 
typedef void(Tesseract::* WordRecognizer) (const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)
 
typedef GenericVector< ParamsTrainingHypothesisParamsTrainingHypothesisList
 
typedef GenericVector< UNICHAR_IDUnicharIdVector
 
typedef GenericVector< AmbigSpec_LIST * > UnicharAmbigsVector
 
typedef bool(* FileReader) (const STRING &filename, GenericVector< char > *data)
 
typedef bool(* FileWriter) (const GenericVector< char > &data, const STRING &filename)
 
typedef KDPairInc< int, int > IntKDPair
 
typedef signed int char32
 
typedef std::unordered_map< int, std::unique_ptr< std::vector< int > > > RSMap
 
typedef std::unordered_map< int, int > RSCounts
 
typedef GenericHeap< ShapeQueueEntryShapeQueue
 
typedef GenericVector< NodeChildNodeChildVector
 
typedef GenericVector< int > SuccessorList
 
typedef GenericVector< SuccessorList * > SuccessorListsVector
 
typedef GenericVector< Dawg * > DawgVector
 
typedef TessResultCallback2< bool, const GenericVector< char > &, LSTMTrainer * > * CheckPointReader
 
typedef TessResultCallback3< bool, SerializeAmount, const LSTMTrainer *, GenericVector< char > * > * CheckPointWriter
 
typedef TessResultCallback4< STRING, int, const double *, const TessdataManager &, int > * TestCallback
 
typedef KDPairInc< double, RecodeNodeRecodePair
 
typedef GenericHeap< RecodePairRecodeHeap
 
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 BBGrid< WordWithBox, WordWithBox_CLIST, WordWithBox_C_IT > WordGrid
 
typedef GridSearch< WordWithBox, WordWithBox_CLIST, WordWithBox_C_IT > WordSearch
 
typedef std::unordered_map< string, string, StringHashLigHash
 
typedef GenericHeap< MatrixCoordPairPainPointHeap
 
typedef unsigned char LanguageModelFlagsType
 Used for expressing various language model flags. More...
 

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  CachingStrategy { CS_SEQUENTIAL, CS_ROUND_ROBIN }
 
enum  NormalizationMode { NM_BASELINE = -3, NM_CHAR_ISOTROPIC = -2, NM_CHAR_ANISOTROPIC = -1 }
 
enum  kParamsTrainingFeatureType {
  PTRAIN_DIGITS_SHORT, PTRAIN_DIGITS_MED, PTRAIN_DIGITS_LONG, PTRAIN_NUM_SHORT,
  PTRAIN_NUM_MED, PTRAIN_NUM_LONG, PTRAIN_DOC_SHORT, PTRAIN_DOC_MED,
  PTRAIN_DOC_LONG, PTRAIN_DICT_SHORT, PTRAIN_DICT_MED, PTRAIN_DICT_LONG,
  PTRAIN_FREQ_SHORT, PTRAIN_FREQ_MED, PTRAIN_FREQ_LONG, PTRAIN_SHAPE_COST_PER_CHAR,
  PTRAIN_NGRAM_COST_PER_CHAR, PTRAIN_NUM_BAD_PUNC, PTRAIN_NUM_BAD_CASE, PTRAIN_XHEIGHT_CONSISTENCY,
  PTRAIN_NUM_BAD_CHAR_TYPE, PTRAIN_NUM_BAD_SPACING, PTRAIN_NUM_BAD_FONT, PTRAIN_RATING_PER_CHAR,
  PTRAIN_NUM_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_SPARSE_TEXT,
  PSM_SPARSE_TEXT_OSD, PSM_RAW_LINE, 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_LSTM_ONLY, OEM_TESSERACT_LSTM_COMBINED, OEM_DEFAULT,
  OEM_COUNT
}
 
enum  ScriptPos { SP_NORMAL, SP_SUBSCRIPT, SP_SUPERSCRIPT, SP_DROPCAP }
 
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_MODEL, TESSDATA_LSTM, TESSDATA_LSTM_PUNC_DAWG, TESSDATA_LSTM_SYSTEM_DAWG,
  TESSDATA_LSTM_NUMBER_DAWG, TESSDATA_LSTM_UNICHARSET, TESSDATA_LSTM_RECODER, TESSDATA_VERSION,
  TESSDATA_NUM_ENTRIES
}
 
enum  CharSegmentationType { CST_FRAGMENT, CST_WHOLE, CST_IMPROPER, CST_NGRAM }
 
enum  CountTypes {
  CT_UNICHAR_TOP_OK, CT_UNICHAR_TOP1_ERR, CT_UNICHAR_TOP2_ERR, CT_UNICHAR_TOPN_ERR,
  CT_UNICHAR_TOPTOP_ERR, CT_OK_MULTI_UNICHAR, CT_OK_JOINED, CT_OK_BROKEN,
  CT_REJECT, CT_FONT_ATTR_ERR, CT_OK_MULTI_FONT, 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  XHeightConsistencyEnum { XH_GOOD, XH_SUBNORMAL, XH_INCONSISTENT }
 
enum  TrainingFlags { TF_INT_MODE = 1, TF_COMPRESS_UNICHARSET = 64 }
 
enum  ErrorTypes {
  ET_RMS, ET_DELTA, ET_WORD_RECERR, ET_CHAR_ERROR,
  ET_SKIP_RATIO, ET_COUNT
}
 
enum  Trainability {
  TRAINABLE, PERFECT, UNENCODABLE, HI_PRECISION_ERR,
  NOT_BOXED
}
 
enum  SerializeAmount { LIGHT, NO_BEST_TRAINER, FULL }
 
enum  SubTrainerResult { STR_NONE, STR_UPDATED, STR_REPLACED }
 
enum  NetworkType {
  NT_NONE, NT_INPUT, NT_CONVOLVE, NT_MAXPOOL,
  NT_PARALLEL, NT_REPLICATED, NT_PAR_RL_LSTM, NT_PAR_UD_LSTM,
  NT_PAR_2D_LSTM, NT_SERIES, NT_RECONFIG, NT_XREVERSED,
  NT_YREVERSED, NT_XYTRANSPOSE, NT_LSTM, NT_LSTM_SUMMARY,
  NT_LOGISTIC, NT_POSCLIP, NT_SYMCLIP, NT_TANH,
  NT_RELU, NT_LINEAR, NT_SOFTMAX, NT_SOFTMAX_NO_CTC,
  NT_LSTM_SOFTMAX, NT_LSTM_SOFTMAX_ENCODED, NT_TENSORFLOW, NT_COUNT
}
 
enum  NetworkFlags { NF_LAYER_SPECIFIC_LR = 64, NF_ADAM = 128 }
 
enum  TrainingState { TS_DISABLED, TS_ENABLED, TS_TEMP_DISABLE, TS_RE_ENABLE }
 
enum  NodeContinuation { NC_ANYTHING, NC_ONLY_DUP, NC_NO_DUP, NC_COUNT }
 
enum  TopNState { TN_TOP2, TN_TOPN, TN_ALSO_RAN, TN_COUNT }
 
enum  LossType { LT_NONE, LT_CTC, LT_SOFTMAX, LT_LOGISTIC }
 
enum  FlexDimensions { FD_BATCH, FD_HEIGHT, FD_WIDTH, FD_DIMSIZE }
 
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  PartitionFindResult { PFR_OK, PFR_SKEW, PFR_NOISE }
 
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
}
 
enum  FactorNames {
  FN_INCOLOR, FN_Y0, FN_Y1, FN_Y2,
  FN_Y3, FN_X0, FN_X1, FN_SHEAR,
  FN_NUM_FACTORS
}
 
enum  UnicodeNormMode { UnicodeNormMode::kNFD, UnicodeNormMode::kNFC, UnicodeNormMode::kNFKD, UnicodeNormMode::kNFKC }
 
enum  OCRNorm { OCRNorm::kNone, OCRNorm::kNormalize }
 
enum  GraphemeNorm { GraphemeNorm::kNone, GraphemeNorm::kNormalize }
 
enum  GraphemeNormMode { GraphemeNormMode::kSingleString, GraphemeNormMode::kCombined, GraphemeNormMode::kGlyphSplit, GraphemeNormMode::kIndividualUnicodes }
 
enum  ViramaScript : char32 {
  ViramaScript::kNonVirama = 0, ViramaScript::kDevanagari = 0x900, ViramaScript::kBengali = 0x980, ViramaScript::kGurmukhi = 0xa00,
  ViramaScript::kGujarati = 0xa80, ViramaScript::kOriya = 0xb00, ViramaScript::kTamil = 0xb80, ViramaScript::kTelugu = 0xc00,
  ViramaScript::kKannada = 0xc80, ViramaScript::kMalayalam = 0xd00, ViramaScript::kSinhala = 0xd80, ViramaScript::kMyanmar = 0x1000,
  ViramaScript::kKhmer = 0x1780
}
 
enum  LMPainPointsType {
  LM_PPTYPE_BLAMER, LM_PPTYPE_AMBIG, LM_PPTYPE_PATH, LM_PPTYPE_SHAPE,
  LM_PPTYPE_NUM
}
 

Functions

TBLOBmake_tesseract_blob (float baseline, float xheight, float descender, float ascender, bool numeric_mode, Pix *pix)
 
STRING HOcrEscape (const char *text)
 
double prec (double x)
 
long dist2 (int x1, int y1, int x2, int y2)
 
void GetWordBaseline (int writing_direction, int ppi, int height, int word_x1, int word_y1, int word_x2, int word_y2, int line_x1, int line_y1, int line_x2, int line_y2, double *x0, double *y0, double *length)
 
void AffineMatrix (int writing_direction, int line_x1, int line_y1, int line_x2, int line_y2, double *a, double *b, double *c, double *d)
 
void ClipBaseline (int ppi, int x1, int y1, int x2, int y2, int *line_x1, int *line_y1, int *line_x2, int *line_y2)
 
bool CodepointToUtf16be (int code, char utf16[kMaxBytesPerCodepoint])
 
double DotProductAVX (const double *u, const double *v, int n)
 
double DotProductSSE (const double *u, const double *v, int n)
 
int32_t IntDotProductSSE (const int8_t *u, const int8_t *v, int n)
 
bool IsTextOrEquationType (PolyBlockType type)
 
bool IsLeftIndented (const EquationDetect::IndentType type)
 
bool IsRightIndented (const EquationDetect::IndentType type)
 
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)
 
void YOutlierPieces (WERD_RES *word, int rebuilt_blob_index, int super_y_bottom, int sub_y_top, ScriptPos *leading_pos, int *num_leading_outliers, ScriptPos *trailing_pos, int *num_trailing_outliers)
 
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 (TFile *f, FontInfo *fi)
 
bool write_info (FILE *f, const FontInfo &fi)
 
bool read_spacing_info (TFile *f, FontInfo *fi)
 
bool write_spacing_info (FILE *f, const FontInfo &fi)
 
bool read_set (TFile *f, FontSet *fs)
 
bool write_set (FILE *f, const FontSet &fs)
 
void * ReCachePagesFunc (void *data)
 
int OtsuThreshold (Pix *src_pix, int left, int top, int width, int height, int **thresholds, int **hi_values)
 
void HistogramRect (Pix *src_pix, int channel, int left, int top, int width, int height, int *histogram)
 
int OtsuStats (const int *histogram, int *H_out, int *omega0_out)
 
int ParamsTrainingFeatureByName (const char *name)
 
bool PSM_OSD_ENABLED (int pageseg_mode)
 
bool PSM_ORIENTATION_ENABLED (int pageseg_mode)
 
bool PSM_COL_FIND_ENABLED (int pageseg_mode)
 
bool PSM_SPARSE (int pageseg_mode)
 
bool PSM_BLOCK_FIND_ENABLED (int pageseg_mode)
 
bool PSM_LINE_FIND_ENABLED (int pageseg_mode)
 
bool PSM_WORD_FIND_ENABLED (int pageseg_mode)
 
const char * ScriptPosToString (enum ScriptPos script_pos)
 
bool LoadDataFromFile (const char *filename, GenericVector< char > *data)
 
bool LoadDataFromFile (const STRING &filename, GenericVector< char > *data)
 
bool SaveDataToFile (const GenericVector< char > &data, const STRING &filename)
 
bool LoadFileLinesToStrings (const STRING &filename, GenericVector< STRING > *lines)
 
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 ExtractFontName (const STRING &filename, STRING *fontname)
 
TrainingSampleBlobToTrainingSample (const TBLOB &blob, bool nonlinear_norm, INT_FX_RESULT_STRUCT *fx_info, GenericVector< INT_FEATURE_STRUCT > *bl_features)
 
uinT8 NormalizeDirection (uinT8 dir, const FCOORD &unnormed_pos, const DENORM &denorm, const DENORM *root_denorm)
 
void ClearFeatureSpaceWindow (NORM_METHOD norm_method, ScrollView *window)
 
void CallWithUTF8 (TessCallback1< const char *> *cb, const WERD_CHOICE *wc)
 
double Tanh (double x)
 
double Logistic (double x)
 
template<class Func >
void FuncInplace (int n, double *inout)
 
template<class Func >
void FuncMultiply (const double *u, const double *v, int n, double *out)
 
template<typename T >
void SoftmaxInPlace (int n, T *inout)
 
void CopyVector (int n, const double *src, double *dest)
 
void AccumulateVector (int n, const double *src, double *dest)
 
void MultiplyVectorsInPlace (int n, const double *src, double *inout)
 
void MultiplyAccumulate (int n, const double *u, const double *v, double *out)
 
void SumVectors (int n, const double *v1, const double *v2, const double *v3, const double *v4, const double *v5, double *sum)
 
template<typename T >
void ZeroVector (int n, T *vec)
 
template<typename T >
void ClipVector (int n, T lower, T upper, T *vec)
 
void CodeInBinary (int n, int nf, double *vec)
 
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)
 
void SetBlobStrokeWidth (Pix *pix, BLOBNBOX *blob)
 
void assign_blobs_to_blocks2 (Pix *pix, BLOCK_LIST *blocks, TO_BLOCK_LIST *port_blocks)
 
bool IntFlagExists (const char *flag_name, inT32 *value)
 
bool DoubleFlagExists (const char *flag_name, double *value)
 
bool BoolFlagExists (const char *flag_name, bool *value)
 
bool StringFlagExists (const char *flag_name, const char **value)
 
void SetIntFlagValue (const char *flag_name, const inT32 new_val)
 
void SetDoubleFlagValue (const char *flag_name, const double new_val)
 
void SetBoolFlagValue (const char *flag_name, const bool new_val)
 
void SetStringFlagValue (const char *flag_name, const char *new_val)
 
bool SafeAtoi (const char *str, int *val)
 
bool SafeAtod (const char *str, double *val)
 
void PrintCommandLineFlags ()
 
void ParseCommandLineFlags (const char *usage, int *argc, char ***argv, const bool remove_flags)
 
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)
 
Pix * DegradeImage (Pix *input, int exposure, TRand *randomizer, float *rotation)
 
Pix * PrepareDistortedPix (const Pix *pix, bool perspective, bool invert, bool white_noise, bool smooth_noise, bool blur, int box_reduction, TRand *randomizer, GenericVector< TBOX > *boxes)
 
void GeneratePerspectiveDistortion (int width, int height, TRand *randomizer, Pix **pix, GenericVector< TBOX > *boxes)
 
int ProjectiveCoeffs (int width, int height, TRand *randomizer, float **im_coeffs, float **box_coeffs)
 
bool WriteFile (const string &output_dir, const string &lang, const string &suffix, const GenericVector< char > &data, FileWriter writer)
 
STRING ReadFile (const string &filename, FileReader reader)
 
bool WriteUnicharset (const UNICHARSET &unicharset, const string &output_dir, const string &lang, FileWriter writer, TessdataManager *traineddata)
 
bool WriteRecoder (const UNICHARSET &unicharset, bool pass_through, const string &output_dir, const string &lang, FileWriter writer, STRING *radical_table_data, TessdataManager *traineddata)
 
int CombineLangModel (const UNICHARSET &unicharset, const string &script_dir, const string &version_str, const string &output_dir, const string &lang, bool pass_through_recoder, const GenericVector< STRING > &words, const GenericVector< STRING > &puncs, const GenericVector< STRING > &numbers, bool lang_is_rtl, FileReader reader, FileWriter writer)
 
bool is_hyphen_punc (const char32 ch)
 
bool is_single_quote (const char32 ch)
 
bool is_double_quote (const char32 ch)
 
bool NormalizeUTF8String (UnicodeNormMode u_mode, OCRNorm ocr_normalize, GraphemeNorm grapheme_normalize, const char *str8, string *normalized)
 
bool NormalizeCleanAndSegmentUTF8 (UnicodeNormMode u_mode, OCRNorm ocr_normalize, GraphemeNormMode g_mode, bool report_errors, const char *str8, std::vector< string > *graphemes)
 
char32 OCRNormalize (char32 ch)
 
bool IsOCREquivalent (char32 ch1, char32 ch2)
 
bool IsValidCodepoint (const char32 ch)
 
bool IsWhitespace (const char32 ch)
 
bool IsUTF8Whitespace (const char *text)
 
unsigned int SpanUTF8Whitespace (const char *text)
 
unsigned int SpanUTF8NotWhitespace (const char *text)
 
bool IsInterchangeValid (const char32 ch)
 
bool IsInterchangeValid7BitAscii (const char32 ch)
 
char32 FullwidthToHalfwidth (const char32 ch)
 
Pix * CairoARGB32ToPixFormat (cairo_surface_t *surface)
 
void ExtractFontProperties (const string &utf8_text, StringRenderer *render, const string &output_base)
 
bool MakeIndividualGlyphs (Pix *pix, const std::vector< BoxChar *> &vbox, const int input_tiff_page)
 
int Main (int argc, char **argv)
 
void SetupBasicProperties (bool report_errors, bool decompose, UNICHARSET *unicharset)
 
void SetScriptProperties (const string &script_dir, UNICHARSET *unicharset)
 
string GetXheightString (const string &script_dir, const UNICHARSET &unicharset)
 
void SetPropertiesForInputFile (const string &script_dir, const string &input_unicharset_file, const string &output_unicharset_file, const string &output_xheights_file)
 
void SetupBasicProperties (bool report_errors, UNICHARSET *unicharset)
 
bool CmpPairSecond (const std::pair< int, int > &p1, const std::pair< int, int > &p2)
 
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 kNumbersPerBlob = 5
 
const int kBytesPerNumber = 5
 
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 float kCertaintyScale = 7.0f
 
const float kWorstDictCertainty = -25.0f
 
const int kMaxCircleErosions = 8
 
const ParagraphModelkCrownLeft = reinterpret_cast<ParagraphModel *>(0xDEAD111F)
 
const ParagraphModelkCrownRight = reinterpret_cast<ParagraphModel *>(0xDEAD888F)
 
const inT16 kMaxBoxEdgeDiff = 2
 
const int kBoxClipTolerance = 2
 
const int kNumEndPoints = 3
 
const int kMinPointsForErrorCount = 16
 
const int kMaxRealDistance = 2.0
 
const int kFeaturePadding = 2
 
const int kImagePadding = 4
 
const int kHistogramSize = 256
 
const int kMaxAmbigStringSize = UNICHAR_LEN * (MAX_AMBIG_SIZE + 1)
 
CCUtilMutex tprintfMutex
 
const char * kNullChar = "<nul>"
 
const int kRadicalRadix = 29
 
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 char kUniversalAmbigsFile []
 
const int ksizeofUniversalAmbigsFile = sizeof(kUniversalAmbigsFile)
 
const double kRatingEpsilon = 1.0 / 32
 
const int kMaxOffsetDist = 32
 
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 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 []
 
double TanhTable [kTableSize]
 
double LogisticTable [kTableSize]
 
const int kTableSize = 4096
 
const double kScaleFactor = 256.0
 
const int kMaxInputHeight = 48
 
const double kStateClip = 100.0
 
const double kErrClip = 1.0f
 
const int kMaxChoices = 4
 
const double kDictRatio = 2.25
 
const double kCertOffset = -0.085
 
const double kMinDivergenceRate = 50.0
 
const int kMinStallIterations = 10000
 
const double kSubTrainerMarginFraction = 3.0 / 128
 
const double kLearningRateDecay = sqrt(0.5)
 
const int kNumAdjustmentIterations = 100
 
const int kErrorGraphInterval = 1000
 
const int kNumPagesPerBatch = 100
 
const int kMinStartedErrorRate = 75
 
const double kStageTransitionThreshold = 10.0
 
const double kHighConfidence = 0.9375
 
const double kImprovementFraction = 15.0 / 16.0
 
const double kBestCheckpointFraction = 31.0 / 32.0
 
const int kTargetXScale = 5
 
const int kTargetYScale = 100
 
const int kMinWinSize = 500
 
const int kMaxWinSize = 2000
 
const int kXWinFrameSize = 30
 
const int kYWinFrameSize = 80
 
const float kMinCertainty = -20.0f
 
const float kMinProb = exp(kMinCertainty)
 
const char * kNodeContNames [] = {"Anything", "OnlyDup", "NoDup"}
 
const int kAdamCorrectionIterations = 200000
 
const double kAdamEpsilon = 1e-8
 
const int kInt8Flag = 1
 
const int kAdamFlag = 4
 
const int kDoubleFlag = 128
 
const int kHistogramBuckets = 16
 
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 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 kMaxIncompatibleColumnCount = 2
 
const double kHorizontalGapMergeFraction = 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 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 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 kMarginOverlapFraction = 0.25
 
const double kBigPartSizeRatio = 1.75
 
const double kTinyEnoughTextlineOverlapFraction = 0.25
 
const double kMaxPartitionSpacing = 1.75
 
const int kSmoothDecisionMargin = 4
 
const double kMinColumnWidth = 2.0 / 3
 
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
 
const double kStrokeWidthFractionTolerance = 0.125
 
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 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 double kNeighbourSearchFactor = 2.5
 
const double kNoiseOverlapGrowthFactor = 4.0
 
const double kNoiseOverlapAreaFactor = 1.0 / 512
 
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 kMaxGutterWidthAbsolute = 2.00
 
const int kRaggedGutterMultiple = 5
 
const double kLineFragmentAspectRatio = 10.0
 
const int kMinEvaluatedTabs = 3
 
const double kCosMaxSkewAngle = 0.866025
 
bool textord_tabfind_show_initialtabs = false
 
bool textord_tabfind_show_finaltabs = false
 
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 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
 
const double kStrokeWidthConstantTolerance = 2.0
 
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 []
 
const int kMaxLineLength = 1024
 
const float kRotationRange = 0.02f
 
const int kExposureFactor = 16
 
const int kSaltnPepper = 5
 
const int kMinRampSize = 1000
 
const int kMinLigature = 0xfb00
 
const int kMaxLigature = 0xfb17
 
const int kDefaultResolution = 300
 

Detailed Description

The box file is assumed to contain box definitions, one per line, of the following format for blob-level boxes:

*   <UTF8 str> <left> <bottom> <right> <top> <page id>
* 

and for word/line-level boxes:

*   WordStr <left> <bottom> <right> <top> <page id> #<space-delimited word str>
* 

NOTES: The boxes use tesseract coordinates, i.e. 0,0 is at BOTTOM-LEFT.

<page id>=""> is 0-based, and the page number is used for multipage input (tiff).

In the blob-level form, each line represents a recognizable unit, which may be several UTF-8 bytes, but there is a bounding box around each recognizable unit, and no classifier is needed to train in this mode (bootstrapping.)

In the word/line-level form, the line begins with the literal "WordStr", and the bounding box bounds either a whole line or a whole word. The recognizable units in the word/line are listed after the # at the end of the line and are space delimited, ignoring any original spaces on the line. Eg.

* word -> #w o r d
* multi word line -> #m u l t i w o r d l i n e
* 

The recognizable units must be space-delimited in order to allow multiple unicodes to be used for a single recognizable unit, eg Hindi.

In this mode, the classifier must have been pre-trained with the desired character set, or it will not be able to find the character segmentations.

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

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 Function Prototypes


Include Files and Type Defines

Typedef Documentation

◆ BlobGridSearch

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

Definition at line 31 of file blobgrid.h.

◆ char32

typedef signed int tesseract::char32

Definition at line 52 of file unichar.h.

◆ CheckPointReader

Definition at line 69 of file lstmtrainer.h.

◆ CheckPointWriter

Definition at line 78 of file lstmtrainer.h.

◆ ColPartitionGridSearch

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

Definition at line 930 of file colpartition.h.

◆ ColSegmentGrid

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

Definition at line 118 of file tablefind.h.

◆ ColSegmentGridSearch

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

Definition at line 121 of file tablefind.h.

◆ DawgVector

Definition at line 49 of file dict.h.

◆ DictFunc

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

Definition at line 76 of file baseapi.h.

◆ FileReader

typedef bool(* tesseract::FileReader)(const STRING &filename, GenericVector< char > *data)

Definition at line 361 of file genericvector.h.

◆ FileWriter

typedef bool(* tesseract::FileWriter)(const GenericVector< char > &data, const STRING &filename)

Definition at line 364 of file genericvector.h.

◆ FillLatticeFunc

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

Definition at line 85 of file baseapi.h.

◆ IntKDPair

typedef KDPairInc<int, int> tesseract::IntKDPair

Definition at line 179 of file kdpair.h.

◆ LanguageModelFlagsType

typedef unsigned char tesseract::LanguageModelFlagsType

Used for expressing various language model flags.

Definition at line 37 of file lm_state.h.

◆ LigHash

typedef std::unordered_map<string, string, StringHash> tesseract::LigHash

Definition at line 33 of file ligature_table.h.

◆ NodeChildVector

Definition at line 68 of file dawg.h.

◆ PainPointHeap

◆ ParamsModelClassifyFunc

typedef float(Dict::* tesseract::ParamsModelClassifyFunc) (const char *lang, void *path)

Definition at line 83 of file baseapi.h.

◆ ParamsTrainingHypothesisList

◆ PartSetVector

◆ ProbabilityInContextFunc

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

Definition at line 78 of file baseapi.h.

◆ RecodeHeap

Definition at line 173 of file recodebeam.h.

◆ RecodePair

Definition at line 172 of file recodebeam.h.

◆ RSCounts

typedef std::unordered_map<int, int> tesseract::RSCounts

Definition at line 49 of file unicharcompress.cpp.

◆ RSMap

typedef std::unordered_map<int, std::unique_ptr<std::vector<int> > > tesseract::RSMap

Definition at line 47 of file unicharcompress.cpp.

◆ SetOfModels

Definition at line 94 of file paragraphs_internal.h.

◆ ShapeQueue

Definition at line 156 of file shapetable.h.

◆ SuccessorList

Definition at line 69 of file dawg.h.

◆ SuccessorListsVector

Definition at line 70 of file dawg.h.

◆ TestCallback

typedef TessResultCallback4<STRING, int, const double*, const TessdataManager&, int>* tesseract::TestCallback

Definition at line 83 of file lstmtrainer.h.

◆ TruthCallback

Definition at line 90 of file baseapi.h.

◆ UnicharAmbigsVector

typedef GenericVector<AmbigSpec_LIST *> tesseract::UnicharAmbigsVector

Definition at line 141 of file ambigs.h.

◆ UnicharIdVector

Definition at line 34 of file ambigs.h.

◆ WidthCallback

Definition at line 36 of file tabfind.h.

◆ WordGrid

typedef BBGrid<WordWithBox, WordWithBox_CLIST, WordWithBox_C_IT> tesseract::WordGrid

Definition at line 65 of file textord.h.

◆ WordRecognizer

typedef void(Tesseract::* tesseract::WordRecognizer) (const WordData &word_data, WERD_RES **in_word, PointerVector< WERD_RES > *out_words)

Definition at line 160 of file tesseractclass.h.

◆ WordSearch

typedef GridSearch<WordWithBox, WordWithBox_CLIST, WordWithBox_C_IT> tesseract::WordSearch

Definition at line 66 of file textord.h.

Enumeration Type Documentation

◆ AmbigType

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 };

◆ CachingStrategy

Enumerator
CS_SEQUENTIAL 
CS_ROUND_ROBIN 

Definition at line 40 of file imagedata.h.

40  {
41  // Reads all of one file before moving on to the next. Requires samples to be
42  // shuffled across files. Uses the count of samples in the first file as
43  // the count in all the files to achieve high-speed random access. As a
44  // consequence, if subsequent files are smaller, they get entries used more
45  // than once, and if subsequent files are larger, some entries are not used.
46  // Best for larger data sets that don't fit in memory.
48  // Reads one sample from each file in rotation. Does not require shuffled
49  // samples, but is extremely disk-intensive. Samples in smaller files also
50  // get used more often than samples in larger files.
51  // Best for smaller data sets that mostly fit in memory.
53 };

◆ CharSegmentationType

Enumerator
CST_FRAGMENT 
CST_WHOLE 
CST_IMPROPER 
CST_NGRAM 

Definition at line 54 of file classify.h.

54  {
55  CST_FRAGMENT, // A partial character.
56  CST_WHOLE, // A correctly segmented character.
57  CST_IMPROPER, // More than one but less than 2 characters.
58  CST_NGRAM // Multiple characters.
59 };

◆ CMD_EVENTS

Enumerator
ACTION_1_CMD_EVENT 
RECOG_WERDS 
RECOG_PSEUDO 
ACTION_2_CMD_EVENT 

Definition at line 464 of file tessedit.cpp.

◆ ColSegType

Enumerator
COL_UNKNOWN 
COL_TEXT 
COL_TABLE 
COL_MIXED 
COL_COUNT 

Definition at line 30 of file tablefind.h.

◆ ColumnSpanningType

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 };

◆ CountTypes

Enumerator
CT_UNICHAR_TOP_OK 
CT_UNICHAR_TOP1_ERR 
CT_UNICHAR_TOP2_ERR 
CT_UNICHAR_TOPN_ERR 
CT_UNICHAR_TOPTOP_ERR 
CT_OK_MULTI_UNICHAR 
CT_OK_JOINED 
CT_OK_BROKEN 
CT_REJECT 
CT_FONT_ATTR_ERR 
CT_OK_MULTI_FONT 
CT_NUM_RESULTS 
CT_RANK 
CT_REJECTED_JUNK 
CT_ACCEPTED_JUNK 
CT_SIZE 

Definition at line 69 of file errorcounter.h.

69  {
70  CT_UNICHAR_TOP_OK, // Top shape contains correct unichar id.
71  // The rank of the results in TOP1, TOP2, TOPN is determined by a gap of
72  // kRatingEpsilon from the first result in each group. The real top choice
73  // is measured using TOPTOP.
74  CT_UNICHAR_TOP1_ERR, // Top shape does not contain correct unichar id.
75  CT_UNICHAR_TOP2_ERR, // Top 2 shapes don't contain correct unichar id.
76  CT_UNICHAR_TOPN_ERR, // No output shape contains correct unichar id.
77  CT_UNICHAR_TOPTOP_ERR, // Very top choice not correct.
78  CT_OK_MULTI_UNICHAR, // Top shape id has correct unichar id, and others.
79  CT_OK_JOINED, // Top shape id is correct but marked joined.
80  CT_OK_BROKEN, // Top shape id is correct but marked broken.
81  CT_REJECT, // Classifier hates this.
82  CT_FONT_ATTR_ERR, // Top unichar OK, but font attributes incorrect.
83  CT_OK_MULTI_FONT, // CT_FONT_ATTR_OK but there are multiple font attrs.
84  CT_NUM_RESULTS, // Number of answers produced.
85  CT_RANK, // Rank of correct answer.
86  CT_REJECTED_JUNK, // Junk that was correctly rejected.
87  CT_ACCEPTED_JUNK, // Junk that was incorrectly classified otherwise.
88 
89  CT_SIZE // Number of types for array sizing.
90 };

◆ DawgType

Enumerator
DAWG_TYPE_PUNCTUATION 
DAWG_TYPE_WORD 
DAWG_TYPE_NUMBER 
DAWG_TYPE_PATTERN 
DAWG_TYPE_COUNT 

Definition at line 72 of file dawg.h.

◆ ErrorTypes

Enumerator
ET_RMS 
ET_DELTA 
ET_WORD_RECERR 
ET_CHAR_ERROR 
ET_SKIP_RATIO 
ET_COUNT 

Definition at line 37 of file lstmtrainer.h.

37  {
38  ET_RMS, // RMS activation error.
39  ET_DELTA, // Number of big errors in deltas.
40  ET_WORD_RECERR, // Output text string word recall error.
41  ET_CHAR_ERROR, // Output text string total char error.
42  ET_SKIP_RATIO, // Fraction of samples skipped.
43  ET_COUNT // For array sizing.
44 };

◆ FactorNames

Enumerator
FN_INCOLOR 
FN_Y0 
FN_Y1 
FN_Y2 
FN_Y3 
FN_X0 
FN_X1 
FN_SHEAR 
FN_NUM_FACTORS 

Definition at line 41 of file degradeimage.cpp.

◆ FlexDimensions

Enumerator
FD_BATCH 
FD_HEIGHT 
FD_WIDTH 
FD_DIMSIZE 

Definition at line 34 of file stridemap.h.

34  {
35  FD_BATCH, // Index of multiple images.
36  FD_HEIGHT, // y-coordinate in image.
37  FD_WIDTH, // x-coordinate in image.
38  FD_DIMSIZE, // Number of flexible non-depth dimensions.
39 };

◆ GraphemeNorm

Enumerator
kNone 
kNormalize 

Definition at line 49 of file normstrngs.h.

◆ GraphemeNormMode

Enumerator
kSingleString 
kCombined 
kGlyphSplit 
kIndividualUnicodes 

Definition at line 34 of file validator.h.

34  {
35  // Validation result is a single string, even if input is multi-word.
37  // Standard unicode graphemes are validated and output as grapheme units.
38  kCombined,
39  // Graphemes are validated and sub-divided. For virama-using scripts, units
40  // that correspond to repeatable glyphs are generated. (Mostly single unicodes
41  // but viramas and joiners are paired with the most sensible neighbor.)
42  // For non-virama scripts, this means that base/accent pairs are separated,
43  // ie the output is individual unicodes.
45  // The output is always single unicodes, regardless of the script.
47 };

◆ kParamsTrainingFeatureType

Enumerator
PTRAIN_DIGITS_SHORT 
PTRAIN_DIGITS_MED 
PTRAIN_DIGITS_LONG 
PTRAIN_NUM_SHORT 
PTRAIN_NUM_MED 
PTRAIN_NUM_LONG 
PTRAIN_DOC_SHORT 
PTRAIN_DOC_MED 
PTRAIN_DOC_LONG 
PTRAIN_DICT_SHORT 
PTRAIN_DICT_MED 
PTRAIN_DICT_LONG 
PTRAIN_FREQ_SHORT 
PTRAIN_FREQ_MED 
PTRAIN_FREQ_LONG 
PTRAIN_SHAPE_COST_PER_CHAR 
PTRAIN_NGRAM_COST_PER_CHAR 
PTRAIN_NUM_BAD_PUNC 
PTRAIN_NUM_BAD_CASE 
PTRAIN_XHEIGHT_CONSISTENCY 
PTRAIN_NUM_BAD_CHAR_TYPE 
PTRAIN_NUM_BAD_SPACING 
PTRAIN_NUM_BAD_FONT 
PTRAIN_RATING_PER_CHAR 
PTRAIN_NUM_FEATURE_TYPES 

Definition at line 39 of file params_training_featdef.h.

39  {
40  // Digits
42  PTRAIN_DIGITS_MED, // 1
43  PTRAIN_DIGITS_LONG, // 2
44  // Number or pattern (NUMBER_PERM, USER_PATTERN_PERM)
45  PTRAIN_NUM_SHORT, // 3
46  PTRAIN_NUM_MED, // 4
47  PTRAIN_NUM_LONG, // 5
48  // Document word (DOC_DAWG_PERM)
49  PTRAIN_DOC_SHORT, // 6
50  PTRAIN_DOC_MED, // 7
51  PTRAIN_DOC_LONG, // 8
52  // Word (SYSTEM_DAWG_PERM, USER_DAWG_PERM, COMPOUND_PERM)
53  PTRAIN_DICT_SHORT, // 9
54  PTRAIN_DICT_MED, // 10
55  PTRAIN_DICT_LONG, // 11
56  // Frequent word (FREQ_DAWG_PERM)
57  PTRAIN_FREQ_SHORT, // 12
58  PTRAIN_FREQ_MED, // 13
59  PTRAIN_FREQ_LONG, // 14
62  PTRAIN_NUM_BAD_PUNC, // 17
63  PTRAIN_NUM_BAD_CASE, // 18
67  PTRAIN_NUM_BAD_FONT, // 22
69 
71 };

◆ LeftOrRight

Enumerator
LR_LEFT 
LR_RIGHT 

Definition at line 39 of file strokewidth.h.

◆ LineType

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 };

◆ LMPainPointsType

Enumerator
LM_PPTYPE_BLAMER 
LM_PPTYPE_AMBIG 
LM_PPTYPE_PATH 
LM_PPTYPE_SHAPE 
LM_PPTYPE_NUM 

Definition at line 37 of file lm_pain_points.h.

◆ LossType

Enumerator
LT_NONE 
LT_CTC 
LT_SOFTMAX 
LT_LOGISTIC 

Definition at line 27 of file static_shape.h.

27  {
28  LT_NONE, // Undefined.
29  LT_CTC, // Softmax with standard CTC for training/decoding.
30  LT_SOFTMAX, // Outputs sum to 1 in fixed positions.
31  LT_LOGISTIC, // Logistic outputs with independent values.
32 };

◆ NeighbourPartitionType

Enumerator
NPT_HTEXT 
NPT_VTEXT 
NPT_WEAK_HTEXT 
NPT_WEAK_VTEXT 
NPT_IMAGE 
NPT_COUNT 

Definition at line 1510 of file colpartitiongrid.cpp.

1510  {
1511  NPT_HTEXT, // Definite horizontal text.
1512  NPT_VTEXT, // Definite vertical text.
1513  NPT_WEAK_HTEXT, // Weakly horizontal text. Counts as HTEXT for HTEXT, but
1514  // image for image and VTEXT.
1515  NPT_WEAK_VTEXT, // Weakly vertical text. Counts as VTEXT for VTEXT, but
1516  // image for image and HTEXT.
1517  NPT_IMAGE, // Defininte non-text.
1518  NPT_COUNT // Number of array elements.
1519 };

◆ NetworkFlags

Enumerator
NF_LAYER_SPECIFIC_LR 
NF_ADAM 

Definition at line 85 of file network.h.

85  {
86  // Network forward/backprop behavior.
87  NF_LAYER_SPECIFIC_LR = 64, // Separate learning rate for each layer.
88  NF_ADAM = 128, // Weight-specific learning rate.
89 };

◆ NetworkType

Enumerator
NT_NONE 
NT_INPUT 
NT_CONVOLVE 
NT_MAXPOOL 
NT_PARALLEL 
NT_REPLICATED 
NT_PAR_RL_LSTM 
NT_PAR_UD_LSTM 
NT_PAR_2D_LSTM 
NT_SERIES 
NT_RECONFIG 
NT_XREVERSED 
NT_YREVERSED 
NT_XYTRANSPOSE 
NT_LSTM 
NT_LSTM_SUMMARY 
NT_LOGISTIC 
NT_POSCLIP 
NT_SYMCLIP 
NT_TANH 
NT_RELU 
NT_LINEAR 
NT_SOFTMAX 
NT_SOFTMAX_NO_CTC 
NT_LSTM_SOFTMAX 
NT_LSTM_SOFTMAX_ENCODED 
NT_TENSORFLOW 
NT_COUNT 

Definition at line 43 of file network.h.

43  {
44  NT_NONE, // The naked base class.
45  NT_INPUT, // Inputs from an image.
46  // Plumbing networks combine other networks or rearrange the inputs.
47  NT_CONVOLVE, // Duplicates inputs in a sliding window neighborhood.
48  NT_MAXPOOL, // Chooses the max result from a rectangle.
49  NT_PARALLEL, // Runs networks in parallel.
50  NT_REPLICATED, // Runs identical networks in parallel.
51  NT_PAR_RL_LSTM, // Runs LTR and RTL LSTMs in parallel.
52  NT_PAR_UD_LSTM, // Runs Up and Down LSTMs in parallel.
53  NT_PAR_2D_LSTM, // Runs 4 LSTMs in parallel.
54  NT_SERIES, // Executes a sequence of layers.
55  NT_RECONFIG, // Scales the time/y size but makes the output deeper.
56  NT_XREVERSED, // Reverses the x direction of the inputs/outputs.
57  NT_YREVERSED, // Reverses the y-direction of the inputs/outputs.
58  NT_XYTRANSPOSE, // Transposes x and y (for just a single op).
59  // Functional networks actually calculate stuff.
60  NT_LSTM, // Long-Short-Term-Memory block.
61  NT_LSTM_SUMMARY, // LSTM that only keeps its last output.
62  NT_LOGISTIC, // Fully connected logistic nonlinearity.
63  NT_POSCLIP, // Fully connected rect lin version of logistic.
64  NT_SYMCLIP, // Fully connected rect lin version of tanh.
65  NT_TANH, // Fully connected with tanh nonlinearity.
66  NT_RELU, // Fully connected with rectifier nonlinearity.
67  NT_LINEAR, // Fully connected with no nonlinearity.
68  NT_SOFTMAX, // Softmax uses exponential normalization, with CTC.
69  NT_SOFTMAX_NO_CTC, // Softmax uses exponential normalization, no CTC.
70  // The SOFTMAX LSTMs both have an extra softmax layer on top, but inside, with
71  // the outputs fed back to the input of the LSTM at the next timestep.
72  // The ENCODED version binary encodes the softmax outputs, providing log2 of
73  // the number of outputs as additional inputs, and the other version just
74  // provides all the softmax outputs as additional inputs.
75  NT_LSTM_SOFTMAX, // 1-d LSTM with built-in fully connected softmax.
76  NT_LSTM_SOFTMAX_ENCODED, // 1-d LSTM with built-in binary encoded softmax.
77  // A TensorFlow graph encapsulated as a Tesseract network.
79 
80  NT_COUNT // Array size.
81 };

◆ NodeContinuation

Enumerator
NC_ANYTHING 
NC_ONLY_DUP 
NC_NO_DUP 
NC_COUNT 

Definition at line 69 of file recodebeam.h.

69  {
70  NC_ANYTHING, // This node used just its own score, so anything can follow.
71  NC_ONLY_DUP, // The current node combined another score with the score for
72  // itself, without a stand-alone duplicate before, so must be
73  // followed by a stand-alone duplicate.
74  NC_NO_DUP, // The current node combined another score with the score for
75  // itself, after a stand-alone, so can only be followed by
76  // something other than a duplicate of the current node.
77  NC_COUNT
78 };

◆ NormalizationMode

Enumerator
NM_BASELINE 
NM_CHAR_ISOTROPIC 
NM_CHAR_ANISOTROPIC 

Definition at line 44 of file normalis.h.

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

◆ OcrEngineMode

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_LSTM_ONLY 
OEM_TESSERACT_LSTM_COMBINED 
OEM_DEFAULT 
OEM_COUNT 

Definition at line 268 of file publictypes.h.

268  {
269  OEM_TESSERACT_ONLY, // Run Tesseract only - fastest; deprecated
270  OEM_LSTM_ONLY, // Run just the LSTM line recognizer.
271  OEM_TESSERACT_LSTM_COMBINED, // Run the LSTM recognizer, but allow fallback
272  // to Tesseract when things get difficult.
273  // deprecated
274  OEM_DEFAULT, // Specify this mode when calling init_*(),
275  // to indicate that any of the above modes
276  // should be automatically inferred from the
277  // variables in the language-specific config,
278  // command-line configs, or if not specified
279  // in any of the above should be set to the
280  // default OEM_TESSERACT_ONLY.
281  OEM_COUNT // Number of OEMs
282 };

◆ OCRNorm

enum tesseract::OCRNorm
strong
Enumerator
kNone 
kNormalize 

Definition at line 41 of file normstrngs.h.

◆ Orientation

+---------------—+ 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 120 of file publictypes.h.

◆ PageIteratorLevel

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 219 of file publictypes.h.

219  {
220  RIL_BLOCK, // Block of text/image/separator line.
221  RIL_PARA, // Paragraph within a block.
222  RIL_TEXTLINE, // Line within a paragraph.
223  RIL_WORD, // Word within a textline.
224  RIL_SYMBOL // Symbol/character within a word.
225 };
Definition: capi.h:92
Definition: capi.h:92
Definition: capi.h:92

◆ PageSegMode

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_SPARSE_TEXT 

Find as much text as possible in no particular order.

PSM_SPARSE_TEXT_OSD 

Sparse text with orientation and script det.

PSM_RAW_LINE 

Treat the image as a single text line, bypassing hacks that are Tesseract-specific.

PSM_COUNT 

Number of enum entries.

Definition at line 163 of file publictypes.h.

◆ ParagraphJustification

JUSTIFICATION_UNKNOWN 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 251 of file publictypes.h.

◆ PartitionFindResult

Enumerator
PFR_OK 
PFR_SKEW 
PFR_NOISE 

Definition at line 46 of file strokewidth.h.

46  {
47  PFR_OK, // Everything is OK.
48  PFR_SKEW, // Skew was detected and rotated.
49  PFR_NOISE // Noise was detected and removed.
50 };

◆ ScriptPos

Enumerator
SP_NORMAL 
SP_SUBSCRIPT 
SP_SUPERSCRIPT 
SP_DROPCAP 

Definition at line 258 of file ratngs.h.

◆ SerializeAmount

Enumerator
LIGHT 
NO_BEST_TRAINER 
FULL 

Definition at line 56 of file lstmtrainer.h.

56  {
57  LIGHT, // Minimal data for remote training.
58  NO_BEST_TRAINER, // Save an empty vector in place of best_trainer_.
59  FULL, // All data including best_trainer_.
60 };

◆ SetParamConstraint

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.

◆ SubTrainerResult

Enumerator
STR_NONE 
STR_UPDATED 
STR_REPLACED 

Definition at line 63 of file lstmtrainer.h.

63  {
64  STR_NONE, // Did nothing as not good enough.
65  STR_UPDATED, // Subtrainer was updated, but didn't replace *this.
66  STR_REPLACED // Subtrainer replaced *this.
67 };

◆ TabAlignment

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.

◆ TessdataType

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_MODEL 
TESSDATA_LSTM 
TESSDATA_LSTM_PUNC_DAWG 
TESSDATA_LSTM_SYSTEM_DAWG 
TESSDATA_LSTM_NUMBER_DAWG 
TESSDATA_LSTM_UNICHARSET 
TESSDATA_LSTM_RECODER 
TESSDATA_VERSION 
TESSDATA_NUM_ENTRIES 

Definition at line 61 of file tessdatamanager.h.

61  {
64  TESSDATA_AMBIGS, // 2
65  TESSDATA_INTTEMP, // 3
66  TESSDATA_PFFMTABLE, // 4
67  TESSDATA_NORMPROTO, // 5
68  TESSDATA_PUNC_DAWG, // 6
71  TESSDATA_FREQ_DAWG, // 9
72  TESSDATA_FIXED_LENGTH_DAWGS, // 10 // deprecated
73  TESSDATA_CUBE_UNICHARSET, // 11 // deprecated
74  TESSDATA_CUBE_SYSTEM_DAWG, // 12 // deprecated
79  TESSDATA_LSTM, // 17
85  TESSDATA_VERSION, // 23
86 
88 };

◆ TextlineOrder

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 152 of file publictypes.h.

◆ TopNState

Enumerator
TN_TOP2 
TN_TOPN 
TN_ALSO_RAN 
TN_COUNT 

Definition at line 81 of file recodebeam.h.

81  {
82  TN_TOP2, // Winner or 2nd.
83  TN_TOPN, // Runner up in top-n, but not 1st or 2nd.
84  TN_ALSO_RAN, // Not in the top-n.
85  TN_COUNT
86 };

◆ Trainability

Enumerator
TRAINABLE 
PERFECT 
UNENCODABLE 
HI_PRECISION_ERR 
NOT_BOXED 

Definition at line 47 of file lstmtrainer.h.

47  {
48  TRAINABLE, // Non-zero delta error.
49  PERFECT, // Zero delta error.
50  UNENCODABLE, // Not trainable due to coding/alignment trouble.
51  HI_PRECISION_ERR, // Hi confidence disagreement.
52  NOT_BOXED, // Early in training and has no character boxes.
53 };

◆ TrainingFlags

Enumerator
TF_INT_MODE 
TF_COMPRESS_UNICHARSET 

Definition at line 46 of file lstmrecognizer.h.

◆ TrainingState

Enumerator
TS_DISABLED 
TS_ENABLED 
TS_TEMP_DISABLE 
TS_RE_ENABLE 

Definition at line 92 of file network.h.

92  {
93  // Valid states of training_.
94  TS_DISABLED, // Disabled permanently.
95  TS_ENABLED, // Enabled for backprop and to write a training dump.
96  // Re-enable from ANY disabled state.
97  TS_TEMP_DISABLE, // Temporarily disabled to write a recognition dump.
98  // Valid only for SetEnableTraining.
99  TS_RE_ENABLE, // Re-Enable from TS_TEMP_DISABLE, but not TS_DISABLED.
100 };

◆ UnicodeNormMode

Enumerator
kNFD 
kNFC 
kNFKD 
kNFKC 

Definition at line 32 of file normstrngs.h.

◆ ViramaScript

Enumerator
kNonVirama 
kDevanagari 
kBengali 
kGurmukhi 
kGujarati 
kOriya 
kTamil 
kTelugu 
kKannada 
kMalayalam 
kSinhala 
kMyanmar 
kKhmer 

Definition at line 53 of file validator.h.

◆ WritingDirection

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 135 of file publictypes.h.

◆ XHeightConsistencyEnum

Enumerator
XH_GOOD 
XH_SUBNORMAL 
XH_INCONSISTENT 

Definition at line 74 of file dict.h.

Function Documentation

◆ AccumulateVector()

void tesseract::AccumulateVector ( int  n,
const double *  src,
double *  dest 
)
inline

Definition at line 191 of file functions.h.

191  {
192  for (int i = 0; i < n; ++i) dest[i] += src[i];
193 }

◆ AffineMatrix()

void tesseract::AffineMatrix ( int  writing_direction,
int  line_x1,
int  line_y1,
int  line_x2,
int  line_y2,
double *  a,
double *  b,
double *  c,
double *  d 
)

Definition at line 267 of file pdfrenderer.cpp.

269  {
270  double theta = atan2(static_cast<double>(line_y1 - line_y2),
271  static_cast<double>(line_x2 - line_x1));
272  *a = cos(theta);
273  *b = sin(theta);
274  *c = -sin(theta);
275  *d = cos(theta);
276  switch(writing_direction) {
278  *a = -*a;
279  *b = -*b;
280  break;
282  // TODO(jbreiden) Consider using the vertical PDF writing mode.
283  break;
284  default:
285  break;
286  }
287 }

◆ AsciiLikelyListItem()

bool tesseract::AsciiLikelyListItem ( const STRING word)

Definition at line 268 of file paragraphs.cpp.

268  {
269  return LikelyListMark(word) || LikelyListNumeral(word);
270 }
bool LikelyListNumeral(const STRING &word)
Definition: paragraphs.cpp:229
bool LikelyListMark(const STRING &word)
Definition: paragraphs.cpp:263

◆ assign_blobs_to_blocks2()

void tesseract::assign_blobs_to_blocks2 ( Pix *  pix,
BLOCK_LIST *  blocks,
TO_BLOCK_LIST *  port_blocks 
)

Definition at line 154 of file tordmain.cpp.

156  { // output list
157  BLOCK *block; // current block
158  BLOBNBOX *newblob; // created blob
159  C_BLOB *blob; // current blob
160  BLOCK_IT block_it = blocks;
161  C_BLOB_IT blob_it; // iterator
162  BLOBNBOX_IT port_box_it; // iterator
163  // destination iterator
164  TO_BLOCK_IT port_block_it = port_blocks;
165  TO_BLOCK *port_block; // created block
166 
167  for (block_it.mark_cycle_pt(); !block_it.cycled_list(); block_it.forward()) {
168  block = block_it.data();
169  port_block = new TO_BLOCK(block);
170 
171  // Convert the good outlines to block->blob_list
172  port_box_it.set_to_list(&port_block->blobs);
173  blob_it.set_to_list(block->blob_list());
174  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
175  blob = blob_it.extract();
176  newblob = new BLOBNBOX(blob); // Convert blob to BLOBNBOX.
177  SetBlobStrokeWidth(pix, newblob);
178  port_box_it.add_after_then_move(newblob);
179  }
180 
181  // Put the rejected outlines in block->noise_blobs, which allows them to
182  // be reconsidered and sorted back into rows and recover outlines mistakenly
183  // rejected.
184  port_box_it.set_to_list(&port_block->noise_blobs);
185  blob_it.set_to_list(block->reject_blobs());
186  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
187  blob = blob_it.extract();
188  newblob = new BLOBNBOX(blob); // Convert blob to BLOBNBOX.
189  SetBlobStrokeWidth(pix, newblob);
190  port_box_it.add_after_then_move(newblob);
191  }
192 
193  port_block_it.add_after_then_move(port_block);
194  }
195 }
C_BLOB_LIST * blob_list()
get blobs
Definition: ocrblock.h:132
void SetBlobStrokeWidth(Pix *pix, BLOBNBOX *blob)
Definition: tordmain.cpp:55
BLOBNBOX_LIST noise_blobs
Definition: blobbox.h:770
Definition: ocrblock.h:30
C_BLOB_LIST * reject_blobs()
Definition: ocrblock.h:135
BLOBNBOX_LIST blobs
Definition: blobbox.h:768

◆ BlobToTrainingSample()

TrainingSample * tesseract::BlobToTrainingSample ( const TBLOB blob,
bool  nonlinear_norm,
INT_FX_RESULT_STRUCT fx_info,
GenericVector< INT_FEATURE_STRUCT > *  bl_features 
)

Definition at line 81 of file intfx.cpp.

83  {
85  Classify::ExtractFeatures(blob, nonlinear_norm, bl_features,
86  &cn_features, fx_info, NULL);
87  // TODO(rays) Use blob->PreciseBoundingBox() instead.
88  TBOX box = blob.bounding_box();
89  TrainingSample* sample = NULL;
90  int num_features = fx_info->NumCN;
91  if (num_features > 0) {
92  sample = TrainingSample::CopyFromFeatures(*fx_info, box, &cn_features[0],
93  num_features);
94  }
95  if (sample != NULL) {
96  // Set the bounding box (in original image coordinates) in the sample.
97  TPOINT topleft, botright;
98  topleft.x = box.left();
99  topleft.y = box.top();
100  botright.x = box.right();
101  botright.y = box.bottom();
102  TPOINT original_topleft, original_botright;
103  blob.denorm().DenormTransform(NULL, topleft, &original_topleft);
104  blob.denorm().DenormTransform(NULL, botright, &original_botright);
105  sample->set_bounding_box(TBOX(original_topleft.x, original_botright.y,
106  original_botright.x, original_topleft.y));
107  }
108  return sample;
109 }
Definition: blobs.h:50
void DenormTransform(const DENORM *last_denorm, const TPOINT &pt, TPOINT *original) const
Definition: normalis.cpp:389
void set_bounding_box(const TBOX &box)
inT16 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
inT16 left() const
Definition: rect.h:68
Definition: cluster.h:32
inT16 y
Definition: blobs.h:72
TBOX bounding_box() const
Definition: blobs.cpp:482
inT16 right() const
Definition: rect.h:75
inT16 x
Definition: blobs.h:71
const DENORM & denorm() const
Definition: blobs.h:340

◆ BoolFlagExists()

bool tesseract::BoolFlagExists ( const char *  flag_name,
bool *  value 
)

Definition at line 37 of file commandlineflags.cpp.

37  {
38  STRING full_flag_name("FLAGS_");
39  full_flag_name += flag_name;
41  BoolParam *p = ParamUtils::FindParam<BoolParam>(
42  full_flag_name.string(), GlobalParams()->bool_params, empty);
43  if (p == nullptr) return false;
44  *value = (BOOL8)(*p);
45  return true;
46 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< BoolParam * > bool_params
Definition: params.h:45
Definition: strngs.h:45
unsigned char BOOL8
Definition: host.h:44

◆ CairoARGB32ToPixFormat()

Pix* tesseract::CairoARGB32ToPixFormat ( cairo_surface_t *  surface)

Definition at line 72 of file stringrenderer.cpp.

72  {
73  if (cairo_image_surface_get_format(surface) != CAIRO_FORMAT_ARGB32) {
74  printf("Unexpected surface format %d\n",
75  cairo_image_surface_get_format(surface));
76  return nullptr;
77  }
78  const int width = cairo_image_surface_get_width(surface);
79  const int height = cairo_image_surface_get_height(surface);
80  Pix* pix = pixCreate(width, height, 32);
81  int byte_stride = cairo_image_surface_get_stride(surface);
82 
83  for (int i = 0; i < height; ++i) {
84  memcpy(reinterpret_cast<unsigned char*>(pix->data + i * pix->wpl) + 1,
85  cairo_image_surface_get_data(surface) + i * byte_stride,
86  byte_stride - ((i == height - 1) ? 1 : 0));
87  }
88  return pix;
89 }

◆ CalculateTabStops()

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 692 of file paragraphs.cpp.

696  {
697  if (!AcceptableRowArgs(0, 1, __func__, rows, row_start, row_end))
698  return;
699  // First pass: toss all left and right indents into clusterers.
700  SimpleClusterer initial_lefts(tolerance);
701  SimpleClusterer initial_rights(tolerance);
702  GenericVector<Cluster> initial_left_tabs;
703  GenericVector<Cluster> initial_right_tabs;
704  for (int i = row_start; i < row_end; i++) {
705  initial_lefts.Add((*rows)[i].lindent_);
706  initial_rights.Add((*rows)[i].rindent_);
707  }
708  initial_lefts.GetClusters(&initial_left_tabs);
709  initial_rights.GetClusters(&initial_right_tabs);
710 
711  // Second pass: cluster only lines that are not "stray"
712  // An example of a stray line is a page number -- a line whose start
713  // and end tab-stops are far outside the typical start and end tab-stops
714  // for the block.
715  // Put another way, we only cluster data from lines whose start or end
716  // tab stop is frequent.
717  SimpleClusterer lefts(tolerance);
718  SimpleClusterer rights(tolerance);
719 
720  // Outlier elimination. We might want to switch this to test outlier-ness
721  // based on how strange a position an outlier is in instead of or in addition
722  // to how rare it is. These outliers get re-added if we end up having too
723  // few tab stops, to work with, however.
724  int infrequent_enough_to_ignore = 0;
725  if (row_end - row_start >= 8) infrequent_enough_to_ignore = 1;
726  if (row_end - row_start >= 20) infrequent_enough_to_ignore = 2;
727 
728  for (int i = row_start; i < row_end; i++) {
729  int lidx = ClosestCluster(initial_left_tabs, (*rows)[i].lindent_);
730  int ridx = ClosestCluster(initial_right_tabs, (*rows)[i].rindent_);
731  if (initial_left_tabs[lidx].count > infrequent_enough_to_ignore ||
732  initial_right_tabs[ridx].count > infrequent_enough_to_ignore) {
733  lefts.Add((*rows)[i].lindent_);
734  rights.Add((*rows)[i].rindent_);
735  }
736  }
737  lefts.GetClusters(left_tabs);
738  rights.GetClusters(right_tabs);
739 
740  if ((left_tabs->size() == 1 && right_tabs->size() >= 4) ||
741  (right_tabs->size() == 1 && left_tabs->size() >= 4)) {
742  // One side is really ragged, and the other only has one tab stop,
743  // so those "insignificant outliers" are probably important, actually.
744  // This often happens on a page of an index. Add back in the ones
745  // we omitted in the first pass.
746  for (int i = row_start; i < row_end; i++) {
747  int lidx = ClosestCluster(initial_left_tabs, (*rows)[i].lindent_);
748  int ridx = ClosestCluster(initial_right_tabs, (*rows)[i].rindent_);
749  if (!(initial_left_tabs[lidx].count > infrequent_enough_to_ignore ||
750  initial_right_tabs[ridx].count > infrequent_enough_to_ignore)) {
751  lefts.Add((*rows)[i].lindent_);
752  rights.Add((*rows)[i].rindent_);
753  }
754  }
755  }
756  lefts.GetClusters(left_tabs);
757  rights.GetClusters(right_tabs);
758 
759  // If one side is almost a two-indent aligned side, and the other clearly
760  // isn't, try to prune out the least frequent tab stop from that side.
761  if (left_tabs->size() == 3 && right_tabs->size() >= 4) {
762  int to_prune = -1;
763  for (int i = left_tabs->size() - 1; i >= 0; i--) {
764  if (to_prune < 0 ||
765  (*left_tabs)[i].count < (*left_tabs)[to_prune].count) {
766  to_prune = i;
767  }
768  }
769  if (to_prune >= 0 &&
770  (*left_tabs)[to_prune].count <= infrequent_enough_to_ignore) {
771  left_tabs->remove(to_prune);
772  }
773  }
774  if (right_tabs->size() == 3 && left_tabs->size() >= 4) {
775  int to_prune = -1;
776  for (int i = right_tabs->size() - 1; i >= 0; i--) {
777  if (to_prune < 0 ||
778  (*right_tabs)[i].count < (*right_tabs)[to_prune].count) {
779  to_prune = i;
780  }
781  }
782  if (to_prune >= 0 &&
783  (*right_tabs)[to_prune].count <= infrequent_enough_to_ignore) {
784  right_tabs->remove(to_prune);
785  }
786  }
787 }
void remove(int index)
int size() const
Definition: genericvector.h:72
int ClosestCluster(const GenericVector< Cluster > &clusters, int value)
Definition: paragraphs.cpp:666
int count(LIST var_list)
Definition: oldlist.cpp:103

◆ CallWithUTF8()

void tesseract::CallWithUTF8 ( TessCallback1< const char *> *  cb,
const WERD_CHOICE wc 
)

Definition at line 111 of file dawg.cpp.

111  {
112  STRING s;
113  wc->string_and_lengths(&s, NULL);
114  cb->Run(s.string());
115 }
const char * string() const
Definition: strngs.cpp:198
Definition: strngs.h:45
virtual void Run(A1)=0
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
Definition: ratngs.cpp:430

◆ CanonicalizeDetectionResults()

void tesseract::CanonicalizeDetectionResults ( GenericVector< PARA *> *  row_owners,
PARA_LIST *  paragraphs 
)

Definition at line 2234 of file paragraphs.cpp.

2236  {
2237  GenericVector<PARA *> &rows = *row_owners;
2238  paragraphs->clear();
2239  PARA_IT out(paragraphs);
2240  PARA *formerly_null = NULL;
2241  for (int i = 0; i < rows.size(); i++) {
2242  if (rows[i] == NULL) {
2243  if (i == 0 || rows[i - 1] != formerly_null) {
2244  rows[i] = formerly_null = new PARA();
2245  } else {
2246  rows[i] = formerly_null;
2247  continue;
2248  }
2249  } else if (i > 0 && rows[i - 1] == rows[i]) {
2250  continue;
2251  }
2252  out.add_after_then_move(rows[i]);
2253  }
2254 }
int size() const
Definition: genericvector.h:72
Definition: ocrpara.h:29

◆ ClearFeatureSpaceWindow()

void tesseract::ClearFeatureSpaceWindow ( NORM_METHOD  norm_method,
ScrollView window 
)

Clears the given window and draws the featurespace guides for the appropriate normalization method.

Definition at line 1033 of file intproto.cpp.

1033  {
1034  window->Clear();
1035 
1036  window->Pen(ScrollView::GREY);
1037  // Draw the feature space limit rectangle.
1038  window->Rectangle(0, 0, INT_MAX_X, INT_MAX_Y);
1039  if (norm_method == baseline) {
1040  window->SetCursor(0, INT_DESCENDER);
1041  window->DrawTo(INT_MAX_X, INT_DESCENDER);
1042  window->SetCursor(0, INT_BASELINE);
1043  window->DrawTo(INT_MAX_X, INT_BASELINE);
1044  window->SetCursor(0, INT_XHEIGHT);
1045  window->DrawTo(INT_MAX_X, INT_XHEIGHT);
1046  window->SetCursor(0, INT_CAPHEIGHT);
1047  window->DrawTo(INT_MAX_X, INT_CAPHEIGHT);
1048  } else {
1051  }
1052 }
#define INT_BASELINE
Definition: intproto.cpp:55
#define INT_XHEIGHT
Definition: intproto.cpp:56
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
#define INT_DESCENDER
Definition: intproto.cpp:54
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:606
#define INT_MAX_Y
Definition: intproto.cpp:66
#define INT_YCENTER
Definition: intproto.cpp:60
void Pen(Color color)
Definition: scrollview.cpp:726
void Clear()
Definition: scrollview.cpp:595
#define INT_XCENTER
Definition: intproto.cpp:59
#define INT_YRADIUS
Definition: intproto.cpp:62
#define INT_XRADIUS
Definition: intproto.cpp:61
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
#define INT_MAX_X
Definition: intproto.cpp:65
#define INT_CAPHEIGHT
Definition: intproto.cpp:57

◆ ClipBaseline()

void tesseract::ClipBaseline ( int  ppi,
int  x1,
int  y1,
int  x2,
int  y2,
int *  line_x1,
int *  line_y1,
int *  line_x2,
int *  line_y2 
)

Definition at line 296 of file pdfrenderer.cpp.

298  {
299  *line_x1 = x1;
300  *line_y1 = y1;
301  *line_x2 = x2;
302  *line_y2 = y2;
303  double rise = abs(y2 - y1) * 72 / ppi;
304  double run = abs(x2 - x1) * 72 / ppi;
305  if (rise < 2.0 && 2.0 < run)
306  *line_y1 = *line_y2 = (y1 + y2) / 2;
307 }

◆ ClipVector()

template<typename T >
void tesseract::ClipVector ( int  n,
lower,
upper,
T *  vec 
)
inline

Definition at line 225 of file functions.h.

225  {
226  for (int i = 0; i < n; ++i) vec[i] = ClipToRange(vec[i], lower, upper);
227 }
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122

◆ ClosestCluster()

int tesseract::ClosestCluster ( const GenericVector< Cluster > &  clusters,
int  value 
)

Definition at line 666 of file paragraphs.cpp.

666  {
667  int best_index = 0;
668  for (int i = 0; i < clusters.size(); i++) {
669  if (abs(value - clusters[i].center) <
670  abs(value - clusters[best_index].center))
671  best_index = i;
672  }
673  return best_index;
674 }
int size() const
Definition: genericvector.h:72

◆ cmp_eq()

template<typename T >
bool tesseract::cmp_eq ( T const &  t1,
T const &  t2 
)

Definition at line 414 of file genericvector.h.

414  {
415  return t1 == t2;
416 }

◆ CmpPairSecond()

bool tesseract::CmpPairSecond ( const std::pair< int, int > &  p1,
const std::pair< int, int > &  p2 
)

Definition at line 126 of file validator.cpp.

127  {
128  return p1.second < p2.second;
129 }

◆ CodeInBinary()

void tesseract::CodeInBinary ( int  n,
int  nf,
double *  vec 
)
inline

Definition at line 231 of file functions.h.

231  {
232  if (nf <= 0 || n < nf) return;
233  int index = 0;
234  double best_score = vec[0];
235  for (int i = 1; i < n; ++i) {
236  if (vec[i] > best_score) {
237  best_score = vec[i];
238  index = i;
239  }
240  }
241  int mask = 1;
242  for (int i = 0; i < nf; ++i, mask *= 2) {
243  vec[i] = (index & mask) ? 1.0 : 0.0;
244  }
245 }

◆ CodepointToUtf16be()

bool tesseract::CodepointToUtf16be ( int  code,
char  utf16[kMaxBytesPerCodepoint] 
)

Definition at line 309 of file pdfrenderer.cpp.

309  {
310  if ((code > 0xD7FF && code < 0xE000) || code > 0x10FFFF) {
311  tprintf("Dropping invalid codepoint %d\n", code);
312  return false;
313  }
314  if (code < 0x10000) {
315  snprintf(utf16, kMaxBytesPerCodepoint, "%04X", code);
316  } else {
317  int a = code - 0x010000;
318  int high_surrogate = (0x03FF & (a >> 10)) + 0xD800;
319  int low_surrogate = (0x03FF & a) + 0xDC00;
320  snprintf(utf16, kMaxBytesPerCodepoint,
321  "%04X%04X", high_surrogate, low_surrogate);
322  }
323  return true;
324 }
#define tprintf(...)
Definition: tprintf.h:31

◆ CombineLangModel()

int tesseract::CombineLangModel ( const UNICHARSET unicharset,
const string &  script_dir,
const string &  version_str,
const string &  output_dir,
const string &  lang,
bool  pass_through_recoder,
const GenericVector< STRING > &  words,
const GenericVector< STRING > &  puncs,
const GenericVector< STRING > &  numbers,
bool  lang_is_rtl,
FileReader  reader,
FileWriter  writer 
)

Definition at line 185 of file lang_model_helpers.cpp.

191  {
192  // Build the traineddata file.
193  TessdataManager traineddata;
194  if (!version_str.empty()) {
195  traineddata.SetVersionString(traineddata.VersionString() + ":" +
196  version_str);
197  }
198  // Unicharset and recoder.
199  if (!WriteUnicharset(unicharset, output_dir, lang, writer, &traineddata)) {
200  tprintf("Error writing unicharset!!\n");
201  return EXIT_FAILURE;
202  } else {
203  tprintf("Config file is optional, continuing...\n");
204  }
205  // If there is a config file, read it and add to traineddata.
206  string config_filename = script_dir + "/" + lang + "/" + lang + ".config";
207  STRING config_file = ReadFile(config_filename, reader);
208  if (config_file.length() > 0) {
209  traineddata.OverwriteEntry(TESSDATA_LANG_CONFIG, &config_file[0],
210  config_file.length());
211  }
212  string radical_filename = script_dir + "/radical-stroke.txt";
213  STRING radical_data = ReadFile(radical_filename, reader);
214  if (radical_data.length() == 0) {
215  tprintf("Error reading radical code table %s\n", radical_filename.c_str());
216  return EXIT_FAILURE;
217  }
218  if (!WriteRecoder(unicharset, pass_through_recoder, output_dir, lang, writer,
219  &radical_data, &traineddata)) {
220  tprintf("Error writing recoder!!\n");
221  }
222  if (!words.empty() || !puncs.empty() || !numbers.empty()) {
223  if (!WriteDawgs(words, puncs, numbers, lang_is_rtl, unicharset,
224  &traineddata)) {
225  tprintf("Error during conversion of wordlists to DAWGs!!\n");
226  return EXIT_FAILURE;
227  }
228  }
229 
230  // Traineddata file.
231  GenericVector<char> traineddata_data;
232  traineddata.Serialize(&traineddata_data);
233  if (!WriteFile(output_dir, lang, ".traineddata", traineddata_data, writer)) {
234  tprintf("Error writing output traineddata file!!\n");
235  return EXIT_FAILURE;
236  }
237  return EXIT_SUCCESS;
238 }
bool empty() const
Definition: genericvector.h:91
bool WriteUnicharset(const UNICHARSET &unicharset, const string &output_dir, const string &lang, FileWriter writer, TessdataManager *traineddata)
bool WriteRecoder(const UNICHARSET &unicharset, bool pass_through, const string &output_dir, const string &lang, FileWriter writer, STRING *radical_table_data, TessdataManager *traineddata)
#define tprintf(...)
Definition: tprintf.h:31
bool Serialize(FILE *fp) const
Definition: strngs.h:45
bool WriteFile(const string &output_dir, const string &lang, const string &suffix, const GenericVector< char > &data, FileWriter writer)
STRING ReadFile(const string &filename, FileReader reader)
inT32 length() const
Definition: strngs.cpp:193

◆ CompareFontInfo()

bool tesseract::CompareFontInfo ( const FontInfo fi1,
const FontInfo fi2 
)

Definition at line 120 of file fontinfo.cpp.

120  {
121  // The font properties are required to be the same for two font with the same
122  // name, so there is no need to test them.
123  // Consequently, querying the table with only its font name as information is
124  // enough to retrieve its properties.
125  return strcmp(fi1.name, fi2.name) == 0;
126 }

◆ CompareFontSet()

bool tesseract::CompareFontSet ( const FontSet fs1,
const FontSet fs2 
)

Definition at line 128 of file fontinfo.cpp.

128  {
129  if (fs1.size != fs2.size)
130  return false;
131  for (int i = 0; i < fs1.size; ++i) {
132  if (fs1.configs[i] != fs2.configs[i])
133  return false;
134  }
135  return true;
136 }

◆ ConvertHypothesizedModelRunsToParagraphs()

void tesseract::ConvertHypothesizedModelRunsToParagraphs ( int  debug_level,
const GenericVector< RowScratchRegisters > &  rows,
GenericVector< PARA *> *  row_owners,
ParagraphTheory theory 
)

Definition at line 2042 of file paragraphs.cpp.

2046  {
2047  int end = rows.size();
2048  int start;
2049  for (; end > 0; end = start) {
2050  start = end - 1;
2051  const ParagraphModel *model = NULL;
2052  // TODO(eger): Be smarter about dealing with multiple hypotheses.
2053  bool single_line_paragraph = false;
2054  SetOfModels models;
2055  rows[start].NonNullHypotheses(&models);
2056  if (!models.empty()) {
2057  model = models[0];
2058  if (rows[start].GetLineType(model) != LT_BODY)
2059  single_line_paragraph = true;
2060  }
2061  if (model && !single_line_paragraph) {
2062  // walk back looking for more body lines and then a start line.
2063  while (--start > 0 && rows[start].GetLineType(model) == LT_BODY) {
2064  // do nothing
2065  }
2066  if (start < 0 || rows[start].GetLineType(model) != LT_START) {
2067  model = NULL;
2068  }
2069  }
2070  if (model == NULL) {
2071  continue;
2072  }
2073  // rows[start, end) should be a paragraph.
2074  PARA *p = new PARA();
2075  if (model == kCrownLeft || model == kCrownRight) {
2077  // Crown paragraph.
2078  // If we can find an existing ParagraphModel that fits, use it,
2079  // else create a new one.
2080  for (int row = end; row < rows.size(); row++) {
2081  if ((*row_owners)[row] &&
2082  (ValidBodyLine(&rows, start, (*row_owners)[row]->model) &&
2083  (start == 0 ||
2084  ValidFirstLine(&rows, start, (*row_owners)[row]->model)))) {
2085  model = (*row_owners)[row]->model;
2086  break;
2087  }
2088  }
2089  if (model == kCrownLeft) {
2090  // No subsequent model fits, so cons one up.
2091  model = theory->AddModel(ParagraphModel(
2092  JUSTIFICATION_LEFT, rows[start].lmargin_ + rows[start].lindent_,
2093  0, 0, Epsilon(rows[start].ri_->average_interword_space)));
2094  } else if (model == kCrownRight) {
2095  // No subsequent model fits, so cons one up.
2096  model = theory->AddModel(ParagraphModel(
2097  JUSTIFICATION_RIGHT, rows[start].rmargin_ + rows[start].rmargin_,
2098  0, 0, Epsilon(rows[start].ri_->average_interword_space)));
2099  }
2100  }
2101  rows[start].SetUnknown();
2102  rows[start].AddStartLine(model);
2103  for (int i = start + 1; i < end; i++) {
2104  rows[i].SetUnknown();
2105  rows[i].AddBodyLine(model);
2106  }
2107  p->model = model;
2108  p->has_drop_cap = rows[start].ri_->has_drop_cap;
2109  p->is_list_item =
2111  ? rows[start].ri_->rword_indicates_list_item
2112  : rows[start].ri_->lword_indicates_list_item;
2113  for (int row = start; row < end; row++) {
2114  if ((*row_owners)[row] != NULL) {
2115  tprintf("Memory leak! ConvertHypothesizeModelRunsToParagraphs() called "
2116  "more than once!\n");
2117  delete (*row_owners)[row];
2118  }
2119  (*row_owners)[row] = p;
2120  }
2121  }
2122 }
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
bool is_list_item
Definition: ocrpara.h:38
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:46
int size() const
Definition: genericvector.h:72
bool has_drop_cap
Definition: ocrpara.h:46
#define tprintf(...)
Definition: tprintf.h:31
Definition: ocrpara.h:29
GenericVectorEqEq< const ParagraphModel * > SetOfModels
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:48
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool is_very_first_or_continuation
Definition: ocrpara.h:43
const ParagraphModel * model
Definition: ocrpara.h:36

◆ CopyVector()

void tesseract::CopyVector ( int  n,
const double *  src,
double *  dest 
)
inline

Definition at line 186 of file functions.h.

186  {
187  memcpy(dest, src, n * sizeof(dest[0]));
188 }

◆ CrownCompatible()

bool tesseract::CrownCompatible ( const GenericVector< RowScratchRegisters > *  rows,
int  a,
int  b,
const ParagraphModel model 
)

Definition at line 1289 of file paragraphs.cpp.

1290  {
1291  if (model != kCrownRight && model != kCrownLeft) {
1292  tprintf("CrownCompatible() should only be called with crown models!\n");
1293  return false;
1294  }
1295  RowScratchRegisters &row_a = (*rows)[a];
1296  RowScratchRegisters &row_b = (*rows)[b];
1297  if (model == kCrownRight) {
1298  return NearlyEqual(row_a.rindent_ + row_a.rmargin_,
1299  row_b.rindent_ + row_b.rmargin_,
1300  Epsilon(row_a.ri_->average_interword_space));
1301  }
1302  return NearlyEqual(row_a.lindent_ + row_a.lmargin_,
1303  row_b.lindent_ + row_b.lmargin_,
1304  Epsilon(row_a.ri_->average_interword_space));
1305 }
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:46
#define tprintf(...)
Definition: tprintf.h:31
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:48
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87

◆ DegradeImage()

struct Pix * tesseract::DegradeImage ( Pix *  input,
int  exposure,
TRand randomizer,
float *  rotation 
)

Definition at line 91 of file degradeimage.cpp.

92  {
93  Pix* pix = pixConvertTo8(input, false);
94  pixDestroy(&input);
95  input = pix;
96  int width = pixGetWidth(input);
97  int height = pixGetHeight(input);
98  if (exposure >= 2) {
99  // An erosion simulates the spreading darkening of a dark copy.
100  // This is backwards to binary morphology,
101  // see http://www.leptonica.com/grayscale-morphology.html
102  pix = input;
103  input = pixErodeGray(pix, 3, 3);
104  pixDestroy(&pix);
105  }
106  // A convolution is essential to any mode as no scanner produces an
107  // image as sharp as the electronic image.
108  pix = pixBlockconv(input, 1, 1);
109  pixDestroy(&input);
110  // A small random rotation helps to make the edges jaggy in a realistic way.
111  if (rotation != nullptr) {
112  float radians_clockwise = 0.0f;
113  if (*rotation) {
114  radians_clockwise = *rotation;
115  } else if (randomizer != nullptr) {
116  radians_clockwise = randomizer->SignedRand(kRotationRange);
117  }
118 
119  input = pixRotate(pix, radians_clockwise,
120  L_ROTATE_AREA_MAP, L_BRING_IN_WHITE,
121  0, 0);
122  // Rotate the boxes to match.
123  *rotation = radians_clockwise;
124  pixDestroy(&pix);
125  } else {
126  input = pix;
127  }
128 
129  if (exposure >= 3 || exposure == 1) {
130  // Erosion after the convolution is not as heavy as before, so it is
131  // good for level 1 and in addition as a level 3.
132  // This is backwards to binary morphology,
133  // see http://www.leptonica.com/grayscale-morphology.html
134  pix = input;
135  input = pixErodeGray(pix, 3, 3);
136  pixDestroy(&pix);
137  }
138  // The convolution really needed to be 2x2 to be realistic enough, but
139  // we only have 3x3, so we have to bias the image darker or lose thin
140  // strokes.
141  int erosion_offset = 0;
142  // For light and 0 exposure, there is no dilation, so compensate for the
143  // convolution with a big darkening bias which is undone for lighter
144  // exposures.
145  if (exposure <= 0)
146  erosion_offset = -3 * kExposureFactor;
147  // Add in a general offset of the greyscales for the exposure level so
148  // a threshold of 128 gives a reasonable binary result.
149  erosion_offset -= exposure * kExposureFactor;
150  // Add a gradual fade over the page and a small amount of salt and pepper
151  // noise to simulate noise in the sensor/paper fibres and varying
152  // illumination.
153  l_uint32* data = pixGetData(input);
154  for (int y = 0; y < height; ++y) {
155  for (int x = 0; x < width; ++x) {
156  int pixel = GET_DATA_BYTE(data, x);
157  if (randomizer != nullptr)
158  pixel += randomizer->IntRand() % (kSaltnPepper*2 + 1) - kSaltnPepper;
159  if (height + width > kMinRampSize)
160  pixel -= (2*x + y) * 32 / (height + width);
161  pixel += erosion_offset;
162  if (pixel < 0)
163  pixel = 0;
164  if (pixel > 255)
165  pixel = 255;
166  SET_DATA_BYTE(data, x, pixel);
167  }
168  data += input->wpl;
169  }
170  return input;
171 }
const int kSaltnPepper
const int kExposureFactor
const int kMinRampSize
const float kRotationRange

◆ DeleteObject()

template<typename T >
void tesseract::DeleteObject ( T *  object)

Definition at line 159 of file tablefind.cpp.

159  {
160  delete object;
161 }

◆ DetectParagraphs() [1/2]

void tesseract::DetectParagraphs ( int  debug_level,
GenericVector< RowInfo > *  row_infos,
GenericVector< PARA *> *  row_owners,
PARA_LIST *  paragraphs,
GenericVector< ParagraphModel *> *  models 
)

Definition at line 2266 of file paragraphs.cpp.

2270  {
2272  ParagraphTheory theory(models);
2273 
2274  // Initialize row_owners to be a bunch of NULL pointers.
2275  row_owners->init_to_size(row_infos->size(), NULL);
2276 
2277  // Set up row scratch registers for the main algorithm.
2278  rows.init_to_size(row_infos->size(), RowScratchRegisters());
2279  for (int i = 0; i < row_infos->size(); i++) {
2280  rows[i].Init((*row_infos)[i]);
2281  }
2282 
2283  // Pass 1:
2284  // Detect sequences of lines that all contain leader dots (.....)
2285  // These are likely Tables of Contents. If there are three text lines in
2286  // a row with leader dots, it's pretty safe to say the middle one should
2287  // be a paragraph of its own.
2288  SeparateSimpleLeaderLines(&rows, 0, rows.size(), &theory);
2289 
2290  DebugDump(debug_level > 1, "End of Pass 1", theory, rows);
2291 
2292  GenericVector<Interval> leftovers;
2293  LeftoverSegments(rows, &leftovers, 0, rows.size());
2294  for (int i = 0; i < leftovers.size(); i++) {
2295  // Pass 2a:
2296  // Find any strongly evidenced start-of-paragraph lines. If they're
2297  // followed by two lines that look like body lines, make a paragraph
2298  // model for that and see if that model applies throughout the text
2299  // (that is, "smear" it).
2300  StrongEvidenceClassify(debug_level, &rows,
2301  leftovers[i].begin, leftovers[i].end, &theory);
2302 
2303  // Pass 2b:
2304  // If we had any luck in pass 2a, we got part of the page and didn't
2305  // know how to classify a few runs of rows. Take the segments that
2306  // didn't find a model and reprocess them individually.
2307  GenericVector<Interval> leftovers2;
2308  LeftoverSegments(rows, &leftovers2, leftovers[i].begin, leftovers[i].end);
2309  bool pass2a_was_useful = leftovers2.size() > 1 ||
2310  (leftovers2.size() == 1 &&
2311  (leftovers2[0].begin != 0 || leftovers2[0].end != rows.size()));
2312  if (pass2a_was_useful) {
2313  for (int j = 0; j < leftovers2.size(); j++) {
2314  StrongEvidenceClassify(debug_level, &rows,
2315  leftovers2[j].begin, leftovers2[j].end,
2316  &theory);
2317  }
2318  }
2319  }
2320 
2321  DebugDump(debug_level > 1, "End of Pass 2", theory, rows);
2322 
2323  // Pass 3:
2324  // These are the dregs for which we didn't have enough strong textual
2325  // and geometric clues to form matching models for. Let's see if
2326  // the geometric clues are simple enough that we could just use those.
2327  LeftoverSegments(rows, &leftovers, 0, rows.size());
2328  for (int i = 0; i < leftovers.size(); i++) {
2329  GeometricClassify(debug_level, &rows,
2330  leftovers[i].begin, leftovers[i].end, &theory);
2331  }
2332 
2333  // Undo any flush models for which there's little evidence.
2334  DowngradeWeakestToCrowns(debug_level, &theory, &rows);
2335 
2336  DebugDump(debug_level > 1, "End of Pass 3", theory, rows);
2337 
2338  // Pass 4:
2339  // Take everything that's still not marked up well and clear all markings.
2340  LeftoverSegments(rows, &leftovers, 0, rows.size());
2341  for (int i = 0; i < leftovers.size(); i++) {
2342  for (int j = leftovers[i].begin; j < leftovers[i].end; j++) {
2343  rows[j].SetUnknown();
2344  }
2345  }
2346 
2347  DebugDump(debug_level > 1, "End of Pass 4", theory, rows);
2348 
2349  // Convert all of the unique hypothesis runs to PARAs.
2350  ConvertHypothesizedModelRunsToParagraphs(debug_level, rows, row_owners,
2351  &theory);
2352 
2353  DebugDump(debug_level > 0, "Final Paragraph Segmentation", theory, rows);
2354 
2355  // Finally, clean up any dangling NULL row paragraph parents.
2356  CanonicalizeDetectionResults(row_owners, paragraphs);
2357 }
void ConvertHypothesizedModelRunsToParagraphs(int debug_level, const GenericVector< RowScratchRegisters > &rows, GenericVector< PARA *> *row_owners, ParagraphTheory *theory)
void SeparateSimpleLeaderLines(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
int size() const
Definition: genericvector.h:72
void LeftoverSegments(const GenericVector< RowScratchRegisters > &rows, GenericVector< Interval > *to_fix, int row_start, int row_end)
void StrongEvidenceClassify(int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
void CanonicalizeDetectionResults(GenericVector< PARA *> *row_owners, PARA_LIST *paragraphs)
void GeometricClassify(int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, ParagraphTheory *theory)
void init_to_size(int size, T t)
void DowngradeWeakestToCrowns(int debug_level, ParagraphTheory *theory, GenericVector< RowScratchRegisters > *rows)

◆ DetectParagraphs() [2/2]

void tesseract::DetectParagraphs ( int  debug_level,
bool  after_text_recognition,
const MutableIterator block_start,
GenericVector< ParagraphModel *> *  models 
)

Definition at line 2510 of file paragraphs.cpp.

2513  {
2514  // Clear out any preconceived notions.
2515  if (block_start->Empty(RIL_TEXTLINE)) {
2516  return;
2517  }
2518  BLOCK *block = block_start->PageResIt()->block()->block;
2519  block->para_list()->clear();
2520  bool is_image_block = block->poly_block() && !block->poly_block()->IsText();
2521 
2522  // Convert the Tesseract structures to RowInfos
2523  // for the paragraph detection algorithm.
2524  MutableIterator row(*block_start);
2525  if (row.Empty(RIL_TEXTLINE))
2526  return; // end of input already.
2527 
2528  GenericVector<RowInfo> row_infos;
2529  do {
2530  if (!row.PageResIt()->row())
2531  continue; // empty row.
2532  row.PageResIt()->row()->row->set_para(NULL);
2533  row_infos.push_back(RowInfo());
2534  RowInfo &ri = row_infos.back();
2535  InitializeRowInfo(after_text_recognition, row, &ri);
2536  } while (!row.IsAtFinalElement(RIL_BLOCK, RIL_TEXTLINE) &&
2537  row.Next(RIL_TEXTLINE));
2538 
2539  // If we're called before text recognition, we might not have
2540  // tight block bounding boxes, so trim by the minimum on each side.
2541  if (!row_infos.empty()) {
2542  int min_lmargin = row_infos[0].pix_ldistance;
2543  int min_rmargin = row_infos[0].pix_rdistance;
2544  for (int i = 1; i < row_infos.size(); i++) {
2545  if (row_infos[i].pix_ldistance < min_lmargin)
2546  min_lmargin = row_infos[i].pix_ldistance;
2547  if (row_infos[i].pix_rdistance < min_rmargin)
2548  min_rmargin = row_infos[i].pix_rdistance;
2549  }
2550  if (min_lmargin > 0 || min_rmargin > 0) {
2551  for (int i = 0; i < row_infos.size(); i++) {
2552  row_infos[i].pix_ldistance -= min_lmargin;
2553  row_infos[i].pix_rdistance -= min_rmargin;
2554  }
2555  }
2556  }
2557 
2558  // Run the paragraph detection algorithm.
2559  GenericVector<PARA *> row_owners;
2560  GenericVector<PARA *> the_paragraphs;
2561  if (!is_image_block) {
2562  DetectParagraphs(debug_level, &row_infos, &row_owners, block->para_list(),
2563  models);
2564  } else {
2565  row_owners.init_to_size(row_infos.size(), NULL);
2566  CanonicalizeDetectionResults(&row_owners, block->para_list());
2567  }
2568 
2569  // Now stitch in the row_owners into the rows.
2570  row = *block_start;
2571  for (int i = 0; i < row_owners.size(); i++) {
2572  while (!row.PageResIt()->row())
2573  row.Next(RIL_TEXTLINE);
2574  row.PageResIt()->row()->row->set_para(row_owners[i]);
2575  row.Next(RIL_TEXTLINE);
2576  }
2577 }
bool empty() const
Definition: genericvector.h:91
T & back() const
int size() const
Definition: genericvector.h:72
Definition: ocrblock.h:30
bool IsText() const
Definition: polyblk.h:52
void DetectParagraphs(int debug_level, bool after_text_recognition, const MutableIterator *block_start, GenericVector< ParagraphModel *> *models)
int push_back(T object)
void CanonicalizeDetectionResults(GenericVector< PARA *> *row_owners, PARA_LIST *paragraphs)
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
void InitializeRowInfo(bool after_recognition, const MutableIterator &it, RowInfo *info)
Definition: capi.h:92
void init_to_size(int size, T t)
PARA_LIST * para_list()
Definition: ocrblock.h:128

◆ DiscardUnusedModels()

void tesseract::DiscardUnusedModels ( const GenericVector< RowScratchRegisters > &  rows,
ParagraphTheory theory 
)

Definition at line 1456 of file paragraphs.cpp.

1457  {
1458  SetOfModels used_models;
1459  for (int i = 0; i < rows.size(); i++) {
1460  rows[i].StrongHypotheses(&used_models);
1461  }
1462  theory->DiscardUnusedModels(used_models);
1463 }
int size() const
Definition: genericvector.h:72
GenericVectorEqEq< const ParagraphModel * > SetOfModels

◆ dist2()

long tesseract::dist2 ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 213 of file pdfrenderer.cpp.

213  {
214  return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
215 }

◆ DotProductAVX()

double tesseract::DotProductAVX ( const double *  u,
const double *  v,
int  n 
)

Definition at line 27 of file dotproductavx.cpp.

27  {
28  fprintf(stderr, "DotProductAVX can't be used on Android\n");
29  abort();
30 }

◆ DotProductSSE()

double tesseract::DotProductSSE ( const double *  u,
const double *  v,
int  n 
)

Definition at line 27 of file dotproductsse.cpp.

27  {
28  fprintf(stderr, "DotProductSSE can't be used on Android\n");
29  abort();
30 }

◆ DoubleFlagExists()

bool tesseract::DoubleFlagExists ( const char *  flag_name,
double *  value 
)

Definition at line 26 of file commandlineflags.cpp.

26  {
27  STRING full_flag_name("FLAGS_");
28  full_flag_name += flag_name;
30  DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
31  full_flag_name.string(), GlobalParams()->double_params, empty);
32  if (p == nullptr) return false;
33  *value = static_cast<double>(*p);
34  return true;
35 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< DoubleParam * > double_params
Definition: params.h:47
Definition: strngs.h:45

◆ DowngradeWeakestToCrowns()

void tesseract::DowngradeWeakestToCrowns ( int  debug_level,
ParagraphTheory theory,
GenericVector< RowScratchRegisters > *  rows 
)

Definition at line 1489 of file paragraphs.cpp.

1491  {
1492  int start;
1493  for (int end = rows->size(); end > 0; end = start) {
1494  // Search back for a body line of a unique type.
1495  const ParagraphModel *model = NULL;
1496  while (end > 0 &&
1497  (model = (*rows)[end - 1].UniqueBodyHypothesis()) == NULL) {
1498  end--;
1499  }
1500  if (end == 0) break;
1501  start = end - 1;
1502  while (start >= 0 && (*rows)[start].UniqueBodyHypothesis() == model) {
1503  start--; // walk back to the first line that is not the same body type.
1504  }
1505  if (start >= 0 && (*rows)[start].UniqueStartHypothesis() == model &&
1506  StrongModel(model) &&
1507  NearlyEqual(model->first_indent(), model->body_indent(),
1508  model->tolerance())) {
1509  start--;
1510  }
1511  start++;
1512  // Now rows[start, end) is a sequence of unique body hypotheses of model.
1513  if (StrongModel(model) && model->justification() == JUSTIFICATION_CENTER)
1514  continue;
1515  if (!StrongModel(model)) {
1516  while (start > 0 &&
1517  CrownCompatible(rows, start - 1, start, model))
1518  start--;
1519  }
1520  if (start == 0 ||
1521  (!StrongModel(model)) ||
1522  (StrongModel(model) && !ValidFirstLine(rows, start - 1, model))) {
1523  // crownify rows[start, end)
1524  const ParagraphModel *crown_model = model;
1525  if (StrongModel(model)) {
1526  if (model->justification() == JUSTIFICATION_LEFT)
1527  crown_model = kCrownLeft;
1528  else
1529  crown_model = kCrownRight;
1530  }
1531  (*rows)[start].SetUnknown();
1532  (*rows)[start].AddStartLine(crown_model);
1533  for (int row = start + 1; row < end; row++) {
1534  (*rows)[row].SetUnknown();
1535  (*rows)[row].AddBodyLine(crown_model);
1536  }
1537  }
1538  }
1539  DiscardUnusedModels(*rows, theory);
1540 }
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
int first_indent() const
Definition: ocrpara.h:168
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:46
bool StrongModel(const ParagraphModel *model)
bool CrownCompatible(const GenericVector< RowScratchRegisters > *rows, int a, int b, const ParagraphModel *model)
void DiscardUnusedModels(const GenericVector< RowScratchRegisters > &rows, ParagraphTheory *theory)
int size() const
Definition: genericvector.h:72
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:48
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
int tolerance() const
Definition: ocrpara.h:170
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87
int body_indent() const
Definition: ocrpara.h:169

◆ ExtractFontName()

void tesseract::ExtractFontName ( const STRING filename,
STRING fontname 
)

Public Code

Definition at line 46 of file blobclass.cpp.

46  {
47  *fontname = classify_font_name;
48  if (*fontname == kUnknownFontName) {
49  // filename is expected to be of the form [lang].[fontname].exp[num]
50  // The [lang], [fontname] and [num] fields should not have '.' characters.
51  const char *basename = strrchr(filename.string(), '/');
52  const char *firstdot = strchr(basename ? basename : filename.string(), '.');
53  const char *lastdot = strrchr(filename.string(), '.');
54  if (firstdot != lastdot && firstdot != NULL && lastdot != NULL) {
55  ++firstdot;
56  *fontname = firstdot;
57  fontname->truncate_at(lastdot - firstdot);
58  }
59  }
60 }
char * classify_font_name
Definition: blobclass.cpp:35
const char * string() const
Definition: strngs.cpp:198
void truncate_at(inT32 index)
Definition: strngs.cpp:269

◆ ExtractFontProperties()

void tesseract::ExtractFontProperties ( const string &  utf8_text,
StringRenderer render,
const string &  output_base 
)

Definition at line 210 of file text2image.cpp.

212  {
213  std::map<string, SpacingProperties> spacing_map;
214  std::map<string, SpacingProperties>::iterator spacing_map_it0;
215  std::map<string, SpacingProperties>::iterator spacing_map_it1;
216  int x_bearing, x_advance;
217  int len = utf8_text.length();
218  int offset = 0;
219  const char* text = utf8_text.c_str();
220  while (offset < len) {
221  offset +=
222  render->RenderToImage(text + offset, strlen(text + offset), nullptr);
223  const std::vector<BoxChar*> &boxes = render->GetBoxes();
224 
225  // If the page break split a bigram, correct the offset so we try the bigram
226  // on the next iteration.
227  if (boxes.size() > 2 && !IsWhitespaceBox(boxes[boxes.size() - 1]) &&
228  IsWhitespaceBox(boxes[boxes.size() - 2])) {
229  if (boxes.size() > 3) {
230  tprintf("WARNING: Adjusting to bad page break after '%s%s'\n",
231  boxes[boxes.size() - 4]->ch().c_str(),
232  boxes[boxes.size() - 3]->ch().c_str());
233  }
234  offset -= boxes[boxes.size() - 1]->ch().size();
235  }
236 
237  for (size_t b = 0; b < boxes.size(); b += 2) {
238  while (b < boxes.size() && IsWhitespaceBox(boxes[b])) ++b;
239  if (b + 1 >= boxes.size()) break;
240  const string &ch0 = boxes[b]->ch();
241  // We encountered a ligature. This happens in at least two scenarios:
242  // One is when the rendered bigram forms a grapheme cluster (eg. the
243  // second character in the bigram is a combining vowel), in which case we
244  // correctly output only one bounding box.
245  // A second far less frequent case is when caused some fonts like 'DejaVu
246  // Sans Ultra-Light' force Pango to render a ligatured character even if
247  // the input consists of the separated characters. NOTE(ranjith): As per
248  // behdad@ this is not currently controllable at the level of the Pango
249  // API.
250  // The most frequent of all is a single character "word" made by the CJK
251  // segmenter.
252  // Safeguard against these cases here by just skipping the bigram.
253  if (IsWhitespaceBox(boxes[b+1])) {
254  continue;
255  }
256  int xgap = (boxes[b+1]->box()->x -
257  (boxes[b]->box()->x + boxes[b]->box()->w));
258  spacing_map_it0 = spacing_map.find(ch0);
259  int ok_count = 0;
260  if (spacing_map_it0 == spacing_map.end() &&
261  render->font().GetSpacingProperties(ch0, &x_bearing, &x_advance)) {
262  spacing_map[ch0] = SpacingProperties(
263  x_bearing, x_advance - x_bearing - boxes[b]->box()->w);
264  spacing_map_it0 = spacing_map.find(ch0);
265  ++ok_count;
266  }
267  const string &ch1 = boxes[b+1]->ch();
268  tlog(3, "%s%s\n", ch0.c_str(), ch1.c_str());
269  spacing_map_it1 = spacing_map.find(ch1);
270  if (spacing_map_it1 == spacing_map.end() &&
271  render->font().GetSpacingProperties(ch1, &x_bearing, &x_advance)) {
272  spacing_map[ch1] = SpacingProperties(
273  x_bearing, x_advance - x_bearing - boxes[b+1]->box()->w);
274  spacing_map_it1 = spacing_map.find(ch1);
275  ++ok_count;
276  }
277  if (ok_count == 2 && xgap != (spacing_map_it0->second.x_gap_after +
278  spacing_map_it1->second.x_gap_before)) {
279  spacing_map_it0->second.kerned_x_gaps[ch1] = xgap;
280  }
281  }
282  render->ClearBoxes();
283  }
284  string output_string;
285  const int kBufSize = 1024;
286  char buf[kBufSize];
287  snprintf(buf, kBufSize, "%d\n", static_cast<int>(spacing_map.size()));
288  output_string.append(buf);
289  std::map<string, SpacingProperties>::const_iterator spacing_map_it;
290  for (spacing_map_it = spacing_map.begin();
291  spacing_map_it != spacing_map.end(); ++spacing_map_it) {
292  snprintf(buf, kBufSize,
293  "%s %d %d %d", spacing_map_it->first.c_str(),
294  spacing_map_it->second.x_gap_before,
295  spacing_map_it->second.x_gap_after,
296  static_cast<int>(spacing_map_it->second.kerned_x_gaps.size()));
297  output_string.append(buf);
298  std::map<string, int>::const_iterator kern_it;
299  for (kern_it = spacing_map_it->second.kerned_x_gaps.begin();
300  kern_it != spacing_map_it->second.kerned_x_gaps.end(); ++kern_it) {
301  snprintf(buf, kBufSize,
302  " %s %d", kern_it->first.c_str(), kern_it->second);
303  output_string.append(buf);
304  }
305  output_string.append("\n");
306  }
307  File::WriteStringToFileOrDie(output_string, output_base + ".fontinfo");
308 }
bool GetSpacingProperties(const string &utf8_char, int *x_bearing, int *x_advance) const
#define tprintf(...)
Definition: tprintf.h:31
#define tlog(level,...)
Definition: tlog.h:33
const std::vector< BoxChar * > & GetBoxes() const
int RenderToImage(const char *text, int text_length, Pix **pix)
const PangoFontInfo & font() const

◆ FirstWordWouldHaveFit() [1/2]

bool tesseract::FirstWordWouldHaveFit ( const RowScratchRegisters before,
const RowScratchRegisters after,
tesseract::ParagraphJustification  justification 
)

Definition at line 1622 of file paragraphs.cpp.

1624  {
1625  if (before.ri_->num_words == 0 || after.ri_->num_words == 0)
1626  return true;
1627 
1628  if (justification == JUSTIFICATION_UNKNOWN) {
1629  tprintf("Don't call FirstWordWouldHaveFit(r, s, JUSTIFICATION_UNKNOWN).\n");
1630  }
1631  int available_space;
1632  if (justification == JUSTIFICATION_CENTER) {
1633  available_space = before.lindent_ + before.rindent_;
1634  } else {
1635  available_space = before.OffsideIndent(justification);
1636  }
1637  available_space -= before.ri_->average_interword_space;
1638 
1639  if (before.ri_->ltr)
1640  return after.ri_->lword_box.width() < available_space;
1641  return after.ri_->rword_box.width() < available_space;
1642 }
#define tprintf(...)
Definition: tprintf.h:31

◆ FirstWordWouldHaveFit() [2/2]

bool tesseract::FirstWordWouldHaveFit ( const RowScratchRegisters before,
const RowScratchRegisters after 
)

Definition at line 1647 of file paragraphs.cpp.

1648  {
1649  if (before.ri_->num_words == 0 || after.ri_->num_words == 0)
1650  return true;
1651 
1652  int available_space = before.lindent_;
1653  if (before.rindent_ > available_space)
1654  available_space = before.rindent_;
1655  available_space -= before.ri_->average_interword_space;
1656 
1657  if (before.ri_->ltr)
1658  return after.ri_->lword_box.width() < available_space;
1659  return after.ri_->rword_box.width() < available_space;
1660 }

◆ FontInfoDeleteCallback()

void tesseract::FontInfoDeleteCallback ( FontInfo  f)

Definition at line 139 of file fontinfo.cpp.

139  {
140  if (f.spacing_vec != NULL) {
141  f.spacing_vec->delete_data_pointers();
142  delete f.spacing_vec;
143  }
144  delete[] f.name;
145 }

◆ FontSetDeleteCallback()

void tesseract::FontSetDeleteCallback ( FontSet  fs)

Definition at line 146 of file fontinfo.cpp.

146  {
147  delete[] fs.configs;
148 }

◆ FullwidthToHalfwidth()

char32 tesseract::FullwidthToHalfwidth ( const char32  ch)

Definition at line 282 of file normstrngs.cpp.

282  {
283  // Return unchanged if not in the fullwidth-halfwidth Unicode block.
284  if (ch < 0xFF00 || ch > 0xFFEF || !IsValidCodepoint(ch)) {
285  if (ch != 0x3000) return ch;
286  }
287  // Special case for fullwidth left and right "white parentheses".
288  if (ch == 0xFF5F) return 0x2985;
289  if (ch == 0xFF60) return 0x2986;
290  // Construct a full-to-half width transliterator.
291  IcuErrorCode error_code;
292  icu::UnicodeString uch_str(static_cast<UChar32>(ch));
293  const icu::Transliterator* fulltohalf = icu::Transliterator::createInstance(
294  "Fullwidth-Halfwidth", UTRANS_FORWARD, error_code);
295  error_code.assertSuccess();
296  error_code.reset();
297 
298  fulltohalf->transliterate(uch_str);
299  delete fulltohalf;
300  ASSERT_HOST(uch_str.length() != 0);
301  return uch_str[0];
302 }
bool IsValidCodepoint(const char32 ch)
Definition: normstrngs.cpp:218
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ FuncInplace()

template<class Func >
void tesseract::FuncInplace ( int  n,
double *  inout 
)
inline

Definition at line 146 of file functions.h.

146  {
147  Func f;
148  for (int i = 0; i < n; ++i) {
149  inout[i] = f(inout[i]);
150  }
151 }

◆ FuncMultiply()

template<class Func >
void tesseract::FuncMultiply ( const double *  u,
const double *  v,
int  n,
double *  out 
)
inline

Definition at line 155 of file functions.h.

155  {
156  Func f;
157  for (int i = 0; i < n; ++i) {
158  out[i] = f(u[i]) * v[i];
159  }
160 }

◆ GeneratePerspectiveDistortion()

void tesseract::GeneratePerspectiveDistortion ( int  width,
int  height,
TRand randomizer,
Pix **  pix,
GenericVector< TBOX > *  boxes 
)

Definition at line 219 of file degradeimage.cpp.

220  {
221  if (pix != nullptr && *pix != nullptr) {
222  width = pixGetWidth(*pix);
223  height = pixGetHeight(*pix);
224  }
225  float* im_coeffs = nullptr;
226  float* box_coeffs = nullptr;
227  l_int32 incolor =
228  ProjectiveCoeffs(width, height, randomizer, &im_coeffs, &box_coeffs);
229  if (pix != nullptr && *pix != nullptr) {
230  // Transform the image.
231  Pix* transformed = pixProjective(*pix, im_coeffs, incolor);
232  if (transformed == nullptr) {
233  tprintf("Projective transformation failed!!\n");
234  return;
235  }
236  pixDestroy(pix);
237  *pix = transformed;
238  }
239  if (boxes != nullptr) {
240  // Transform the boxes.
241  for (int b = 0; b < boxes->size(); ++b) {
242  int x1, y1, x2, y2;
243  const TBOX& box = (*boxes)[b];
244  projectiveXformSampledPt(box_coeffs, box.left(), height - box.top(), &x1,
245  &y1);
246  projectiveXformSampledPt(box_coeffs, box.right(), height - box.bottom(),
247  &x2, &y2);
248  TBOX new_box1(x1, height - y2, x2, height - y1);
249  projectiveXformSampledPt(box_coeffs, box.left(), height - box.bottom(),
250  &x1, &y1);
251  projectiveXformSampledPt(box_coeffs, box.right(), height - box.top(), &x2,
252  &y2);
253  TBOX new_box2(x1, height - y1, x2, height - y2);
254  (*boxes)[b] = new_box1.bounding_union(new_box2);
255  }
256  }
257  free(im_coeffs);
258  free(box_coeffs);
259 }
int ProjectiveCoeffs(int width, int height, TRand *randomizer, float **im_coeffs, float **box_coeffs)
int size() const
Definition: genericvector.h:72
#define tprintf(...)
Definition: tprintf.h:31
inT16 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
inT16 left() const
Definition: rect.h:68
inT16 right() const
Definition: rect.h:75

◆ GeometricClassify()

void tesseract::GeometricClassify ( int  debug_level,
GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory theory 
)

Definition at line 1078 of file paragraphs.cpp.

1081  {
1082  if (!AcceptableRowArgs(debug_level, 4, __func__, rows, row_start, row_end))
1083  return;
1084  if (debug_level > 1) {
1085  tprintf("###############################################\n");
1086  tprintf("##### GeometricClassify( rows[%d:%d) ) ####\n",
1087  row_start, row_end);
1088  tprintf("###############################################\n");
1089  }
1090  RecomputeMarginsAndClearHypotheses(rows, row_start, row_end, 10);
1091 
1092  GeometricClassifierState s(debug_level, rows, row_start, row_end);
1093  if (s.left_tabs.size() > 2 && s.right_tabs.size() > 2) {
1094  s.Fail(2, "Too much variety for simple outline classification.");
1095  return;
1096  }
1097  if (s.left_tabs.size() <= 1 && s.right_tabs.size() <= 1) {
1098  s.Fail(1, "Not enough variety for simple outline classification.");
1099  return;
1100  }
1101  if (s.left_tabs.size() + s.right_tabs.size() == 3) {
1102  GeometricClassifyThreeTabStopTextBlock(debug_level, s, theory);
1103  return;
1104  }
1105 
1106  // At this point, we know that one side has at least two tab stops, and the
1107  // other side has one or two tab stops.
1108  // Left to determine:
1109  // (1) Which is the body indent and which is the first line indent?
1110  // (2) Is the text fully justified?
1111 
1112  // If one side happens to have three or more tab stops, assume that side
1113  // is opposite of the aligned side.
1114  if (s.right_tabs.size() > 2) {
1115  s.AssumeLeftJustification();
1116  } else if (s.left_tabs.size() > 2) {
1117  s.AssumeRightJustification();
1118  } else if (s.ltr) { // guess based on script direction
1119  s.AssumeLeftJustification();
1120  } else {
1121  s.AssumeRightJustification();
1122  }
1123 
1124  if (s.AlignTabs().size() == 2) {
1125  // For each tab stop on the aligned side, how many of them appear
1126  // to be paragraph start lines? [first lines]
1127  int firsts[2] = {0, 0};
1128  // Count the first line as a likely paragraph start line.
1129  firsts[s.AlignsideTabIndex(s.row_start)]++;
1130  // For each line, if the first word would have fit on the previous
1131  // line count it as a likely paragraph start line.
1132  bool jam_packed = true;
1133  for (int i = s.row_start + 1; i < s.row_end; i++) {
1134  if (s.FirstWordWouldHaveFit(i - 1, i)) {
1135  firsts[s.AlignsideTabIndex(i)]++;
1136  jam_packed = false;
1137  }
1138  }
1139  // Make an extra accounting for the last line of the paragraph just
1140  // in case it's the only short line in the block. That is, take its
1141  // first word as typical and see if this looks like the *last* line
1142  // of a paragraph. If so, mark the *other* indent as probably a first.
1143  if (jam_packed && s.FirstWordWouldHaveFit(s.row_end - 1, s.row_end - 1)) {
1144  firsts[1 - s.AlignsideTabIndex(s.row_end - 1)]++;
1145  }
1146 
1147  int percent0firsts, percent1firsts;
1148  percent0firsts = (100 * firsts[0]) / s.AlignTabs()[0].count;
1149  percent1firsts = (100 * firsts[1]) / s.AlignTabs()[1].count;
1150 
1151  // TODO(eger): Tune these constants if necessary.
1152  if ((percent0firsts < 20 && 30 < percent1firsts) ||
1153  percent0firsts + 30 < percent1firsts) {
1154  s.first_indent = s.AlignTabs()[1].center;
1155  s.body_indent = s.AlignTabs()[0].center;
1156  } else if ((percent1firsts < 20 && 30 < percent0firsts) ||
1157  percent1firsts + 30 < percent0firsts) {
1158  s.first_indent = s.AlignTabs()[0].center;
1159  s.body_indent = s.AlignTabs()[1].center;
1160  } else {
1161  // Ambiguous! Probably lineated (poetry)
1162  if (debug_level > 1) {
1163  tprintf("# Cannot determine %s indent likely to start paragraphs.\n",
1164  s.just == tesseract::JUSTIFICATION_LEFT ? "left" : "right");
1165  tprintf("# Indent of %d looks like a first line %d%% of the time.\n",
1166  s.AlignTabs()[0].center, percent0firsts);
1167  tprintf("# Indent of %d looks like a first line %d%% of the time.\n",
1168  s.AlignTabs()[1].center, percent1firsts);
1169  s.PrintRows();
1170  }
1171  return;
1172  }
1173  } else {
1174  // There's only one tab stop for the "aligned to" side.
1175  s.first_indent = s.body_indent = s.AlignTabs()[0].center;
1176  }
1177 
1178  // At this point, we have our model.
1179  const ParagraphModel *model = theory->AddModel(s.Model());
1180 
1181  // Now all we have to do is figure out if the text is fully justified or not.
1182  // eop_threshold: default to fully justified unless we see evidence below.
1183  // See description on MarkRowsWithModel()
1184  s.eop_threshold =
1185  (s.OffsideTabs()[0].center + s.OffsideTabs()[1].center) / 2;
1186  // If the text is not fully justified, re-set the eop_threshold to 0.
1187  if (s.AlignTabs().size() == 2) {
1188  // Paragraphs with a paragraph-start indent.
1189  for (int i = s.row_start; i < s.row_end - 1; i++) {
1190  if (ValidFirstLine(s.rows, i + 1, model) &&
1191  !NearlyEqual(s.OffsideTabs()[0].center,
1192  (*s.rows)[i].OffsideIndent(s.just), s.tolerance)) {
1193  // We found a non-end-of-paragraph short line: not fully justified.
1194  s.eop_threshold = 0;
1195  break;
1196  }
1197  }
1198  } else {
1199  // Paragraphs with no paragraph-start indent.
1200  for (int i = s.row_start; i < s.row_end - 1; i++) {
1201  if (!s.FirstWordWouldHaveFit(i, i + 1) &&
1202  !NearlyEqual(s.OffsideTabs()[0].center,
1203  (*s.rows)[i].OffsideIndent(s.just), s.tolerance)) {
1204  // We found a non-end-of-paragraph short line: not fully justified.
1205  s.eop_threshold = 0;
1206  break;
1207  }
1208  }
1209  }
1210  MarkRowsWithModel(rows, row_start, row_end, model, s.ltr, s.eop_threshold);
1211 }
void RecomputeMarginsAndClearHypotheses(GenericVector< RowScratchRegisters > *rows, int start, int end, int percentile)
#define tprintf(...)
Definition: tprintf.h:31
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
void GeometricClassifyThreeTabStopTextBlock(int debug_level, GeometricClassifierState &s, ParagraphTheory *theory)
Definition: paragraphs.cpp:986
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87
void MarkRowsWithModel(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, const ParagraphModel *model, bool ltr, int eop_threshold)
Definition: paragraphs.cpp:808

◆ GeometricClassifyThreeTabStopTextBlock()

void tesseract::GeometricClassifyThreeTabStopTextBlock ( int  debug_level,
GeometricClassifierState s,
ParagraphTheory theory 
)

Definition at line 986 of file paragraphs.cpp.

989  {
990  int num_rows = s.row_end - s.row_start;
991  int num_full_rows = 0;
992  int last_row_full = 0;
993  for (int i = s.row_start; i < s.row_end; i++) {
994  if (s.IsFullRow(i)) {
995  num_full_rows++;
996  if (i == s.row_end - 1) last_row_full++;
997  }
998  }
999 
1000  if (num_full_rows < 0.7 * num_rows) {
1001  s.Fail(1, "Not enough full lines to know which lines start paras.");
1002  return;
1003  }
1004 
1005  // eop_threshold gets set if we're fully justified; see MarkRowsWithModel()
1006  s.eop_threshold = 0;
1007 
1008  if (s.ltr) {
1009  s.AssumeLeftJustification();
1010  } else {
1011  s.AssumeRightJustification();
1012  }
1013 
1014  if (debug_level > 0) {
1015  tprintf("# Not enough variety for clear outline classification. "
1016  "Guessing these are %s aligned based on script.\n",
1017  s.ltr ? "left" : "right");
1018  s.PrintRows();
1019  }
1020 
1021  if (s.AlignTabs().size() == 2) { // case A1 or A2
1022  s.first_indent = s.AlignTabs()[1].center;
1023  s.body_indent = s.AlignTabs()[0].center;
1024  } else { // case B1 or B2
1025  if (num_rows - 1 == num_full_rows - last_row_full) {
1026  // case B2
1027  const ParagraphModel *model = s.ltr ? kCrownLeft : kCrownRight;
1028  (*s.rows)[s.row_start].AddStartLine(model);
1029  for (int i = s.row_start + 1; i < s.row_end; i++) {
1030  (*s.rows)[i].AddBodyLine(model);
1031  }
1032  return;
1033  } else {
1034  // case B1
1035  s.first_indent = s.body_indent = s.AlignTabs()[0].center;
1036  s.eop_threshold = (s.OffsideTabs()[0].center +
1037  s.OffsideTabs()[1].center) / 2;
1038  }
1039  }
1040  const ParagraphModel *model = theory->AddModel(s.Model());
1041  MarkRowsWithModel(s.rows, s.row_start, s.row_end, model,
1042  s.ltr, s.eop_threshold);
1043  return;
1044 }
int first_indent() const
Definition: ocrpara.h:168
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:46
#define tprintf(...)
Definition: tprintf.h:31
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:48
void MarkRowsWithModel(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, const ParagraphModel *model, bool ltr, int eop_threshold)
Definition: paragraphs.cpp:808

◆ GetWordBaseline()

void tesseract::GetWordBaseline ( int  writing_direction,
int  ppi,
int  height,
int  word_x1,
int  word_y1,
int  word_x2,
int  word_y2,
int  line_x1,
int  line_y1,
int  line_x2,
int  line_y2,
double *  x0,
double *  y0,
double *  length 
)

Definition at line 225 of file pdfrenderer.cpp.

228  {
229  if (writing_direction == WRITING_DIRECTION_RIGHT_TO_LEFT) {
230  Swap(&word_x1, &word_x2);
231  Swap(&word_y1, &word_y2);
232  }
233  double word_length;
234  double x, y;
235  {
236  int px = word_x1;
237  int py = word_y1;
238  double l2 = dist2(line_x1, line_y1, line_x2, line_y2);
239  if (l2 == 0) {
240  x = line_x1;
241  y = line_y1;
242  } else {
243  double t = ((px - line_x2) * (line_x2 - line_x1) +
244  (py - line_y2) * (line_y2 - line_y1)) / l2;
245  x = line_x2 + t * (line_x2 - line_x1);
246  y = line_y2 + t * (line_y2 - line_y1);
247  }
248  word_length = sqrt(static_cast<double>(dist2(word_x1, word_y1,
249  word_x2, word_y2)));
250  word_length = word_length * 72.0 / ppi;
251  x = x * 72 / ppi;
252  y = height - (y * 72.0 / ppi);
253  }
254  *x0 = x;
255  *y0 = y;
256  *length = word_length;
257 }
long dist2(int x1, int y1, int x2, int y2)
void Swap(T *p1, T *p2)
Definition: helpers.h:97

◆ GetXheightString()

string tesseract::GetXheightString ( const string &  script_dir,
const UNICHARSET unicharset 
)

Definition at line 164 of file unicharset_training_utils.cpp.

165  {
166  string xheights_str;
167  for (int s = 0; s < unicharset.get_script_table_size(); ++s) {
168  // Load the xheights for the script if available.
169  string filename = script_dir + "/" +
170  unicharset.get_script_from_script_id(s) + ".xheights";
171  string script_heights;
172  if (File::ReadFileToString(filename, &script_heights))
173  xheights_str += script_heights;
174  }
175  return xheights_str;
176 }
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:853
int get_script_table_size() const
Definition: unicharset.h:848

◆ GridReducedPix()

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 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61
inT16 left() const
Definition: rect.h:68
inT16 y() const
access_function
Definition: points.h:56
inT16 right() const
Definition: rect.h:75

◆ HistogramRect()

void tesseract::HistogramRect ( Pix *  src_pix,
int  channel,
int  left,
int  top,
int  width,
int  height,
int *  histogram 
)

Definition at line 151 of file otsuthr.cpp.

153  {
154  PERF_COUNT_START("HistogramRect")
155  int num_channels = pixGetDepth(src_pix) / 8;
156  channel = ClipToRange(channel, 0, num_channels - 1);
157  int bottom = top + height;
158  memset(histogram, 0, sizeof(*histogram) * kHistogramSize);
159  int src_wpl = pixGetWpl(src_pix);
160  l_uint32* srcdata = pixGetData(src_pix);
161  for (int y = top; y < bottom; ++y) {
162  const l_uint32* linedata = srcdata + y * src_wpl;
163  for (int x = 0; x < width; ++x) {
164  int pixel = GET_DATA_BYTE(linedata, (x + left) * num_channels + channel);
165  ++histogram[pixel];
166  }
167  }
169 }
#define PERF_COUNT_END
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122
const int kHistogramSize
Definition: otsuthr.h:27
#define PERF_COUNT_START(FUNCT_NAME)

◆ HOcrEscape()

STRING tesseract::HOcrEscape ( const char *  text)

Escape a char string - remove <>&"' with HTML codes.

Escape a char string - remove &<>"' with HTML codes.

Definition at line 2837 of file baseapi.cpp.

2837  {
2838  STRING ret;
2839  const char *ptr;
2840  for (ptr = text; *ptr; ptr++) {
2841  switch (*ptr) {
2842  case '<': ret += "&lt;"; break;
2843  case '>': ret += "&gt;"; break;
2844  case '&': ret += "&amp;"; break;
2845  case '"': ret += "&quot;"; break;
2846  case '\'': ret += "&#39;"; break;
2847  default: ret += *ptr;
2848  }
2849  }
2850  return ret;
2851 }
Definition: strngs.h:45

◆ InitializeRowInfo()

void tesseract::InitializeRowInfo ( bool  after_recognition,
const MutableIterator it,
RowInfo info 
)

Definition at line 2413 of file paragraphs.cpp.

2415  {
2416  if (it.PageResIt()->row() != NULL) {
2417  ROW *row = it.PageResIt()->row()->row;
2418  info->pix_ldistance = row->lmargin();
2419  info->pix_rdistance = row->rmargin();
2420  info->average_interword_space =
2421  row->space() > 0 ? row->space() : MAX(row->x_height(), 1);
2422  info->pix_xheight = row->x_height();
2423  info->has_leaders = false;
2424  info->has_drop_cap = row->has_drop_cap();
2425  info->ltr = true; // set below depending on word scripts
2426  } else {
2427  info->pix_ldistance = info->pix_rdistance = 0;
2428  info->average_interword_space = 1;
2429  info->pix_xheight = 1.0;
2430  info->has_leaders = false;
2431  info->has_drop_cap = false;
2432  info->ltr = true;
2433  }
2434 
2435  info->num_words = 0;
2436  info->lword_indicates_list_item = false;
2437  info->lword_likely_starts_idea = false;
2438  info->lword_likely_ends_idea = false;
2439  info->rword_indicates_list_item = false;
2440  info->rword_likely_starts_idea = false;
2441  info->rword_likely_ends_idea = false;
2442  info->has_leaders = false;
2443  info->ltr = 1;
2444 
2445  if (!after_recognition) {
2447  return;
2448  }
2449  info->text = "";
2450  const std::unique_ptr<const char[]> text(it.GetUTF8Text(RIL_TEXTLINE));
2451  int trailing_ws_idx = strlen(text.get()); // strip trailing space
2452  while (trailing_ws_idx > 0 &&
2453  // isspace() only takes ASCII
2454  ((text[trailing_ws_idx - 1] & 0x80) == 0) &&
2455  isspace(text[trailing_ws_idx - 1]))
2456  trailing_ws_idx--;
2457  if (trailing_ws_idx > 0) {
2458  int lspaces = info->pix_ldistance / info->average_interword_space;
2459  for (int i = 0; i < lspaces; i++)
2460  info->text += ' ';
2461  for (int i = 0; i < trailing_ws_idx; i++)
2462  info->text += text[i];
2463  }
2464 
2465  if (info->text.size() == 0) {
2466  return;
2467  }
2468 
2469  PAGE_RES_IT page_res_it = *it.PageResIt();
2471  WERD_RES *word_res = page_res_it.restart_row();
2472  ROW_RES *this_row = page_res_it.row();
2473  int num_leaders = 0;
2474  int ltr = 0;
2475  int rtl = 0;
2476  do {
2477  if (word_res && word_res->best_choice->unichar_string().length() > 0) {
2478  werds.push_back(word_res);
2479  ltr += word_res->AnyLtrCharsInWord() ? 1 : 0;
2480  rtl += word_res->AnyRtlCharsInWord() ? 1 : 0;
2481  if (word_res->word->flag(W_REP_CHAR)) num_leaders++;
2482  }
2483  word_res = page_res_it.forward();
2484  } while (page_res_it.row() == this_row);
2485  info->ltr = ltr >= rtl;
2486  info->has_leaders = num_leaders > 3;
2487  info->num_words = werds.size();
2488  if (!werds.empty()) {
2489  WERD_RES *lword = werds[0], *rword = werds[werds.size() - 1];
2490  info->lword_text = lword->best_choice->unichar_string().string();
2491  info->rword_text = rword->best_choice->unichar_string().string();
2492  info->lword_box = lword->word->bounding_box();
2493  info->rword_box = rword->word->bounding_box();
2494  LeftWordAttributes(lword->uch_set, lword->best_choice,
2495  info->lword_text,
2496  &info->lword_indicates_list_item,
2497  &info->lword_likely_starts_idea,
2498  &info->lword_likely_ends_idea);
2499  RightWordAttributes(rword->uch_set, rword->best_choice,
2500  info->rword_text,
2501  &info->rword_indicates_list_item,
2502  &info->rword_likely_starts_idea,
2503  &info->rword_likely_ends_idea);
2504  }
2505 }
float x_height() const
Definition: ocrrow.h:61
bool empty() const
Definition: genericvector.h:91
ROW_RES * row() const
Definition: pageres.h:739
inT16 lmargin() const
Definition: ocrrow.h:98
WERD_RES * restart_row()
Definition: pageres.cpp:1638
#define MAX(x, y)
Definition: ndminx.h:24
const UNICHARSET * uch_set
Definition: pageres.h:192
Definition: ocrrow.h:32
int size() const
Definition: genericvector.h:72
bool has_drop_cap() const
Definition: ocrrow.h:108
WERD_CHOICE * best_choice
Definition: pageres.h:219
inT32 space() const
Definition: ocrrow.h:76
WERD * word
Definition: pageres.h:175
const char * string() const
Definition: strngs.cpp:198
int push_back(T object)
inT16 rmargin() const
Definition: ocrrow.h:101
void InitializeTextAndBoxesPreRecognition(const MutableIterator &it, RowInfo *info)
WERD_RES * forward()
Definition: pageres.h:716
void LeftWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd, const STRING &utf8, bool *is_list, bool *starts_idea, bool *ends_idea)
Definition: paragraphs.cpp:395
void RightWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd, const STRING &utf8, bool *is_list, bool *starts_idea, bool *ends_idea)
Definition: paragraphs.cpp:442
BOOL8 flag(WERD_FLAGS mask) const
Definition: werd.h:128
TBOX bounding_box() const
Definition: werd.cpp:160
bool AnyLtrCharsInWord() const
Definition: pageres.h:392
inT32 length() const
Definition: strngs.cpp:193
bool AnyRtlCharsInWord() const
Definition: pageres.h:375
const STRING & unichar_string() const
Definition: ratngs.h:537

◆ InitializeTextAndBoxesPreRecognition()

void tesseract::InitializeTextAndBoxesPreRecognition ( const MutableIterator it,
RowInfo info 
)

Definition at line 2361 of file paragraphs.cpp.

2362  {
2363  // Set up text, lword_text, and rword_text (mostly for debug printing).
2364  STRING fake_text;
2365  PageIterator pit(static_cast<const PageIterator&>(it));
2366  bool first_word = true;
2367  if (!pit.Empty(RIL_WORD)) {
2368  do {
2369  fake_text += "x";
2370  if (first_word) info->lword_text += "x";
2371  info->rword_text += "x";
2372  if (pit.IsAtFinalElement(RIL_WORD, RIL_SYMBOL) &&
2373  !pit.IsAtFinalElement(RIL_TEXTLINE, RIL_SYMBOL)) {
2374  fake_text += " ";
2375  info->rword_text = "";
2376  first_word = false;
2377  }
2378  } while (!pit.IsAtFinalElement(RIL_TEXTLINE, RIL_SYMBOL) &&
2379  pit.Next(RIL_SYMBOL));
2380  }
2381  if (fake_text.size() == 0) return;
2382 
2383  int lspaces = info->pix_ldistance / info->average_interword_space;
2384  for (int i = 0; i < lspaces; i++) {
2385  info->text += ' ';
2386  }
2387  info->text += fake_text;
2388 
2389  // Set up lword_box, rword_box, and num_words.
2390  PAGE_RES_IT page_res_it = *it.PageResIt();
2391  WERD_RES *word_res = page_res_it.restart_row();
2392  ROW_RES *this_row = page_res_it.row();
2393 
2394  WERD_RES *lword = NULL;
2395  WERD_RES *rword = NULL;
2396  info->num_words = 0;
2397  do {
2398  if (word_res) {
2399  if (!lword) lword = word_res;
2400  if (rword != word_res) info->num_words++;
2401  rword = word_res;
2402  }
2403  word_res = page_res_it.forward();
2404  } while (page_res_it.row() == this_row);
2405 
2406  if (lword) info->lword_box = lword->word->bounding_box();
2407  if (rword) info->rword_box = rword->word->bounding_box();
2408 }
inT32 size() const
Definition: strngs.h:69
ROW_RES * row() const
Definition: pageres.h:739
WERD_RES * restart_row()
Definition: pageres.cpp:1638
WERD * word
Definition: pageres.h:175
Definition: strngs.h:45
WERD_RES * forward()
Definition: pageres.h:716
TBOX bounding_box() const
Definition: werd.cpp:160
Definition: capi.h:92

◆ IntDotProductSSE()

int32_t tesseract::IntDotProductSSE ( const int8_t *  u,
const int8_t *  v,
int  n 
)

Definition at line 31 of file dotproductsse.cpp.

31  {
32  fprintf(stderr, "IntDotProductSSE can't be used on Android\n");
33  abort();
34 }

◆ InternalParagraphModelByOutline()

ParagraphModel tesseract::InternalParagraphModelByOutline ( const GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
int  tolerance,
bool *  consistent 
)

Definition at line 1693 of file paragraphs.cpp.

1695  {
1696  int ltr_line_count = 0;
1697  for (int i = start; i < end; i++) {
1698  ltr_line_count += static_cast<int>((*rows)[i].ri_->ltr);
1699  }
1700  bool ltr = (ltr_line_count >= (end - start) / 2);
1701 
1702  *consistent = true;
1703  if (!AcceptableRowArgs(0, 2, __func__, rows, start, end))
1704  return ParagraphModel();
1705 
1706  // Ensure the caller only passed us a region with a common rmargin and
1707  // lmargin.
1708  int lmargin = (*rows)[start].lmargin_;
1709  int rmargin = (*rows)[start].rmargin_;
1710  int lmin, lmax, rmin, rmax, cmin, cmax;
1711  lmin = lmax = (*rows)[start + 1].lindent_;
1712  rmin = rmax = (*rows)[start + 1].rindent_;
1713  cmin = cmax = 0;
1714  for (int i = start + 1; i < end; i++) {
1715  if ((*rows)[i].lmargin_ != lmargin || (*rows)[i].rmargin_ != rmargin) {
1716  tprintf("Margins don't match! Software error.\n");
1717  *consistent = false;
1718  return ParagraphModel();
1719  }
1720  UpdateRange((*rows)[i].lindent_, &lmin, &lmax);
1721  UpdateRange((*rows)[i].rindent_, &rmin, &rmax);
1722  UpdateRange((*rows)[i].rindent_ - (*rows)[i].lindent_, &cmin, &cmax);
1723  }
1724  int ldiff = lmax - lmin;
1725  int rdiff = rmax - rmin;
1726  int cdiff = cmax - cmin;
1727  if (rdiff > tolerance && ldiff > tolerance) {
1728  if (cdiff < tolerance * 2) {
1729  if (end - start < 3)
1730  return ParagraphModel();
1731  return ParagraphModel(JUSTIFICATION_CENTER, 0, 0, 0, tolerance);
1732  }
1733  *consistent = false;
1734  return ParagraphModel();
1735  }
1736  if (end - start < 3) // Don't return a model for two line paras.
1737  return ParagraphModel();
1738 
1739  // These booleans keep us from saying something is aligned left when the body
1740  // left variance is too large.
1741  bool body_admits_left_alignment = ldiff < tolerance;
1742  bool body_admits_right_alignment = rdiff < tolerance;
1743 
1744  ParagraphModel left_model =
1745  ParagraphModel(JUSTIFICATION_LEFT, lmargin, (*rows)[start].lindent_,
1746  (lmin + lmax) / 2, tolerance);
1747  ParagraphModel right_model =
1748  ParagraphModel(JUSTIFICATION_RIGHT, rmargin, (*rows)[start].rindent_,
1749  (rmin + rmax) / 2, tolerance);
1750 
1751  // These booleans keep us from having an indent on the "wrong side" for the
1752  // first line.
1753  bool text_admits_left_alignment = ltr || left_model.is_flush();
1754  bool text_admits_right_alignment = !ltr || right_model.is_flush();
1755 
1756  // At least one of the edges is less than tolerance in variance.
1757  // If the other is obviously ragged, it can't be the one aligned to.
1758  // [Note the last line is included in this raggedness.]
1759  if (tolerance < rdiff) {
1760  if (body_admits_left_alignment && text_admits_left_alignment)
1761  return left_model;
1762  *consistent = false;
1763  return ParagraphModel();
1764  }
1765  if (tolerance < ldiff) {
1766  if (body_admits_right_alignment && text_admits_right_alignment)
1767  return right_model;
1768  *consistent = false;
1769  return ParagraphModel();
1770  }
1771 
1772  // At this point, we know the body text doesn't vary much on either side.
1773 
1774  // If the first line juts out oddly in one direction or the other,
1775  // that likely indicates the side aligned to.
1776  int first_left = (*rows)[start].lindent_;
1777  int first_right = (*rows)[start].rindent_;
1778 
1779  if (ltr && body_admits_left_alignment &&
1780  (first_left < lmin || first_left > lmax))
1781  return left_model;
1782  if (!ltr && body_admits_right_alignment &&
1783  (first_right < rmin || first_right > rmax))
1784  return right_model;
1785 
1786  *consistent = false;
1787  return ParagraphModel();
1788 }
bool is_flush() const
Definition: ocrpara.h:171
#define tprintf(...)
Definition: tprintf.h:31
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:132

◆ InterwordSpace()

int tesseract::InterwordSpace ( const GenericVector< RowScratchRegisters > &  rows,
int  row_start,
int  row_end 
)

Definition at line 1599 of file paragraphs.cpp.

1600  {
1601  if (row_end < row_start + 1) return 1;
1602  int word_height = (rows[row_start].ri_->lword_box.height() +
1603  rows[row_end - 1].ri_->lword_box.height()) / 2;
1604  int word_width = (rows[row_start].ri_->lword_box.width() +
1605  rows[row_end - 1].ri_->lword_box.width()) / 2;
1606  STATS spacing_widths(0, 5 + word_width);
1607  for (int i = row_start; i < row_end; i++) {
1608  if (rows[i].ri_->num_words > 1) {
1609  spacing_widths.add(rows[i].ri_->average_interword_space, 1);
1610  }
1611  }
1612  int minimum_reasonable_space = word_height / 3;
1613  if (minimum_reasonable_space < 2)
1614  minimum_reasonable_space = 2;
1615  int median = spacing_widths.median();
1616  return (median > minimum_reasonable_space)
1617  ? median : minimum_reasonable_space;
1618 }
Definition: statistc.h:33

◆ IntFlagExists()

bool tesseract::IntFlagExists ( const char *  flag_name,
inT32 value 
)

Definition at line 15 of file commandlineflags.cpp.

15  {
16  STRING full_flag_name("FLAGS_");
17  full_flag_name += flag_name;
19  IntParam *p = ParamUtils::FindParam<IntParam>(
20  full_flag_name.string(), GlobalParams()->int_params, empty);
21  if (p == nullptr) return false;
22  *value = (inT32)(*p);
23  return true;
24 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< IntParam * > int_params
Definition: params.h:44
Definition: strngs.h:45
int32_t inT32
Definition: host.h:38

◆ is_double_quote()

bool tesseract::is_double_quote ( const char32  ch)

Definition at line 74 of file normstrngs.cpp.

74  {
75  static const int kNumDoubleQuoteUnicodes = 8;
76  static const char32 kDoubleQuoteUnicodes[kNumDoubleQuoteUnicodes] = {
77  '"',
78  0x201C, // left double quotation mark (English, others)
79  0x201D, // right double quotation mark (Danish, Finnish, Swedish, Norw.)
80  0x201F, // double high-reversed-9 quotation mark (PropList.txt)
81  0x2033, // double prime
82  0x301D, // reversed double prime quotation mark (East Asian langs,
83  // horiz.)
84  0x301E, // close double prime (East Asian languages written horizontally)
85  0xFF02, // fullwidth quotation mark
86  };
87  for (int i = 0; i < kNumDoubleQuoteUnicodes; ++i) {
88  if (kDoubleQuoteUnicodes[i] == ch) return true;
89  }
90  return false;
91 }
signed int char32

◆ is_hyphen_punc()

bool tesseract::is_hyphen_punc ( const char32  ch)

Definition at line 38 of file normstrngs.cpp.

38  {
39  static const int kNumHyphenPuncUnicodes = 13;
40  static const char32 kHyphenPuncUnicodes[kNumHyphenPuncUnicodes] = {
41  '-', 0x2010, 0x2011, 0x2012,
42  0x2013, 0x2014, 0x2015, // hyphen..horizontal bar
43  0x207b, // superscript minus
44  0x208b, // subscript minus
45  0x2212, // minus sign
46  0xfe58, // small em dash
47  0xfe63, // small hyphen-minus
48  0xff0d, // fullwidth hyphen-minus
49  };
50  for (int i = 0; i < kNumHyphenPuncUnicodes; ++i) {
51  if (kHyphenPuncUnicodes[i] == ch) return true;
52  }
53  return false;
54 }
signed int char32

◆ is_single_quote()

bool tesseract::is_single_quote ( const char32  ch)

Definition at line 56 of file normstrngs.cpp.

56  {
57  static const int kNumSingleQuoteUnicodes = 8;
58  static const char32 kSingleQuoteUnicodes[kNumSingleQuoteUnicodes] = {
59  '\'', '`',
60  0x2018, // left single quotation mark (English, others)
61  0x2019, // right single quotation mark (Danish, Finnish, Swedish, Norw.)
62  // We may have to introduce a comma set with 0x201a
63  0x201B, // single high-reveresed-9 quotation mark (PropList.txt)
64  0x2032, // prime
65  0x300C, // left corner bracket (East Asian languages)
66  0xFF07, // fullwidth apostrophe
67  };
68  for (int i = 0; i < kNumSingleQuoteUnicodes; ++i) {
69  if (kSingleQuoteUnicodes[i] == ch) return true;
70  }
71  return false;
72 }
signed int char32

◆ IsDigitLike()

bool tesseract::IsDigitLike ( int  ch)

Definition at line 198 of file paragraphs.cpp.

198  {
199  return ch == 'o' || ch == 'O' || ch == 'l' || ch == 'I';
200 }

◆ IsInterchangeValid()

bool tesseract::IsInterchangeValid ( const char32  ch)

Definition at line 253 of file normstrngs.cpp.

253  {
254  return IsValidCodepoint(ch) &&
255  !(ch >= 0xFDD0 && ch <= 0xFDEF) && // Noncharacters.
256  !(ch >= 0xFFFE && ch <= 0xFFFF) && !(ch >= 0x1FFFE && ch <= 0x1FFFF) &&
257  !(ch >= 0x2FFFE && ch <= 0x2FFFF) &&
258  !(ch >= 0x3FFFE && ch <= 0x3FFFF) &&
259  !(ch >= 0x4FFFE && ch <= 0x4FFFF) &&
260  !(ch >= 0x5FFFE && ch <= 0x5FFFF) &&
261  !(ch >= 0x6FFFE && ch <= 0x6FFFF) &&
262  !(ch >= 0x7FFFE && ch <= 0x7FFFF) &&
263  !(ch >= 0x8FFFE && ch <= 0x8FFFF) &&
264  !(ch >= 0x9FFFE && ch <= 0x9FFFF) &&
265  !(ch >= 0xAFFFE && ch <= 0xAFFFF) &&
266  !(ch >= 0xBFFFE && ch <= 0xBFFFF) &&
267  !(ch >= 0xCFFFE && ch <= 0xCFFFF) &&
268  !(ch >= 0xDFFFE && ch <= 0xDFFFF) &&
269  !(ch >= 0xEFFFE && ch <= 0xEFFFF) &&
270  !(ch >= 0xFFFFE && ch <= 0xFFFFF) &&
271  !(ch >= 0x10FFFE && ch <= 0x10FFFF) &&
272  (!u_isISOControl(static_cast<UChar32>(ch)) || ch == '\n' ||
273  ch == '\f' || ch == '\t' || ch == '\r');
274 }
bool IsValidCodepoint(const char32 ch)
Definition: normstrngs.cpp:218

◆ IsInterchangeValid7BitAscii()

bool tesseract::IsInterchangeValid7BitAscii ( const char32  ch)

Definition at line 276 of file normstrngs.cpp.

276  {
277  return IsValidCodepoint(ch) && ch <= 128 &&
278  (!u_isISOControl(static_cast<UChar32>(ch)) || ch == '\n' ||
279  ch == '\f' || ch == '\t' || ch == '\r');
280 }
bool IsValidCodepoint(const char32 ch)
Definition: normstrngs.cpp:218

◆ IsLatinLetter()

bool tesseract::IsLatinLetter ( int  ch)

Definition at line 194 of file paragraphs.cpp.

194  {
195  return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
196 }

◆ IsLeftIndented()

bool tesseract::IsLeftIndented ( const EquationDetect::IndentType  type)
inline

Definition at line 90 of file equationdetect.cpp.

90  {
91  return type == EquationDetect::LEFT_INDENT ||
92  type == EquationDetect::BOTH_INDENT;
93 }

◆ IsOCREquivalent()

bool tesseract::IsOCREquivalent ( char32  ch1,
char32  ch2 
)

Definition at line 214 of file normstrngs.cpp.

214  {
215  return OCRNormalize(ch1) == OCRNormalize(ch2);
216 }
char32 OCRNormalize(char32 ch)
Definition: normstrngs.cpp:204

◆ IsOpeningPunct()

bool tesseract::IsOpeningPunct ( int  ch)

Definition at line 202 of file paragraphs.cpp.

202  {
203  return strchr("'\"({[", ch) != NULL;
204 }

◆ IsRightIndented()

bool tesseract::IsRightIndented ( const EquationDetect::IndentType  type)
inline

Definition at line 95 of file equationdetect.cpp.

95  {
96  return type == EquationDetect::RIGHT_INDENT ||
97  type == EquationDetect::BOTH_INDENT;
98 }

◆ IsTerminalPunct()

bool tesseract::IsTerminalPunct ( int  ch)

Definition at line 206 of file paragraphs.cpp.

206  {
207  return strchr(":'\".?!]})", ch) != NULL;
208 }

◆ IsTextOrEquationType()

bool tesseract::IsTextOrEquationType ( PolyBlockType  type)
inline

Definition at line 86 of file equationdetect.cpp.

86  {
87  return PTIsTextType(type) || type == PT_EQUATION;
88 }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:82

◆ IsUTF8Whitespace()

bool tesseract::IsUTF8Whitespace ( const char *  text)

Definition at line 229 of file normstrngs.cpp.

229  {
230  return SpanUTF8Whitespace(text) == strlen(text);
231 }
unsigned int SpanUTF8Whitespace(const char *text)
Definition: normstrngs.cpp:233

◆ IsValidCodepoint()

bool tesseract::IsValidCodepoint ( const char32  ch)

Definition at line 218 of file normstrngs.cpp.

218  {
219  // In the range [0, 0xD800) or [0xE000, 0x10FFFF]
220  return (static_cast<uint32_t>(ch) < 0xD800) || (ch >= 0xE000 && ch <= 0x10FFFF);
221 }

◆ IsWhitespace()

bool tesseract::IsWhitespace ( const char32  ch)

Definition at line 223 of file normstrngs.cpp.

223  {
224  ASSERT_HOST_MSG(IsValidCodepoint(ch), "Invalid Unicode codepoint: 0x%x\n",
225  ch);
226  return u_isUWhiteSpace(static_cast<UChar32>(ch));
227 }
#define ASSERT_HOST_MSG(x,...)
Definition: errcode.h:90
bool IsValidCodepoint(const char32 ch)
Definition: normstrngs.cpp:218

◆ LeftoverSegments()

void tesseract::LeftoverSegments ( const GenericVector< RowScratchRegisters > &  rows,
GenericVector< Interval > *  to_fix,
int  row_start,
int  row_end 
)

Definition at line 2183 of file paragraphs.cpp.

2185  {
2186  to_fix->clear();
2187  for (int i = row_start; i < row_end; i++) {
2188  bool needs_fixing = false;
2189 
2190  SetOfModels models;
2191  SetOfModels models_w_crowns;
2192  rows[i].StrongHypotheses(&models);
2193  rows[i].NonNullHypotheses(&models_w_crowns);
2194  if (models.empty() && !models_w_crowns.empty()) {
2195  // Crown paragraph. Is it followed by a modeled line?
2196  for (int end = i + 1; end < rows.size(); end++) {
2197  SetOfModels end_models;
2198  SetOfModels strong_end_models;
2199  rows[end].NonNullHypotheses(&end_models);
2200  rows[end].StrongHypotheses(&strong_end_models);
2201  if (end_models.empty()) {
2202  needs_fixing = true;
2203  break;
2204  } else if (!strong_end_models.empty()) {
2205  needs_fixing = false;
2206  break;
2207  }
2208  }
2209  } else if (models.empty() && rows[i].ri_->num_words > 0) {
2210  // No models at all.
2211  needs_fixing = true;
2212  }
2213 
2214  if (!needs_fixing && !models.empty()) {
2215  needs_fixing = RowIsStranded(rows, i);
2216  }
2217 
2218  if (needs_fixing) {
2219  if (!to_fix->empty() && to_fix->back().end == i - 1)
2220  to_fix->back().end = i;
2221  else
2222  to_fix->push_back(Interval(i, i));
2223  }
2224  }
2225  // Convert inclusive intervals to half-open intervals.
2226  for (int i = 0; i < to_fix->size(); i++) {
2227  (*to_fix)[i].end = (*to_fix)[i].end + 1;
2228  }
2229 }
bool empty() const
Definition: genericvector.h:91
T & back() const
int size() const
Definition: genericvector.h:72
int push_back(T object)
bool RowIsStranded(const GenericVector< RowScratchRegisters > &rows, int row)
GenericVectorEqEq< const ParagraphModel * > SetOfModels

◆ LeftWordAttributes()

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 395 of file paragraphs.cpp.

397  {
398  *is_list = false;
399  *starts_idea = false;
400  *ends_idea = false;
401  if (utf8.size() == 0 || (werd != NULL && werd->length() == 0)) { // Empty
402  *ends_idea = true;
403  return;
404  }
405 
406  if (unicharset && werd) { // We have a proper werd and unicharset so use it.
407  if (UniLikelyListItem(unicharset, werd)) {
408  *is_list = true;
409  *starts_idea = true;
410  *ends_idea = true;
411  }
412  if (unicharset->get_isupper(werd->unichar_id(0))) {
413  *starts_idea = true;
414  }
415  if (unicharset->get_ispunctuation(werd->unichar_id(0))) {
416  *starts_idea = true;
417  *ends_idea = true;
418  }
419  } else { // Assume utf8 is mostly ASCII
420  if (AsciiLikelyListItem(utf8)) {
421  *is_list = true;
422  *starts_idea = true;
423  }
424  int start_letter = utf8[0];
425  if (IsOpeningPunct(start_letter)) {
426  *starts_idea = true;
427  }
428  if (IsTerminalPunct(start_letter)) {
429  *ends_idea = true;
430  }
431  if (start_letter >= 'A' && start_letter <= 'Z') {
432  *starts_idea = true;
433  }
434  }
435 }
inT32 size() const
Definition: strngs.h:69
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:518
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:311
bool AsciiLikelyListItem(const STRING &word)
Definition: paragraphs.cpp:268
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:504
bool IsTerminalPunct(int ch)
Definition: paragraphs.cpp:206
int length() const
Definition: ratngs.h:299
bool UniLikelyListItem(const UNICHARSET *u, const WERD_CHOICE *werd)
Definition: paragraphs.cpp:358
bool IsOpeningPunct(int ch)
Definition: paragraphs.cpp:202

◆ LikelyListMark()

bool tesseract::LikelyListMark ( const STRING word)

Definition at line 263 of file paragraphs.cpp.

263  {
264  const char *kListMarks = "0Oo*.,+.";
265  return word.size() == 1 && strchr(kListMarks, word[0]) != NULL;
266 }
inT32 size() const
Definition: strngs.h:69

◆ LikelyListMarkUnicode()

bool tesseract::LikelyListMarkUnicode ( int  ch)

Definition at line 329 of file paragraphs.cpp.

329  {
330  if (ch < 0x80) {
331  STRING single_ch;
332  single_ch += ch;
333  return LikelyListMark(single_ch);
334  }
335  switch (ch) {
336  // TODO(eger) expand this list of unicodes as needed.
337  case 0x00B0: // degree sign
338  case 0x2022: // bullet
339  case 0x25E6: // white bullet
340  case 0x00B7: // middle dot
341  case 0x25A1: // white square
342  case 0x25A0: // black square
343  case 0x25AA: // black small square
344  case 0x2B1D: // black very small square
345  case 0x25BA: // black right-pointing pointer
346  case 0x25CF: // black circle
347  case 0x25CB: // white circle
348  return true;
349  default:
350  break; // fall through
351  }
352  return false;
353 }
Definition: strngs.h:45
bool LikelyListMark(const STRING &word)
Definition: paragraphs.cpp:263

◆ LikelyListNumeral()

bool tesseract::LikelyListNumeral ( const STRING word)

Definition at line 229 of file paragraphs.cpp.

229  {
230  const char *kRomans = "ivxlmdIVXLMD";
231  const char *kDigits = "012345789";
232  const char *kOpen = "[{(";
233  const char *kSep = ":;-.,";
234  const char *kClose = "]})";
235 
236  int num_segments = 0;
237  const char *pos = word.string();
238  while (*pos != '\0' && num_segments < 3) {
239  // skip up to two open parens.
240  const char *numeral_start = SkipOne(SkipOne(pos, kOpen), kOpen);
241  const char *numeral_end = SkipChars(numeral_start, kRomans);
242  if (numeral_end != numeral_start) {
243  // Got Roman Numeral. Great.
244  } else {
245  numeral_end = SkipChars(numeral_start, kDigits);
246  if (numeral_end == numeral_start) {
247  // If there's a single latin letter, we can use that.
248  numeral_end = SkipChars(numeral_start, IsLatinLetter);
249  if (numeral_end - numeral_start != 1)
250  break;
251  }
252  }
253  // We got some sort of numeral.
254  num_segments++;
255  // Skip any trailing parens or punctuation.
256  pos = SkipChars(SkipChars(numeral_end, kClose), kSep);
257  if (pos == numeral_end)
258  break;
259  }
260  return *pos == '\0';
261 }
const char * string() const
Definition: strngs.cpp:198
const char * SkipOne(const char *str, const char *toskip)
Definition: paragraphs.cpp:221
bool IsLatinLetter(int ch)
Definition: paragraphs.cpp:194
const char * SkipChars(const char *str, bool(*skip)(int))
Definition: paragraphs.cpp:216

◆ LikelyParagraphStart() [1/2]

bool tesseract::LikelyParagraphStart ( const RowScratchRegisters before,
const RowScratchRegisters after 
)

Definition at line 1673 of file paragraphs.cpp.

1674  {
1675  return before.ri_->num_words == 0 ||
1676  (FirstWordWouldHaveFit(before, after) &&
1677  TextSupportsBreak(before, after));
1678 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool TextSupportsBreak(const RowScratchRegisters &before, const RowScratchRegisters &after)

◆ LikelyParagraphStart() [2/2]

bool tesseract::LikelyParagraphStart ( const RowScratchRegisters before,
const RowScratchRegisters after,
tesseract::ParagraphJustification  j 
)

Definition at line 1680 of file paragraphs.cpp.

1682  {
1683  return before.ri_->num_words == 0 ||
1684  (FirstWordWouldHaveFit(before, after, j) &&
1685  TextSupportsBreak(before, after));
1686 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool TextSupportsBreak(const RowScratchRegisters &before, const RowScratchRegisters &after)

◆ LoadDataFromFile() [1/2]

bool tesseract::LoadDataFromFile ( const char *  filename,
GenericVector< char > *  data 
)
inline

Definition at line 368 of file genericvector.h.

368  {
369  bool result = false;
370  FILE* fp = fopen(filename, "rb");
371  if (fp != NULL) {
372  fseek(fp, 0, SEEK_END);
373  long size = ftell(fp);
374  fseek(fp, 0, SEEK_SET);
375  // Trying to open a directory on Linux sets size to LONG_MAX. Catch it here.
376  if (size > 0 && size < LONG_MAX) {
377  data->resize_no_init(size);
378  result = fread(&(*data)[0], 1, size, fp) == size;
379  }
380  fclose(fp);
381  }
382  return result;
383 }
void resize_no_init(int size)
Definition: genericvector.h:66

◆ LoadDataFromFile() [2/2]

bool tesseract::LoadDataFromFile ( const STRING filename,
GenericVector< char > *  data 
)
inline

Definition at line 385 of file genericvector.h.

386  {
387  return LoadDataFromFile(filename.string(), data);
388 }
bool LoadDataFromFile(const STRING &filename, GenericVector< char > *data)
const char * string() const
Definition: strngs.cpp:198

◆ LoadFileLinesToStrings()

bool tesseract::LoadFileLinesToStrings ( const STRING filename,
GenericVector< STRING > *  lines 
)
inline

Definition at line 402 of file genericvector.h.

403  {
404  GenericVector<char> data;
405  if (!LoadDataFromFile(filename.string(), &data)) {
406  return false;
407  }
408  STRING lines_str(&data[0], data.size());
409  lines_str.split('\n', lines);
410  return true;
411 }
int size() const
Definition: genericvector.h:72
bool LoadDataFromFile(const STRING &filename, GenericVector< char > *data)
const char * string() const
Definition: strngs.cpp:198
Definition: strngs.h:45
void split(const char c, GenericVector< STRING > *splited)
Definition: strngs.cpp:286

◆ LoadShapeTable()

ShapeTable * tesseract::LoadShapeTable ( const STRING file_prefix)

Definition at line 116 of file commontraining.cpp.

116  {
117  ShapeTable* shape_table = nullptr;
118  STRING shape_table_file = file_prefix;
119  shape_table_file += kShapeTableFileSuffix;
120  TFile shape_fp;
121  if (shape_fp.Open(shape_table_file.string(), nullptr)) {
122  shape_table = new ShapeTable;
123  if (!shape_table->DeSerialize(&shape_fp)) {
124  delete shape_table;
125  shape_table = nullptr;
126  tprintf("Error: Failed to read shape table %s\n",
127  shape_table_file.string());
128  } else {
129  int num_shapes = shape_table->NumShapes();
130  tprintf("Read shape table %s of %d shapes\n",
131  shape_table_file.string(), num_shapes);
132  }
133  } else {
134  tprintf("Warning: No shape table file present: %s\n",
135  shape_table_file.string());
136  }
137  return shape_table;
138 }
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198
Definition: strngs.h:45
int NumShapes() const
Definition: shapetable.h:275
bool DeSerialize(TFile *fp)
Definition: shapetable.cpp:252

◆ LoadTrainingData()

MasterTrainer * tesseract::LoadTrainingData ( int  argc,
const char *const *  argv,
bool  replication,
ShapeTable **  shape_table,
STRING file_prefix 
)

Creates a MasterTraininer and loads the training data into it: Initializes feature_defs and IntegerFX. Loads the shape_table if shape_table != nullptr. Loads initial unicharset from -U command-line option. If FLAGS_T is set, loads the majority of data from there, else:

  • Loads font info from -F option.
  • Loads xheights from -X option.
  • Loads samples from .tr files in remaining command-line args.
  • Deletes outliers and computes canonical samples.
  • If FLAGS_output_trainer is set, saves the trainer for future use. Computes canonical and cloud features. If shape_table is not nullptr, but failed to load, make a fake flat one, as shape clustering was not run.

Definition at line 172 of file commontraining.cpp.

175  {
177  InitIntegerFX();
178  *file_prefix = "";
179  if (!FLAGS_D.empty()) {
180  *file_prefix += FLAGS_D.c_str();
181  *file_prefix += "/";
182  }
183  // If we are shape clustering (nullptr shape_table) or we successfully load
184  // a shape_table written by a previous shape clustering, then
185  // shape_analysis will be true, meaning that the MasterTrainer will replace
186  // some members of the unicharset with their fragments.
187  bool shape_analysis = false;
188  if (shape_table != nullptr) {
189  *shape_table = LoadShapeTable(*file_prefix);
190  if (*shape_table != nullptr) shape_analysis = true;
191  } else {
192  shape_analysis = true;
193  }
194  MasterTrainer* trainer = new MasterTrainer(NM_CHAR_ANISOTROPIC,
195  shape_analysis,
196  replication,
197  FLAGS_debug_level);
198  IntFeatureSpace fs;
200  trainer->LoadUnicharset(FLAGS_U.c_str());
201  // Get basic font information from font_properties.
202  if (!FLAGS_F.empty()) {
203  if (!trainer->LoadFontInfo(FLAGS_F.c_str())) {
204  delete trainer;
205  return nullptr;
206  }
207  }
208  if (!FLAGS_X.empty()) {
209  if (!trainer->LoadXHeights(FLAGS_X.c_str())) {
210  delete trainer;
211  return nullptr;
212  }
213  }
214  trainer->SetFeatureSpace(fs);
215  const char* page_name;
216  // Load training data from .tr files on the command line.
217  while ((page_name = GetNextFilename(argc, argv)) != nullptr) {
218  tprintf("Reading %s ...\n", page_name);
219  trainer->ReadTrainingSamples(page_name, feature_defs, false);
220 
221  // If there is a file with [lang].[fontname].exp[num].fontinfo present,
222  // read font spacing information in to fontinfo_table.
223  int pagename_len = strlen(page_name);
224  char* fontinfo_file_name = new char[pagename_len + 7];
225  strncpy(fontinfo_file_name, page_name, pagename_len - 2); // remove "tr"
226  strcpy(fontinfo_file_name + pagename_len - 2, "fontinfo"); // +"fontinfo"
227  trainer->AddSpacingInfo(fontinfo_file_name);
228  delete[] fontinfo_file_name;
229 
230  // Load the images into memory if required by the classifier.
231  if (FLAGS_load_images) {
232  STRING image_name = page_name;
233  // Chop off the tr and replace with tif. Extension must be tif!
234  image_name.truncate_at(image_name.length() - 2);
235  image_name += "tif";
236  trainer->LoadPageImages(image_name.string());
237  }
238  }
239  trainer->PostLoadCleanup();
240  // Write the master trainer if required.
241  if (!FLAGS_output_trainer.empty()) {
242  FILE* fp = fopen(FLAGS_output_trainer.c_str(), "wb");
243  if (fp == nullptr) {
244  tprintf("Can't create saved trainer data!\n");
245  } else {
246  trainer->Serialize(fp);
247  fclose(fp);
248  }
249  }
250  trainer->PreTrainingSetup();
251  if (!FLAGS_O.empty() &&
252  !trainer->unicharset().save_to_file(FLAGS_O.c_str())) {
253  fprintf(stderr, "Failed to save unicharset to file %s\n", FLAGS_O.c_str());
254  delete trainer;
255  return nullptr;
256  }
257  if (shape_table != nullptr) {
258  // If we previously failed to load a shapetable, then shape clustering
259  // wasn't run so make a flat one now.
260  if (*shape_table == nullptr) {
261  *shape_table = new ShapeTable;
262  trainer->SetupFlatShapeTable(*shape_table);
263  tprintf("Flat shape table summary: %s\n",
264  (*shape_table)->SummaryStr().string());
265  }
266  (*shape_table)->set_unicharset(trainer->unicharset());
267  }
268  return trainer;
269 }
const int kBoostDirBuckets
const int kBoostXYBuckets
void Init(uinT8 xbuckets, uinT8 ybuckets, uinT8 thetabuckets)
ShapeTable * LoadShapeTable(const STRING &file_prefix)
const char * GetNextFilename(int argc, const char *const *argv)
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198
Definition: strngs.h:45
void truncate_at(inT32 index)
Definition: strngs.cpp:269
void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs)
Definition: featdefs.cpp:117
FEATURE_DEFS_STRUCT feature_defs
const char * c_str() const
Definition: strngs.cpp:209
void InitIntegerFX()
Definition: intfx.cpp:55
inT32 length() const
Definition: strngs.cpp:193

◆ Logistic()

double tesseract::Logistic ( double  x)
inline

Definition at line 63 of file functions.h.

63  {
64  if (x < 0.0) return 1.0 - Logistic(-x);
65  if (x >= (kTableSize - 1) / kScaleFactor) return 1.0;
66  x *= kScaleFactor;
67  int index = static_cast<int>(floor(x));
68  if (LogisticTable[index] == 0.0) {
69  // Generate the entry.
70  LogisticTable[index] = 1.0 / (1.0 + exp(-index / kScaleFactor));
71  }
72  if (index == kTableSize - 1) return LogisticTable[kTableSize - 1];
73  if (LogisticTable[index + 1] == 0.0) {
74  // Generate the entry.
75  LogisticTable[index + 1] = 1.0 / (1.0 + exp(-(index + 1) / kScaleFactor));
76  }
77  double offset = x - index;
78  return LogisticTable[index] * (1.0 - offset) +
79  LogisticTable[index + 1] * offset;
80 }
double LogisticTable[kTableSize]
Definition: functions.cpp:24
double Logistic(double x)
Definition: functions.h:63
const int kTableSize
Definition: functions.h:37
const double kScaleFactor
Definition: functions.h:39

◆ Main()

int tesseract::Main ( int  argc,
char **  argv 
)

Definition at line 64 of file unicharset_extractor.cpp.

64  {
65  UNICHARSET unicharset;
66  // Load input files
67  for (int arg = 1; arg < argc; ++arg) {
68  STRING file_data = tesseract::ReadFile(argv[arg], /*reader*/ nullptr);
69  if (file_data.length() == 0) continue;
71  if (ReadMemBoxes(-1, /*skip_blanks*/ true, &file_data[0],
72  /*continue_on_failure*/ false, /*boxes*/ nullptr,
73  &texts, /*box_texts*/ nullptr, /*pages*/ nullptr)) {
74  tprintf("Extracting unicharset from box file %s\n", argv[arg]);
75  } else {
76  tprintf("Extracting unicharset from plain text file %s\n", argv[arg]);
77  texts.truncate(0);
78  file_data.split('\n', &texts);
79  }
80  AddStringsToUnicharset(texts, FLAGS_norm_mode, &unicharset);
81  }
82  SetupBasicProperties(/*report_errors*/ true, /*decompose*/ false,
83  &unicharset);
84  // Write unicharset file.
85  if (unicharset.save_to_file(FLAGS_output_unicharset.c_str())) {
86  tprintf("Wrote unicharset file %s\n", FLAGS_output_unicharset.c_str());
87  } else {
88  tprintf("Cannot save unicharset file %s\n",
89  FLAGS_output_unicharset.c_str());
90  return EXIT_FAILURE;
91  }
92  return EXIT_SUCCESS;
93 }
void SetupBasicProperties(bool report_errors, bool decompose, UNICHARSET *unicharset)
#define tprintf(...)
Definition: tprintf.h:31
bool save_to_file(const char *const filename) const
Definition: unicharset.h:347
void truncate(int size)
bool ReadMemBoxes(int target_page, bool skip_blanks, const char *box_data, bool continue_on_failure, GenericVector< TBOX > *boxes, GenericVector< STRING > *texts, GenericVector< STRING > *box_texts, GenericVector< int > *pages)
Definition: boxread.cpp:66
Definition: strngs.h:45
STRING ReadFile(const string &filename, FileReader reader)
void split(const char c, GenericVector< STRING > *splited)
Definition: strngs.cpp:286
inT32 length() const
Definition: strngs.cpp:193

◆ make_tesseract_blob()

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

2540  {
2541  TBLOB *tblob = TessBaseAPI::MakeTBLOB(pix);
2542 
2543  // Normalize TBLOB
2544  ROW *row =
2545  TessBaseAPI::MakeTessOCRRow(baseline, xheight, descender, ascender);
2546  TessBaseAPI::NormalizeTBLOB(tblob, row, numeric_mode);
2547  delete row;
2548  return tblob;
2549 }
Definition: ocrrow.h:32
Definition: blobs.h:261

◆ MakeIndividualGlyphs()

bool tesseract::MakeIndividualGlyphs ( Pix *  pix,
const std::vector< BoxChar *> &  vbox,
const int  input_tiff_page 
)

Definition at line 310 of file text2image.cpp.

312  {
313  // If checks fail, return false without exiting text2image
314  if (!pix) {
315  tprintf("ERROR: MakeIndividualGlyphs(): Input Pix* is nullptr\n");
316  return false;
317  } else if (FLAGS_glyph_resized_size <= 0) {
318  tprintf("ERROR: --glyph_resized_size must be positive\n");
319  return false;
320  } else if (FLAGS_glyph_num_border_pixels_to_pad < 0) {
321  tprintf("ERROR: --glyph_num_border_pixels_to_pad must be 0 or positive\n");
322  return false;
323  }
324 
325  const int n_boxes = vbox.size();
326  int n_boxes_saved = 0;
327  int current_tiff_page = 0;
328  int y_previous = 0;
329  static int glyph_count = 0;
330  for (int i = 0; i < n_boxes; i++) {
331  // Get one bounding box
332  Box* b = vbox[i]->mutable_box();
333  if (!b) continue;
334  const int x = b->x;
335  const int y = b->y;
336  const int w = b->w;
337  const int h = b->h;
338  // Check present tiff page (for multipage tiff)
339  if (y < y_previous-pixGetHeight(pix)/10) {
340  tprintf("ERROR: Wrap-around encountered, at i=%d\n", i);
341  current_tiff_page++;
342  }
343  if (current_tiff_page < input_tiff_page) continue;
344  else if (current_tiff_page > input_tiff_page) break;
345  // Check box validity
346  if (x < 0 || y < 0 ||
347  (x+w-1) >= pixGetWidth(pix) ||
348  (y+h-1) >= pixGetHeight(pix)) {
349  tprintf("ERROR: MakeIndividualGlyphs(): Index out of range, at i=%d"
350  " (x=%d, y=%d, w=%d, h=%d\n)", i, x, y, w, h);
351  continue;
352  } else if (w < FLAGS_glyph_num_border_pixels_to_pad &&
353  h < FLAGS_glyph_num_border_pixels_to_pad) {
354  tprintf("ERROR: Input image too small to be a character, at i=%d\n", i);
355  continue;
356  }
357  // Crop the boxed character
358  Pix* pix_glyph = pixClipRectangle(pix, b, nullptr);
359  if (!pix_glyph) {
360  tprintf("ERROR: MakeIndividualGlyphs(): Failed to clip, at i=%d\n", i);
361  continue;
362  }
363  // Resize to square
364  Pix* pix_glyph_sq = pixScaleToSize(pix_glyph,
365  FLAGS_glyph_resized_size,
366  FLAGS_glyph_resized_size);
367  if (!pix_glyph_sq) {
368  tprintf("ERROR: MakeIndividualGlyphs(): Failed to resize, at i=%d\n", i);
369  continue;
370  }
371  // Zero-pad
372  Pix* pix_glyph_sq_pad = pixAddBorder(pix_glyph_sq,
373  FLAGS_glyph_num_border_pixels_to_pad,
374  0);
375  if (!pix_glyph_sq_pad) {
376  tprintf("ERROR: MakeIndividualGlyphs(): Failed to zero-pad, at i=%d\n",
377  i);
378  continue;
379  }
380  // Write out
381  Pix* pix_glyph_sq_pad_8 = pixConvertTo8(pix_glyph_sq_pad, false);
382  char filename[1024];
383  snprintf(filename, 1024, "%s_%d.jpg", FLAGS_outputbase.c_str(),
384  glyph_count++);
385  if (pixWriteJpeg(filename, pix_glyph_sq_pad_8, 100, 0)) {
386  tprintf("ERROR: MakeIndividualGlyphs(): Failed to write JPEG to %s,"
387  " at i=%d\n", filename, i);
388  continue;
389  }
390 
391  pixDestroy(&pix_glyph);
392  pixDestroy(&pix_glyph_sq);
393  pixDestroy(&pix_glyph_sq_pad);
394  pixDestroy(&pix_glyph_sq_pad_8);
395  n_boxes_saved++;
396  y_previous = y;
397  }
398  if (n_boxes_saved == 0) {
399  return false;
400  } else {
401  tprintf("Total number of characters saved = %d\n", n_boxes_saved);
402  return true;
403  }
404 }
#define tprintf(...)
Definition: tprintf.h:31

◆ MarkRowsWithModel()

void tesseract::MarkRowsWithModel ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
const ParagraphModel model,
bool  ltr,
int  eop_threshold 
)

Definition at line 808 of file paragraphs.cpp.

812  {
813  if (!AcceptableRowArgs(0, 0, __func__, rows, row_start, row_end))
814  return;
815  for (int row = row_start; row < row_end; row++) {
816  bool valid_first = ValidFirstLine(rows, row, model);
817  bool valid_body = ValidBodyLine(rows, row, model);
818  if (valid_first && !valid_body) {
819  (*rows)[row].AddStartLine(model);
820  } else if (valid_body && !valid_first) {
821  (*rows)[row].AddBodyLine(model);
822  } else if (valid_body && valid_first) {
823  bool after_eop = (row == row_start);
824  if (row > row_start) {
825  if (eop_threshold > 0) {
826  if (model->justification() == JUSTIFICATION_LEFT) {
827  after_eop = (*rows)[row - 1].rindent_ > eop_threshold;
828  } else {
829  after_eop = (*rows)[row - 1].lindent_ > eop_threshold;
830  }
831  } else {
832  after_eop = FirstWordWouldHaveFit((*rows)[row - 1], (*rows)[row],
833  model->justification());
834  }
835  }
836  if (after_eop) {
837  (*rows)[row].AddStartLine(model);
838  } else {
839  (*rows)[row].AddBodyLine(model);
840  }
841  } else {
842  // Do nothing. Stray row.
843  }
844  }
845 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)

◆ MarkStrongEvidence()

void tesseract::MarkStrongEvidence ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end 
)

Definition at line 1831 of file paragraphs.cpp.

1832  {
1833  // Record patently obvious body text.
1834  for (int i = row_start + 1; i < row_end; i++) {
1835  const RowScratchRegisters &prev = (*rows)[i - 1];
1836  RowScratchRegisters &curr = (*rows)[i];
1837  tesseract::ParagraphJustification typical_justification =
1838  prev.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1839  if (!curr.ri_->rword_likely_starts_idea &&
1840  !curr.ri_->lword_likely_starts_idea &&
1841  !FirstWordWouldHaveFit(prev, curr, typical_justification)) {
1842  curr.SetBodyLine();
1843  }
1844  }
1845 
1846  // Record patently obvious start paragraph lines.
1847  //
1848  // It's an extremely good signal of the start of a paragraph that
1849  // the first word would have fit on the end of the previous line.
1850  // However, applying just that signal would have us mark random
1851  // start lines of lineated text (poetry and source code) and some
1852  // centered headings as paragraph start lines. Therefore, we use
1853  // a second qualification for a paragraph start: Not only should
1854  // the first word of this line have fit on the previous line,
1855  // but also, this line should go full to the right of the block,
1856  // disallowing a subsequent word from having fit on this line.
1857 
1858  // First row:
1859  {
1860  RowScratchRegisters &curr = (*rows)[row_start];
1861  RowScratchRegisters &next = (*rows)[row_start + 1];
1863  curr.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1864  if (curr.GetLineType() == LT_UNKNOWN &&
1865  !FirstWordWouldHaveFit(curr, next, j) &&
1866  (curr.ri_->lword_likely_starts_idea ||
1867  curr.ri_->rword_likely_starts_idea)) {
1868  curr.SetStartLine();
1869  }
1870  }
1871  // Middle rows
1872  for (int i = row_start + 1; i < row_end - 1; i++) {
1873  RowScratchRegisters &prev = (*rows)[i - 1];
1874  RowScratchRegisters &curr = (*rows)[i];
1875  RowScratchRegisters &next = (*rows)[i + 1];
1877  curr.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1878  if (curr.GetLineType() == LT_UNKNOWN &&
1879  !FirstWordWouldHaveFit(curr, next, j) &&
1880  LikelyParagraphStart(prev, curr, j)) {
1881  curr.SetStartLine();
1882  }
1883  }
1884  // Last row
1885  { // the short circuit at the top means we have at least two lines.
1886  RowScratchRegisters &prev = (*rows)[row_end - 2];
1887  RowScratchRegisters &curr = (*rows)[row_end - 1];
1889  curr.ri_->ltr ? JUSTIFICATION_LEFT : JUSTIFICATION_RIGHT;
1890  if (curr.GetLineType() == LT_UNKNOWN &&
1891  !FirstWordWouldHaveFit(curr, curr, j) &&
1892  LikelyParagraphStart(prev, curr, j)) {
1893  curr.SetStartLine();
1894  }
1895  }
1896 }
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool LikelyParagraphStart(const RowScratchRegisters &before, const RowScratchRegisters &after, tesseract::ParagraphJustification j)
ParagraphJustification
Definition: publictypes.h:251

◆ ModelStrongEvidence()

void tesseract::ModelStrongEvidence ( int  debug_level,
GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
bool  allow_flush_models,
ParagraphTheory theory 
)

Definition at line 1901 of file paragraphs.cpp.

1905  {
1906  if (!AcceptableRowArgs(debug_level, 2, __func__, rows, row_start, row_end))
1907  return;
1908 
1909  int start = row_start;
1910  while (start < row_end) {
1911  while (start < row_end && (*rows)[start].GetLineType() != LT_START)
1912  start++;
1913  if (start >= row_end - 1)
1914  break;
1915 
1916  int tolerance = Epsilon((*rows)[start + 1].ri_->average_interword_space);
1917  int end = start;
1918  ParagraphModel last_model;
1919  bool next_consistent;
1920  do {
1921  ++end;
1922  // rows[row, end) was consistent.
1923  // If rows[row, end + 1) is not consistent,
1924  // just model rows[row, end)
1925  if (end < row_end - 1) {
1926  RowScratchRegisters &next = (*rows)[end];
1927  LineType lt = next.GetLineType();
1928  next_consistent = lt == LT_BODY ||
1929  (lt == LT_UNKNOWN &&
1930  !FirstWordWouldHaveFit((*rows)[end - 1], (*rows)[end]));
1931  } else {
1932  next_consistent = false;
1933  }
1934  if (next_consistent) {
1936  rows, start, end + 1, tolerance, &next_consistent);
1937  if (((*rows)[start].ri_->ltr &&
1938  last_model.justification() == JUSTIFICATION_LEFT &&
1939  next_model.justification() != JUSTIFICATION_LEFT) ||
1940  (!(*rows)[start].ri_->ltr &&
1941  last_model.justification() == JUSTIFICATION_RIGHT &&
1942  next_model.justification() != JUSTIFICATION_RIGHT)) {
1943  next_consistent = false;
1944  }
1945  last_model = next_model;
1946  } else {
1947  next_consistent = false;
1948  }
1949  } while (next_consistent && end < row_end);
1950  // At this point, rows[start, end) looked like it could have been a
1951  // single paragraph. If we can make a good ParagraphModel for it,
1952  // do so and mark this sequence with that model.
1953  if (end > start + 1) {
1954  // emit a new paragraph if we have more than one line.
1955  const ParagraphModel *model = NULL;
1957  debug_level, rows, start, end,
1958  Epsilon(InterwordSpace(*rows, start, end)));
1959  if (new_model.justification() == JUSTIFICATION_UNKNOWN) {
1960  // couldn't create a good model, oh well.
1961  } else if (new_model.is_flush()) {
1962  if (end == start + 2) {
1963  // It's very likely we just got two paragraph starts in a row.
1964  end = start + 1;
1965  } else if (start == row_start) {
1966  // Mark this as a Crown.
1967  if (new_model.justification() == JUSTIFICATION_LEFT) {
1968  model = kCrownLeft;
1969  } else {
1970  model = kCrownRight;
1971  }
1972  } else if (allow_flush_models) {
1973  model = theory->AddModel(new_model);
1974  }
1975  } else {
1976  model = theory->AddModel(new_model);
1977  }
1978  if (model) {
1979  (*rows)[start].AddStartLine(model);
1980  for (int i = start + 1; i < end; i++) {
1981  (*rows)[i].AddBodyLine(model);
1982  }
1983  }
1984  }
1985  start = end;
1986  }
1987 }
ParagraphModel InternalParagraphModelByOutline(const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance, bool *consistent)
bool FirstWordWouldHaveFit(const RowScratchRegisters &before, const RowScratchRegisters &after)
bool is_flush() const
Definition: ocrpara.h:171
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:46
int InterwordSpace(const GenericVector< RowScratchRegisters > &rows, int row_start, int row_end)
ParagraphModel ParagraphModelByOutline(int debug_level, const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance)
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:48

◆ MultiplyAccumulate()

void tesseract::MultiplyAccumulate ( int  n,
const double *  u,
const double *  v,
double *  out 
)
inline

Definition at line 201 of file functions.h.

202  {
203  for (int i = 0; i < n; i++) {
204  out[i] += u[i] * v[i];
205  }
206 }

◆ MultiplyVectorsInPlace()

void tesseract::MultiplyVectorsInPlace ( int  n,
const double *  src,
double *  inout 
)
inline

Definition at line 196 of file functions.h.

196  {
197  for (int i = 0; i < n; ++i) inout[i] *= src[i];
198 }

◆ NormalizeCleanAndSegmentUTF8()

bool tesseract::NormalizeCleanAndSegmentUTF8 ( UnicodeNormMode  u_mode,
OCRNorm  ocr_normalize,
GraphemeNormMode  g_mode,
bool  report_errors,
const char *  str8,
std::vector< string > *  graphemes 
)

Definition at line 172 of file normstrngs.cpp.

175  {
176  std::vector<char32> normed32;
177  NormalizeUTF8ToUTF32(u_mode, ocr_normalize, str8, &normed32);
178  StripJoiners(&normed32);
179  std::vector<std::vector<char32>> graphemes32;
180  bool success = Validator::ValidateCleanAndSegment(g_mode, report_errors,
181  normed32, &graphemes32);
182  if (g_mode != GraphemeNormMode::kSingleString && success) {
183  // If we modified the string to clean it up, the segmentation may not be
184  // correct, so check for changes and do it again.
185  std::vector<char32> cleaned32;
186  for (const auto& g : graphemes32) {
187  cleaned32.insert(cleaned32.end(), g.begin(), g.end());
188  }
189  if (cleaned32 != normed32) {
190  graphemes32.clear();
191  success = Validator::ValidateCleanAndSegment(g_mode, report_errors,
192  cleaned32, &graphemes32);
193  }
194  }
195  graphemes->clear();
196  graphemes->reserve(graphemes32.size());
197  for (const auto& grapheme : graphemes32) {
198  graphemes->push_back(UNICHAR::UTF32ToUTF8(grapheme));
199  }
200  return success;
201 }

◆ NormalizeDirection()

uinT8 tesseract::NormalizeDirection ( uinT8  dir,
const FCOORD unnormed_pos,
const DENORM denorm,
const DENORM root_denorm 
)

Definition at line 171 of file intfx.cpp.

172  {
173  // Convert direction to a vector.
174  FCOORD unnormed_end;
175  unnormed_end.from_direction(dir);
176  unnormed_end += unnormed_pos;
177  FCOORD normed_pos, normed_end;
178  denorm.NormTransform(root_denorm, unnormed_pos, &normed_pos);
179  denorm.NormTransform(root_denorm, unnormed_end, &normed_end);
180  normed_end -= normed_pos;
181  return normed_end.to_direction();
182 }
Definition: points.h:189
uinT8 to_direction() const
Definition: points.cpp:111
void NormTransform(const DENORM *first_norm, const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:334
void from_direction(uinT8 direction)
Definition: points.cpp:115

◆ NormalizeUTF8String()

bool tesseract::NormalizeUTF8String ( UnicodeNormMode  u_mode,
OCRNorm  ocr_normalize,
GraphemeNorm  grapheme_normalize,
const char *  str8,
string *  normalized 
)

Definition at line 147 of file normstrngs.cpp.

149  {
150  std::vector<char32> normed32;
151  NormalizeUTF8ToUTF32(u_mode, ocr_normalize, str8, &normed32);
152  if (grapheme_normalize == GraphemeNorm::kNormalize) {
153  StripJoiners(&normed32);
154  std::vector<std::vector<char32>> graphemes;
155  bool success = Validator::ValidateCleanAndSegment(
156  GraphemeNormMode::kSingleString, false, normed32, &graphemes);
157  if (graphemes.empty() || graphemes[0].empty()) {
158  success = false;
159  } else if (normalized != nullptr) {
160  *normalized = UNICHAR::UTF32ToUTF8(graphemes[0]);
161  }
162  return success;
163  }
164  if (normalized != nullptr) *normalized = UNICHAR::UTF32ToUTF8(normed32);
165  return true;
166 }

◆ OCRNormalize()

char32 tesseract::OCRNormalize ( char32  ch)

Definition at line 204 of file normstrngs.cpp.

204  {
205  if (is_hyphen_punc(ch))
206  return '-';
207  else if (is_single_quote(ch))
208  return '\'';
209  else if (is_double_quote(ch))
210  return '"';
211  return ch;
212 }
bool is_double_quote(const char32 ch)
Definition: normstrngs.cpp:74
bool is_hyphen_punc(const char32 ch)
Definition: normstrngs.cpp:38
bool is_single_quote(const char32 ch)
Definition: normstrngs.cpp:56

◆ OtsuStats()

int tesseract::OtsuStats ( const int *  histogram,
int *  H_out,
int *  omega0_out 
)

Definition at line 174 of file otsuthr.cpp.

174  {
175  int H = 0;
176  double mu_T = 0.0;
177  for (int i = 0; i < kHistogramSize; ++i) {
178  H += histogram[i];
179  mu_T += static_cast<double>(i) * histogram[i];
180  }
181 
182  // Now maximize sig_sq_B over t.
183  // http://www.ctie.monash.edu.au/hargreave/Cornall_Terry_328.pdf
184  int best_t = -1;
185  int omega_0, omega_1;
186  int best_omega_0 = 0;
187  double best_sig_sq_B = 0.0;
188  double mu_0, mu_1, mu_t;
189  omega_0 = 0;
190  mu_t = 0.0;
191  for (int t = 0; t < kHistogramSize - 1; ++t) {
192  omega_0 += histogram[t];
193  mu_t += t * static_cast<double>(histogram[t]);
194  if (omega_0 == 0)
195  continue;
196  omega_1 = H - omega_0;
197  if (omega_1 == 0)
198  break;
199  mu_0 = mu_t / omega_0;
200  mu_1 = (mu_T - mu_t) / omega_1;
201  double sig_sq_B = mu_1 - mu_0;
202  sig_sq_B *= sig_sq_B * omega_0 * omega_1;
203  if (best_t < 0 || sig_sq_B > best_sig_sq_B) {
204  best_sig_sq_B = sig_sq_B;
205  best_t = t;
206  best_omega_0 = omega_0;
207  }
208  }
209  if (H_out != NULL) *H_out = H;
210  if (omega0_out != NULL) *omega0_out = best_omega_0;
211  return best_t;
212 }
const int kHistogramSize
Definition: otsuthr.h:27

◆ OtsuThreshold()

int tesseract::OtsuThreshold ( Pix *  src_pix,
int  left,
int  top,
int  width,
int  height,
int **  thresholds,
int **  hi_values 
)

Definition at line 39 of file otsuthr.cpp.

40  {
41  int num_channels = pixGetDepth(src_pix) / 8;
42  // Of all channels with no good hi_value, keep the best so we can always
43  // produce at least one answer.
44  PERF_COUNT_START("OtsuThreshold")
45  int best_hi_value = 1;
46  int best_hi_index = 0;
47  bool any_good_hivalue = false;
48  double best_hi_dist = 0.0;
49  *thresholds = new int[num_channels];
50  *hi_values = new int[num_channels];
51 
52  // only use opencl if compiled w/ OpenCL and selected device is opencl
53 #ifdef USE_OPENCL
54  // all of channel 0 then all of channel 1...
55  int* histogramAllChannels = new int[kHistogramSize * num_channels];
56 
57  // Calculate Histogram on GPU
58  OpenclDevice od;
59  if (od.selectedDeviceIsOpenCL() && (num_channels == 1 || num_channels == 4) &&
60  top == 0 && left == 0) {
61  od.HistogramRectOCL((unsigned char*)pixGetData(src_pix), num_channels,
62  pixGetWpl(src_pix) * 4, left, top, width, height,
63  kHistogramSize, histogramAllChannels);
64 
65  // Calculate Threshold from Histogram on cpu
66  for (int ch = 0; ch < num_channels; ++ch) {
67  (*thresholds)[ch] = -1;
68  (*hi_values)[ch] = -1;
69  int *histogram = &histogramAllChannels[kHistogramSize * ch];
70  int H;
71  int best_omega_0;
72  int best_t = OtsuStats(histogram, &H, &best_omega_0);
73  if (best_omega_0 == 0 || best_omega_0 == H) {
74  // This channel is empty.
75  continue;
76  }
77  // To be a convincing foreground we must have a small fraction of H
78  // or to be a convincing background we must have a large fraction of H.
79  // In between we assume this channel contains no thresholding information.
80  int hi_value = best_omega_0 < H * 0.5;
81  (*thresholds)[ch] = best_t;
82  if (best_omega_0 > H * 0.75) {
83  any_good_hivalue = true;
84  (*hi_values)[ch] = 0;
85  } else if (best_omega_0 < H * 0.25) {
86  any_good_hivalue = true;
87  (*hi_values)[ch] = 1;
88  } else {
89  // In case all channels are like this, keep the best of the bad lot.
90  double hi_dist = hi_value ? (H - best_omega_0) : best_omega_0;
91  if (hi_dist > best_hi_dist) {
92  best_hi_dist = hi_dist;
93  best_hi_value = hi_value;
94  best_hi_index = ch;
95  }
96  }
97  }
98  } else {
99 #endif
100  for (int ch = 0; ch < num_channels; ++ch) {
101  (*thresholds)[ch] = -1;
102  (*hi_values)[ch] = -1;
103  // Compute the histogram of the image rectangle.
104  int histogram[kHistogramSize];
105  HistogramRect(src_pix, ch, left, top, width, height, histogram);
106  int H;
107  int best_omega_0;
108  int best_t = OtsuStats(histogram, &H, &best_omega_0);
109  if (best_omega_0 == 0 || best_omega_0 == H) {
110  // This channel is empty.
111  continue;
112  }
113  // To be a convincing foreground we must have a small fraction of H
114  // or to be a convincing background we must have a large fraction of H.
115  // In between we assume this channel contains no thresholding information.
116  int hi_value = best_omega_0 < H * 0.5;
117  (*thresholds)[ch] = best_t;
118  if (best_omega_0 > H * 0.75) {
119  any_good_hivalue = true;
120  (*hi_values)[ch] = 0;
121  } else if (best_omega_0 < H * 0.25) {
122  any_good_hivalue = true;
123  (*hi_values)[ch] = 1;
124  } else {
125  // In case all channels are like this, keep the best of the bad lot.
126  double hi_dist = hi_value ? (H - best_omega_0) : best_omega_0;
127  if (hi_dist > best_hi_dist) {
128  best_hi_dist = hi_dist;
129  best_hi_value = hi_value;
130  best_hi_index = ch;
131  }
132  }
133  }
134 #ifdef USE_OPENCL
135  }
136  delete[] histogramAllChannels;
137 #endif // USE_OPENCL
138 
139  if (!any_good_hivalue) {
140  // Use the best of the ones that were not good enough.
141  (*hi_values)[best_hi_index] = best_hi_value;
142  }
144  return num_channels;
145 }
void HistogramRect(Pix *src_pix, int channel, int left, int top, int width, int height, int *histogram)
Definition: otsuthr.cpp:151
#define PERF_COUNT_END
int OtsuStats(const int *histogram, int *H_out, int *omega0_out)
Definition: otsuthr.cpp:174
const int kHistogramSize
Definition: otsuthr.h:27
#define PERF_COUNT_START(FUNCT_NAME)

◆ ParagraphModelByOutline()

ParagraphModel tesseract::ParagraphModelByOutline ( int  debug_level,
const GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
int  tolerance 
)

Definition at line 1794 of file paragraphs.cpp.

1797  {
1798  bool unused_consistent;
1800  rows, start, end, tolerance, &unused_consistent);
1801  if (debug_level >= 2 && retval.justification() == JUSTIFICATION_UNKNOWN) {
1802  tprintf("Could not determine a model for this paragraph:\n");
1803  PrintRowRange(*rows, start, end);
1804  }
1805  return retval;
1806 }
ParagraphModel InternalParagraphModelByOutline(const GenericVector< RowScratchRegisters > *rows, int start, int end, int tolerance, bool *consistent)
tesseract::ParagraphJustification justification() const
Definition: ocrpara.h:164
#define tprintf(...)
Definition: tprintf.h:31

◆ ParamsTrainingFeatureByName()

int tesseract::ParamsTrainingFeatureByName ( const char *  name)

Definition at line 26 of file params_training_featdef.cpp.

26  {
27  if (name == NULL)
28  return -1;
29  int array_size = sizeof(kParamsTrainingFeatureTypeName) /
30  sizeof(kParamsTrainingFeatureTypeName[0]);
31  for (int i = 0; i < array_size; i++) {
32  if (kParamsTrainingFeatureTypeName[i] == NULL)
33  continue;
34  if (strcmp(name, kParamsTrainingFeatureTypeName[i]) == 0)
35  return i;
36  }
37  return -1;
38 }

◆ ParseCommandLineFlags()

void tesseract::ParseCommandLineFlags ( const char *  usage,
int *  argc,
char ***  argv,
const bool  remove_flags 
)

Definition at line 153 of file commandlineflags.cpp.

155  {
156  if (*argc == 1) {
157  printf("USAGE: %s\n", usage);
159  exit(0);
160  }
161 
162  unsigned int i = 1;
163  for (i = 1; i < *argc; ++i) {
164  const char* current_arg = (*argv)[i];
165  // If argument does not start with a hyphen then break.
166  if (current_arg[0] != '-') {
167  break;
168  }
169  // Position current_arg after startings hyphens. We treat a sequence of
170  // consecutive hyphens of any length identically.
171  while (*current_arg == '-') {
172  ++current_arg;
173  }
174  // If this is asking for usage, print the help message and abort.
175  if (!strcmp(current_arg, "help") ||
176  !strcmp(current_arg, "helpshort")) {
177  tprintf("USAGE: %s\n", usage);
179  exit(0);
180  }
181  // Find the starting position of the value if it was specified in this
182  // string.
183  const char* equals_position = strchr(current_arg, '=');
184  const char* rhs = nullptr;
185  if (equals_position != nullptr) {
186  rhs = equals_position + 1;
187  }
188  // Extract the flag name.
189  STRING lhs;
190  if (equals_position == nullptr) {
191  lhs = current_arg;
192  } else {
193  lhs.assign(current_arg, equals_position - current_arg);
194  }
195  if (!lhs.length()) {
196  tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
197  exit(1);
198  }
199 
200  // Find the flag name in the list of global flags.
201  // inT32 flag
202  inT32 int_val;
203  if (IntFlagExists(lhs.string(), &int_val)) {
204  if (rhs != nullptr) {
205  if (!strlen(rhs)) {
206  // Bad input of the format --int_flag=
207  tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
208  exit(1);
209  }
210  if (!SafeAtoi(rhs, &int_val)) {
211  tprintf("ERROR: Could not parse int from %s in flag %s\n",
212  rhs, (*argv)[i]);
213  exit(1);
214  }
215  } else {
216  // We need to parse the next argument
217  if (i + 1 >= *argc) {
218  tprintf("ERROR: Could not find value argument for flag %s\n",
219  lhs.string());
220  exit(1);
221  } else {
222  ++i;
223  if (!SafeAtoi((*argv)[i], &int_val)) {
224  tprintf("ERROR: Could not parse inT32 from %s\n", (*argv)[i]);
225  exit(1);
226  }
227  }
228  }
229  SetIntFlagValue(lhs.string(), int_val);
230  continue;
231  }
232 
233  // double flag
234  double double_val;
235  if (DoubleFlagExists(lhs.string(), &double_val)) {
236  if (rhs != nullptr) {
237  if (!strlen(rhs)) {
238  // Bad input of the format --double_flag=
239  tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
240  exit(1);
241  }
242  if (!SafeAtod(rhs, &double_val)) {
243  tprintf("ERROR: Could not parse double from %s in flag %s\n",
244  rhs, (*argv)[i]);
245  exit(1);
246  }
247  } else {
248  // We need to parse the next argument
249  if (i + 1 >= *argc) {
250  tprintf("ERROR: Could not find value argument for flag %s\n",
251  lhs.string());
252  exit(1);
253  } else {
254  ++i;
255  if (!SafeAtod((*argv)[i], &double_val)) {
256  tprintf("ERROR: Could not parse double from %s\n", (*argv)[i]);
257  exit(1);
258  }
259  }
260  }
261  SetDoubleFlagValue(lhs.string(), double_val);
262  continue;
263  }
264 
265  // Bool flag. Allow input forms --flag (equivalent to --flag=true),
266  // --flag=false, --flag=true, --flag=0 and --flag=1
267  bool bool_val;
268  if (BoolFlagExists(lhs.string(), &bool_val)) {
269  if (rhs == nullptr) {
270  // --flag form
271  bool_val = true;
272  } else {
273  if (!strlen(rhs)) {
274  // Bad input of the format --bool_flag=
275  tprintf("ERROR: Bad argument: %s\n", (*argv)[i]);
276  exit(1);
277  }
278  if (!strcmp(rhs, "false") || !strcmp(rhs, "0")) {
279  bool_val = false;
280  } else if (!strcmp(rhs, "true") || !strcmp(rhs, "1")) {
281  bool_val = true;
282  } else {
283  tprintf("ERROR: Could not parse bool from flag %s\n", (*argv)[i]);
284  exit(1);
285  }
286  }
287  SetBoolFlagValue(lhs.string(), bool_val);
288  continue;
289  }
290 
291  // string flag
292  const char* string_val;
293  if (StringFlagExists(lhs.string(), &string_val)) {
294  if (rhs != nullptr) {
295  string_val = rhs;
296  } else {
297  // Pick the next argument
298  if (i + 1 >= *argc) {
299  tprintf("ERROR: Could not find string value for flag %s\n",
300  lhs.string());
301  exit(1);
302  } else {
303  string_val = (*argv)[++i];
304  }
305  }
306  SetStringFlagValue(lhs.string(), string_val);
307  continue;
308  }
309 
310  // Flag was not found. Exit with an error message.
311  tprintf("ERROR: Non-existent flag %s\n", (*argv)[i]);
312  exit(1);
313  } // for each argv
314  if (remove_flags) {
315  (*argv)[i - 1] = (*argv)[0];
316  (*argv) += (i - 1);
317  (*argc) -= (i - 1);
318  }
319 }
void SetBoolFlagValue(const char *flag_name, const bool new_val)
bool BoolFlagExists(const char *flag_name, bool *value)
void SetIntFlagValue(const char *flag_name, const inT32 new_val)
#define tprintf(...)
Definition: tprintf.h:31
bool DoubleFlagExists(const char *flag_name, double *value)
void assign(const char *cstr, int len)
Definition: strngs.cpp:422
bool SafeAtod(const char *str, double *val)
const char * string() const
Definition: strngs.cpp:198
bool StringFlagExists(const char *flag_name, const char **value)
Definition: strngs.h:45
int32_t inT32
Definition: host.h:38
bool SafeAtoi(const char *str, int *val)
bool IntFlagExists(const char *flag_name, inT32 *value)
void SetDoubleFlagValue(const char *flag_name, const double new_val)
inT32 length() const
Definition: strngs.cpp:193
void SetStringFlagValue(const char *flag_name, const char *new_val)
void PrintCommandLineFlags()

◆ prec()

double tesseract::prec ( double  x)

Definition at line 205 of file pdfrenderer.cpp.

205  {
206  double kPrecision = 1000.0;
207  double a = round(x * kPrecision) / kPrecision;
208  if (a == -0)
209  return 0;
210  return a;
211 }

◆ PrepareDistortedPix()

Pix * tesseract::PrepareDistortedPix ( const Pix *  pix,
bool  perspective,
bool  invert,
bool  white_noise,
bool  smooth_noise,
bool  blur,
int  box_reduction,
TRand randomizer,
GenericVector< TBOX > *  boxes 
)

Definition at line 178 of file degradeimage.cpp.

181  {
182  Pix* distorted = pixCopy(nullptr, const_cast<Pix*>(pix));
183  // Things to do to synthetic training data.
184  if (invert && randomizer->SignedRand(1.0) < 0)
185  pixInvert(distorted, distorted);
186  if ((white_noise || smooth_noise) && randomizer->SignedRand(1.0) > 0.0) {
187  // TODO(rays) Cook noise in a more thread-safe manner than rand().
188  // Attempt to make the sequences reproducible.
189  srand(randomizer->IntRand());
190  Pix* pixn = pixAddGaussianNoise(distorted, 8.0);
191  pixDestroy(&distorted);
192  if (smooth_noise) {
193  distorted = pixBlockconv(pixn, 1, 1);
194  pixDestroy(&pixn);
195  } else {
196  distorted = pixn;
197  }
198  }
199  if (blur && randomizer->SignedRand(1.0) > 0.0) {
200  Pix* blurred = pixBlockconv(distorted, 1, 1);
201  pixDestroy(&distorted);
202  distorted = blurred;
203  }
204  if (perspective)
205  GeneratePerspectiveDistortion(0, 0, randomizer, &distorted, boxes);
206  if (boxes != nullptr) {
207  for (int b = 0; b < boxes->size(); ++b) {
208  (*boxes)[b].scale(1.0f / box_reduction);
209  if ((*boxes)[b].width() <= 0)
210  (*boxes)[b].set_right((*boxes)[b].left() + 1);
211  }
212  }
213  return distorted;
214 }
int size() const
Definition: genericvector.h:72
void GeneratePerspectiveDistortion(int width, int height, TRand *randomizer, Pix **pix, GenericVector< TBOX > *boxes)

◆ PrintCommandLineFlags()

void tesseract::PrintCommandLineFlags ( )

Definition at line 111 of file commandlineflags.cpp.

111  {
112  const char* kFlagNamePrefix = "FLAGS_";
113  const int kFlagNamePrefixLen = strlen(kFlagNamePrefix);
114  for (int i = 0; i < GlobalParams()->int_params.size(); ++i) {
115  if (!strncmp(GlobalParams()->int_params[i]->name_str(),
116  kFlagNamePrefix, kFlagNamePrefixLen)) {
117  printf(" --%s %s (type:int default:%d)\n",
118  GlobalParams()->int_params[i]->name_str() + kFlagNamePrefixLen,
119  GlobalParams()->int_params[i]->info_str(),
120  inT32(*(GlobalParams()->int_params[i])));
121  }
122  }
123  for (int i = 0; i < GlobalParams()->double_params.size(); ++i) {
124  if (!strncmp(GlobalParams()->double_params[i]->name_str(),
125  kFlagNamePrefix, kFlagNamePrefixLen)) {
126  printf(" --%s %s (type:double default:%g)\n",
127  GlobalParams()->double_params[i]->name_str() + kFlagNamePrefixLen,
128  GlobalParams()->double_params[i]->info_str(),
129  static_cast<double>(*(GlobalParams()->double_params[i])));
130  }
131  }
132  for (int i = 0; i < GlobalParams()->bool_params.size(); ++i) {
133  if (!strncmp(GlobalParams()->bool_params[i]->name_str(),
134  kFlagNamePrefix, kFlagNamePrefixLen)) {
135  printf(" --%s %s (type:bool default:%s)\n",
136  GlobalParams()->bool_params[i]->name_str() + kFlagNamePrefixLen,
137  GlobalParams()->bool_params[i]->info_str(),
138  (BOOL8(*(GlobalParams()->bool_params[i])) ? "true" : "false"));
139  }
140  }
141  for (int i = 0; i < GlobalParams()->string_params.size(); ++i) {
142  if (!strncmp(GlobalParams()->string_params[i]->name_str(),
143  kFlagNamePrefix, kFlagNamePrefixLen)) {
144  printf(" --%s %s (type:string default:%s)\n",
145  GlobalParams()->string_params[i]->name_str() + kFlagNamePrefixLen,
146  GlobalParams()->string_params[i]->info_str(),
147  GlobalParams()->string_params[i]->string());
148  }
149  }
150 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< IntParam * > int_params
Definition: params.h:44
GenericVector< DoubleParam * > double_params
Definition: params.h:47
GenericVector< BoolParam * > bool_params
Definition: params.h:45
int32_t inT32
Definition: host.h:38
GenericVector< StringParam * > string_params
Definition: params.h:46
unsigned char BOOL8
Definition: host.h:44

◆ ProjectiveCoeffs()

int tesseract::ProjectiveCoeffs ( int  width,
int  height,
TRand randomizer,
float **  im_coeffs,
float **  box_coeffs 
)

Definition at line 265 of file degradeimage.cpp.

266  {
267  // Setup "from" points.
268  Pta* src_pts = ptaCreate(4);
269  ptaAddPt(src_pts, 0.0f, 0.0f);
270  ptaAddPt(src_pts, width, 0.0f);
271  ptaAddPt(src_pts, width, height);
272  ptaAddPt(src_pts, 0.0f, height);
273  // Extract factors from pseudo-random sequence.
274  float factors[FN_NUM_FACTORS];
275  float shear = 0.0f; // Shear is signed.
276  for (int i = 0; i < FN_NUM_FACTORS; ++i) {
277  // Everything is squared to make wild values rarer.
278  if (i == FN_SHEAR) {
279  // Shear is signed.
280  shear = randomizer->SignedRand(0.5 / 3.0);
281  shear = shear >= 0.0 ? shear * shear : -shear * shear;
282  // Keep the sheared points within the original rectangle.
283  if (shear < -factors[FN_X0]) shear = -factors[FN_X0];
284  if (shear > factors[FN_X1]) shear = factors[FN_X1];
285  factors[i] = shear;
286  } else if (i != FN_INCOLOR) {
287  factors[i] = fabs(randomizer->SignedRand(1.0));
288  if (i <= FN_Y3)
289  factors[i] *= 5.0 / 8.0;
290  else
291  factors[i] *= 0.5;
292  factors[i] *= factors[i];
293  }
294  }
295  // Setup "to" points.
296  Pta* dest_pts = ptaCreate(4);
297  ptaAddPt(dest_pts, factors[FN_X0] * width, factors[FN_Y0] * height);
298  ptaAddPt(dest_pts, (1.0f - factors[FN_X1]) * width, factors[FN_Y1] * height);
299  ptaAddPt(dest_pts, (1.0f - factors[FN_X1] + shear) * width,
300  (1 - factors[FN_Y2]) * height);
301  ptaAddPt(dest_pts, (factors[FN_X0] + shear) * width,
302  (1 - factors[FN_Y3]) * height);
303  getProjectiveXformCoeffs(dest_pts, src_pts, im_coeffs);
304  getProjectiveXformCoeffs(src_pts, dest_pts, box_coeffs);
305  ptaDestroy(&src_pts);
306  ptaDestroy(&dest_pts);
307  return factors[FN_INCOLOR] > 0.5f ? L_BRING_IN_WHITE : L_BRING_IN_BLACK;
308 }

◆ PSM_BLOCK_FIND_ENABLED()

bool tesseract::PSM_BLOCK_FIND_ENABLED ( int  pageseg_mode)
inline

Definition at line 203 of file publictypes.h.

203  {
204  return pageseg_mode >= PSM_AUTO_OSD && pageseg_mode <= PSM_SINGLE_COLUMN;
205 }

◆ PSM_COL_FIND_ENABLED()

bool tesseract::PSM_COL_FIND_ENABLED ( int  pageseg_mode)
inline

Definition at line 197 of file publictypes.h.

197  {
198  return pageseg_mode >= PSM_AUTO_OSD && pageseg_mode <= PSM_AUTO;
199 }
Definition: capi.h:89

◆ PSM_LINE_FIND_ENABLED()

bool tesseract::PSM_LINE_FIND_ENABLED ( int  pageseg_mode)
inline

Definition at line 206 of file publictypes.h.

206  {
207  return pageseg_mode >= PSM_AUTO_OSD && pageseg_mode <= PSM_SINGLE_BLOCK;
208 }

◆ PSM_ORIENTATION_ENABLED()

bool tesseract::PSM_ORIENTATION_ENABLED ( int  pageseg_mode)
inline

Definition at line 194 of file publictypes.h.

194  {
195  return pageseg_mode <= PSM_AUTO || pageseg_mode == PSM_SPARSE_TEXT_OSD;
196 }
Definition: capi.h:89

◆ PSM_OSD_ENABLED()

bool tesseract::PSM_OSD_ENABLED ( int  pageseg_mode)
inline

Inline functions that act on a PageSegMode to determine whether components of layout analysis are enabled. Depend critically on the order of elements of PageSegMode. NOTE that arg is an int for compatibility with INT_PARAM.

Definition at line 191 of file publictypes.h.

191  {
192  return pageseg_mode <= PSM_AUTO_OSD || pageseg_mode == PSM_SPARSE_TEXT_OSD;
193 }

◆ PSM_SPARSE()

bool tesseract::PSM_SPARSE ( int  pageseg_mode)
inline

Definition at line 200 of file publictypes.h.

200  {
201  return pageseg_mode == PSM_SPARSE_TEXT || pageseg_mode == PSM_SPARSE_TEXT_OSD;
202 }

◆ PSM_WORD_FIND_ENABLED()

bool tesseract::PSM_WORD_FIND_ENABLED ( int  pageseg_mode)
inline

Definition at line 209 of file publictypes.h.

209  {
210  return (pageseg_mode >= PSM_AUTO_OSD && pageseg_mode <= PSM_SINGLE_LINE) ||
211  pageseg_mode == PSM_SPARSE_TEXT || pageseg_mode == PSM_SPARSE_TEXT_OSD;
212 }

◆ read_info()

bool tesseract::read_info ( TFile f,
FontInfo fi 
)

Definition at line 152 of file fontinfo.cpp.

152  {
153  inT32 size;
154  if (f->FReadEndian(&size, sizeof(size), 1) != 1) return false;
155  char* font_name = new char[size + 1];
156  fi->name = font_name;
157  if (f->FRead(font_name, sizeof(*font_name), size) != size) return false;
158  font_name[size] = '\0';
159  if (f->FReadEndian(&fi->properties, sizeof(fi->properties), 1) != 1)
160  return false;
161  return true;
162 }
int32_t inT32
Definition: host.h:38

◆ read_set()

bool tesseract::read_set ( TFile f,
FontSet fs 
)

Definition at line 230 of file fontinfo.cpp.

230  {
231  if (f->FReadEndian(&fs->size, sizeof(fs->size), 1) != 1) return false;
232  fs->configs = new int[fs->size];
233  if (f->FReadEndian(fs->configs, sizeof(fs->configs[0]), fs->size) != fs->size)
234  return false;
235  return true;
236 }

◆ read_spacing_info()

bool tesseract::read_spacing_info ( TFile f,
FontInfo fi 
)

Definition at line 173 of file fontinfo.cpp.

173  {
174  inT32 vec_size, kern_size;
175  if (f->FReadEndian(&vec_size, sizeof(vec_size), 1) != 1) return false;
176  ASSERT_HOST(vec_size >= 0);
177  if (vec_size == 0) return true;
178  fi->init_spacing(vec_size);
179  for (int i = 0; i < vec_size; ++i) {
180  FontSpacingInfo *fs = new FontSpacingInfo();
181  if (f->FReadEndian(&fs->x_gap_before, sizeof(fs->x_gap_before), 1) != 1 ||
182  f->FReadEndian(&fs->x_gap_after, sizeof(fs->x_gap_after), 1) != 1 ||
183  f->FReadEndian(&kern_size, sizeof(kern_size), 1) != 1) {
184  delete fs;
185  return false;
186  }
187  if (kern_size < 0) { // indication of a NULL entry in fi->spacing_vec
188  delete fs;
189  continue;
190  }
191  if (kern_size > 0 && (!fs->kerned_unichar_ids.DeSerialize(f) ||
192  !fs->kerned_x_gaps.DeSerialize(f))) {
193  delete fs;
194  return false;
195  }
196  fi->add_spacing(i, fs);
197  }
198  return true;
199 }
int32_t inT32
Definition: host.h:38
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ read_t()

bool tesseract::read_t ( PAGE_RES_IT page_res_it,
TBOX tbox 
)

Definition at line 53 of file recogtraining.cpp.

53  {
54  while (page_res_it->block() != NULL && page_res_it->word() == NULL)
55  page_res_it->forward();
56 
57  if (page_res_it->word() != NULL) {
58  *tbox = page_res_it->word()->word->bounding_box();
59 
60  // If tbox->left() is negative, the training image has vertical text and
61  // all the coordinates of bounding boxes of page_res are rotated by 90
62  // degrees in a counterclockwise direction. We need to rotate the TBOX back
63  // in order to compare with the TBOXes of box files.
64  if (tbox->left() < 0) {
65  tbox->rotate(FCOORD(0.0, -1.0));
66  }
67 
68  return true;
69  } else {
70  return false;
71  }
72 }
Definition: points.h:189
WERD_RES * word() const
Definition: pageres.h:736
WERD * word
Definition: pageres.h:175
inT16 left() const
Definition: rect.h:68
WERD_RES * forward()
Definition: pageres.h:716
void rotate(const FCOORD &vec)
Definition: rect.h:189
BLOCK_RES * block() const
Definition: pageres.h:742
TBOX bounding_box() const
Definition: werd.cpp:160

◆ ReadFile()

STRING tesseract::ReadFile ( const string &  filename,
FileReader  reader 
)

Definition at line 57 of file lang_model_helpers.cpp.

57  {
58  if (filename.empty()) return STRING();
60  bool read_result;
61  if (reader == nullptr)
62  read_result = LoadDataFromFile(filename.c_str(), &data);
63  else
64  read_result = (*reader)(filename.c_str(), &data);
65  if (read_result) return STRING(&data[0], data.size());
66  tprintf("Failed to read data from: %s\n", filename.c_str());
67  return STRING();
68 }
int size() const
Definition: genericvector.h:72
#define tprintf(...)
Definition: tprintf.h:31
Definition: strngs.h:45
bool LoadDataFromFile(const char *filename, GenericVector< char > *data)

◆ ReCachePagesFunc()

void* tesseract::ReCachePagesFunc ( void *  data)

Definition at line 370 of file imagedata.cpp.

370  {
371  DocumentData* document_data = static_cast<DocumentData*>(data);
372  document_data->ReCachePages();
373  return NULL;
374 }

◆ RecomputeMarginsAndClearHypotheses()

void tesseract::RecomputeMarginsAndClearHypotheses ( GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
int  percentile 
)

Definition at line 1559 of file paragraphs.cpp.

1561  {
1562  if (!AcceptableRowArgs(0, 0, __func__, rows, start, end))
1563  return;
1564 
1565  int lmin, lmax, rmin, rmax;
1566  lmin = lmax = (*rows)[start].lmargin_ + (*rows)[start].lindent_;
1567  rmin = rmax = (*rows)[start].rmargin_ + (*rows)[start].rindent_;
1568  for (int i = start; i < end; i++) {
1569  RowScratchRegisters &sr = (*rows)[i];
1570  sr.SetUnknown();
1571  if (sr.ri_->num_words == 0)
1572  continue;
1573  UpdateRange(sr.lmargin_ + sr.lindent_, &lmin, &lmax);
1574  UpdateRange(sr.rmargin_ + sr.rindent_, &rmin, &rmax);
1575  }
1576  STATS lefts(lmin, lmax + 1);
1577  STATS rights(rmin, rmax + 1);
1578  for (int i = start; i < end; i++) {
1579  RowScratchRegisters &sr = (*rows)[i];
1580  if (sr.ri_->num_words == 0)
1581  continue;
1582  lefts.add(sr.lmargin_ + sr.lindent_, 1);
1583  rights.add(sr.rmargin_ + sr.rindent_, 1);
1584  }
1585  int ignorable_left = lefts.ile(ClipToRange(percentile, 0, 100) / 100.0);
1586  int ignorable_right = rights.ile(ClipToRange(percentile, 0, 100) / 100.0);
1587  for (int i = start; i < end; i++) {
1588  RowScratchRegisters &sr = (*rows)[i];
1589  int ldelta = ignorable_left - sr.lmargin_;
1590  sr.lmargin_ += ldelta;
1591  sr.lindent_ -= ldelta;
1592  int rdelta = ignorable_right - sr.rmargin_;
1593  sr.rmargin_ += rdelta;
1594  sr.rindent_ -= rdelta;
1595  }
1596 }
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:132
Definition: statistc.h:33

◆ RightWordAttributes()

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 442 of file paragraphs.cpp.

444  {
445  *is_list = false;
446  *starts_idea = false;
447  *ends_idea = false;
448  if (utf8.size() == 0 || (werd != NULL && werd->length() == 0)) { // Empty
449  *ends_idea = true;
450  return;
451  }
452 
453  if (unicharset && werd) { // We have a proper werd and unicharset so use it.
454  if (UniLikelyListItem(unicharset, werd)) {
455  *is_list = true;
456  *starts_idea = true;
457  }
458  UNICHAR_ID last_letter = werd->unichar_id(werd->length() - 1);
459  if (unicharset->get_ispunctuation(last_letter)) {
460  *ends_idea = true;
461  }
462  } else { // Assume utf8 is mostly ASCII
463  if (AsciiLikelyListItem(utf8)) {
464  *is_list = true;
465  *starts_idea = true;
466  }
467  int last_letter = utf8[utf8.size() - 1];
468  if (IsOpeningPunct(last_letter) || IsTerminalPunct(last_letter)) {
469  *ends_idea = true;
470  }
471  }
472 }
inT32 size() const
Definition: strngs.h:69
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:518
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:311
bool AsciiLikelyListItem(const STRING &word)
Definition: paragraphs.cpp:268
bool IsTerminalPunct(int ch)
Definition: paragraphs.cpp:206
int length() const
Definition: ratngs.h:299
bool UniLikelyListItem(const UNICHARSET *u, const WERD_CHOICE *werd)
Definition: paragraphs.cpp:358
bool IsOpeningPunct(int ch)
Definition: paragraphs.cpp:202
int UNICHAR_ID
Definition: unichar.h:35

◆ RowIsStranded()

bool tesseract::RowIsStranded ( const GenericVector< RowScratchRegisters > &  rows,
int  row 
)

Definition at line 2141 of file paragraphs.cpp.

2141  {
2142  SetOfModels row_models;
2143  rows[row].StrongHypotheses(&row_models);
2144 
2145  for (int m = 0; m < row_models.size(); m++) {
2146  bool all_starts = rows[row].GetLineType();
2147  int run_length = 1;
2148  bool continues = true;
2149  for (int i = row - 1; i >= 0 && continues; i--) {
2150  SetOfModels models;
2151  rows[i].NonNullHypotheses(&models);
2152  switch (rows[i].GetLineType(row_models[m])) {
2153  case LT_START: run_length++; break;
2154  case LT_MULTIPLE: // explicit fall-through
2155  case LT_BODY: run_length++; all_starts = false; break;
2156  case LT_UNKNOWN: // explicit fall-through
2157  default: continues = false;
2158  }
2159  }
2160  continues = true;
2161  for (int i = row + 1; i < rows.size() && continues; i++) {
2162  SetOfModels models;
2163  rows[i].NonNullHypotheses(&models);
2164  switch (rows[i].GetLineType(row_models[m])) {
2165  case LT_START: run_length++; break;
2166  case LT_MULTIPLE: // explicit fall-through
2167  case LT_BODY: run_length++; all_starts = false; break;
2168  case LT_UNKNOWN: // explicit fall-through
2169  default: continues = false;
2170  }
2171  }
2172  if (run_length > 2 || (!all_starts && run_length > 1)) return false;
2173  }
2174  return true;
2175 }
int size() const
Definition: genericvector.h:72
GenericVectorEqEq< const ParagraphModel * > SetOfModels

◆ RowsFitModel()

bool tesseract::RowsFitModel ( const GenericVector< RowScratchRegisters > *  rows,
int  start,
int  end,
const ParagraphModel model 
)

Definition at line 1809 of file paragraphs.cpp.

1810  {
1811  if (!AcceptableRowArgs(0, 1, __func__, rows, start, end))
1812  return false;
1813  if (!ValidFirstLine(rows, start, model)) return false;
1814  for (int i = start + 1 ; i < end; i++) {
1815  if (!ValidBodyLine(rows, i, model)) return false;
1816  }
1817  return true;
1818 }
bool ValidBodyLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)
bool ValidFirstLine(const GenericVector< RowScratchRegisters > *rows, int row, const ParagraphModel *model)

◆ RtlEmbed()

STRING tesseract::RtlEmbed ( const STRING word,
bool  rtlify 
)

Definition at line 122 of file paragraphs.cpp.

122  {
123  if (rtlify)
124  return STRING(kRLE) + word + STRING(kPDF);
125  return word;
126 }
const char * kRLE
Definition: unicodes.cpp:29
Definition: strngs.h:45
const char * kPDF
Definition: unicodes.cpp:30

◆ SafeAtod()

bool tesseract::SafeAtod ( const char *  str,
double *  val 
)

Definition at line 105 of file commandlineflags.cpp.

105  {
106  char* endptr = nullptr;
107  *val = strtod(str, &endptr);
108  return endptr != nullptr && *endptr == '\0';
109 }

◆ SafeAtoi()

bool tesseract::SafeAtoi ( const char *  str,
int *  val 
)

Definition at line 99 of file commandlineflags.cpp.

99  {
100  char* endptr = nullptr;
101  *val = strtol(str, &endptr, 10);
102  return endptr != nullptr && *endptr == '\0';
103 }

◆ SaveDataToFile()

bool tesseract::SaveDataToFile ( const GenericVector< char > &  data,
const STRING filename 
)
inline

Definition at line 392 of file genericvector.h.

393  {
394  FILE* fp = fopen(filename.string(), "wb");
395  if (fp == NULL) return false;
396  bool result =
397  static_cast<int>(fwrite(&data[0], 1, data.size(), fp)) == data.size();
398  fclose(fp);
399  return result;
400 }
int size() const
Definition: genericvector.h:72
const char * string() const
Definition: strngs.cpp:198

◆ ScriptPosToString()

const char * tesseract::ScriptPosToString ( enum ScriptPos  script_pos)

Definition at line 181 of file ratngs.cpp.

181  {
182  switch (script_pos) {
183  case SP_NORMAL: return "NORM";
184  case SP_SUBSCRIPT: return "SUB";
185  case SP_SUPERSCRIPT: return "SUPER";
186  case SP_DROPCAP: return "DROPC";
187  }
188  return "SP_UNKNOWN";
189 }

◆ SeparateSimpleLeaderLines()

void tesseract::SeparateSimpleLeaderLines ( GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory theory 
)

Definition at line 2026 of file paragraphs.cpp.

2028  {
2029  for (int i = row_start + 1; i < row_end - 1; i++) {
2030  if ((*rows)[i - 1].ri_->has_leaders &&
2031  (*rows)[i].ri_->has_leaders &&
2032  (*rows)[i + 1].ri_->has_leaders) {
2033  const ParagraphModel *model = theory->AddModel(
2034  ParagraphModel(JUSTIFICATION_UNKNOWN, 0, 0, 0, 0));
2035  (*rows)[i].AddStartLine(model);
2036  }
2037  }
2038 }

◆ SetBlobStrokeWidth()

void tesseract::SetBlobStrokeWidth ( Pix *  pix,
BLOBNBOX blob 
)

Definition at line 55 of file tordmain.cpp.

55  {
56  // Cut the blob rectangle into a Pix.
57  int pix_height = pixGetHeight(pix);
58  const TBOX& box = blob->bounding_box();
59  int width = box.width();
60  int height = box.height();
61  Box* blob_pix_box = boxCreate(box.left(), pix_height - box.top(),
62  width, height);
63  Pix* pix_blob = pixClipRectangle(pix, blob_pix_box, NULL);
64  boxDestroy(&blob_pix_box);
65  Pix* dist_pix = pixDistanceFunction(pix_blob, 4, 8, L_BOUNDARY_BG);
66  pixDestroy(&pix_blob);
67  // Compute the stroke widths.
68  uinT32* data = pixGetData(dist_pix);
69  int wpl = pixGetWpl(dist_pix);
70  // Horizontal width of stroke.
71  STATS h_stats(0, width + 1);
72  for (int y = 0; y < height; ++y) {
73  uinT32* pixels = data + y*wpl;
74  int prev_pixel = 0;
75  int pixel = GET_DATA_BYTE(pixels, 0);
76  for (int x = 1; x < width; ++x) {
77  int next_pixel = GET_DATA_BYTE(pixels, x);
78  // We are looking for a pixel that is equal to its vertical neighbours,
79  // yet greater than its left neighbour.
80  if (prev_pixel < pixel &&
81  (y == 0 || pixel == GET_DATA_BYTE(pixels - wpl, x - 1)) &&
82  (y == height - 1 || pixel == GET_DATA_BYTE(pixels + wpl, x - 1))) {
83  if (pixel > next_pixel) {
84  // Single local max, so an odd width.
85  h_stats.add(pixel * 2 - 1, 1);
86  } else if (pixel == next_pixel && x + 1 < width &&
87  pixel > GET_DATA_BYTE(pixels, x + 1)) {
88  // Double local max, so an even width.
89  h_stats.add(pixel * 2, 1);
90  }
91  }
92  prev_pixel = pixel;
93  pixel = next_pixel;
94  }
95  }
96  // Vertical width of stroke.
97  STATS v_stats(0, height + 1);
98  for (int x = 0; x < width; ++x) {
99  int prev_pixel = 0;
100  int pixel = GET_DATA_BYTE(data, x);
101  for (int y = 1; y < height; ++y) {
102  uinT32* pixels = data + y*wpl;
103  int next_pixel = GET_DATA_BYTE(pixels, x);
104  // We are looking for a pixel that is equal to its horizontal neighbours,
105  // yet greater than its upper neighbour.
106  if (prev_pixel < pixel &&
107  (x == 0 || pixel == GET_DATA_BYTE(pixels - wpl, x - 1)) &&
108  (x == width - 1 || pixel == GET_DATA_BYTE(pixels - wpl, x + 1))) {
109  if (pixel > next_pixel) {
110  // Single local max, so an odd width.
111  v_stats.add(pixel * 2 - 1, 1);
112  } else if (pixel == next_pixel && y + 1 < height &&
113  pixel > GET_DATA_BYTE(pixels + wpl, x)) {
114  // Double local max, so an even width.
115  v_stats.add(pixel * 2, 1);
116  }
117  }
118  prev_pixel = pixel;
119  pixel = next_pixel;
120  }
121  }
122  pixDestroy(&dist_pix);
123  // Store the horizontal and vertical width in the blob, keeping both
124  // widths if there is enough information, otherwse only the one with
125  // the most samples.
126  // If there are insufficent samples, store zero, rather than using
127  // 2*area/perimeter, as the numbers that gives do not match the numbers
128  // from the distance method.
129  if (h_stats.get_total() >= (width + height) / 4) {
130  blob->set_horz_stroke_width(h_stats.ile(0.5f));
131  if (v_stats.get_total() >= (width + height) / 4)
132  blob->set_vert_stroke_width(v_stats.ile(0.5f));
133  else
134  blob->set_vert_stroke_width(0.0f);
135  } else {
136  if (v_stats.get_total() >= (width + height) / 4 ||
137  v_stats.get_total() > h_stats.get_total()) {
138  blob->set_horz_stroke_width(0.0f);
139  blob->set_vert_stroke_width(v_stats.ile(0.5f));
140  } else {
141  blob->set_horz_stroke_width(h_stats.get_total() > 2 ? h_stats.ile(0.5f)
142  : 0.0f);
143  blob->set_vert_stroke_width(0.0f);
144  }
145  }
146 }
uint32_t uinT32
Definition: host.h:39
const TBOX & bounding_box() const
Definition: blobbox.h:215
inT16 top() const
Definition: rect.h:54
inT16 height() const
Definition: rect.h:104
Definition: rect.h:30
inT16 left() const
Definition: rect.h:68
void set_horz_stroke_width(float width)
Definition: blobbox.h:325
Definition: statistc.h:33
void set_vert_stroke_width(float width)
Definition: blobbox.h:331
inT16 width() const
Definition: rect.h:111

◆ SetBoolFlagValue()

void tesseract::SetBoolFlagValue ( const char *  flag_name,
const bool  new_val 
)

Definition at line 79 of file commandlineflags.cpp.

79  {
80  STRING full_flag_name("FLAGS_");
81  full_flag_name += flag_name;
83  BoolParam *p = ParamUtils::FindParam<BoolParam>(
84  full_flag_name.string(), GlobalParams()->bool_params, empty);
85  ASSERT_HOST(p != nullptr);
86  p->set_value(new_val);
87 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< BoolParam * > bool_params
Definition: params.h:45
Definition: strngs.h:45
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ SetDoubleFlagValue()

void tesseract::SetDoubleFlagValue ( const char *  flag_name,
const double  new_val 
)

Definition at line 69 of file commandlineflags.cpp.

69  {
70  STRING full_flag_name("FLAGS_");
71  full_flag_name += flag_name;
73  DoubleParam *p = ParamUtils::FindParam<DoubleParam>(
74  full_flag_name.string(), GlobalParams()->double_params, empty);
75  ASSERT_HOST(p != nullptr);
76  p->set_value(new_val);
77 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< DoubleParam * > double_params
Definition: params.h:47
Definition: strngs.h:45
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ SetIntFlagValue()

void tesseract::SetIntFlagValue ( const char *  flag_name,
const inT32  new_val 
)

Definition at line 59 of file commandlineflags.cpp.

59  {
60  STRING full_flag_name("FLAGS_");
61  full_flag_name += flag_name;
63  IntParam *p = ParamUtils::FindParam<IntParam>(
64  full_flag_name.string(), GlobalParams()->int_params, empty);
65  ASSERT_HOST(p != nullptr);
66  p->set_value(new_val);
67 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
GenericVector< IntParam * > int_params
Definition: params.h:44
Definition: strngs.h:45
#define ASSERT_HOST(x)
Definition: errcode.h:84

◆ SetPropertiesForInputFile()

void tesseract::SetPropertiesForInputFile ( const string &  script_dir,
const string &  input_unicharset_file,
const string &  output_unicharset_file,
const string &  output_xheights_file 
)

Definition at line 183 of file unicharset_training_utils.cpp.

186  {
187  UNICHARSET unicharset;
188 
189  // Load the input unicharset
190  unicharset.load_from_file(input_unicharset_file.c_str());
191  tprintf("Loaded unicharset of size %d from file %s\n", unicharset.size(),
192  input_unicharset_file.c_str());
193 
194  // Set unichar properties
195  tprintf("Setting unichar properties\n");
196  SetupBasicProperties(true, false, &unicharset);
197  tprintf("Setting script properties\n");
198  SetScriptProperties(script_dir, &unicharset);
199  if (!output_xheights_file.empty()) {
200  string xheights_str = GetXheightString(script_dir, unicharset);
201  File::WriteStringToFileOrDie(xheights_str, output_xheights_file);
202  }
203 
204  // Write the output unicharset
205  tprintf("Writing unicharset to file %s\n", output_unicharset_file.c_str());
206  unicharset.save_to_file(output_unicharset_file.c_str());
207 }
void SetScriptProperties(const string &script_dir, UNICHARSET *unicharset)
void SetupBasicProperties(bool report_errors, bool decompose, UNICHARSET *unicharset)
#define tprintf(...)
Definition: tprintf.h:31
bool save_to_file(const char *const filename) const
Definition: unicharset.h:347
int size() const
Definition: unicharset.h:338
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:387
string GetXheightString(const string &script_dir, const UNICHARSET &unicharset)

◆ SetScriptProperties()

void tesseract::SetScriptProperties ( const string &  script_dir,
UNICHARSET unicharset 
)

Definition at line 143 of file unicharset_training_utils.cpp.

143  {
144  for (int s = 0; s < unicharset->get_script_table_size(); ++s) {
145  // Load the unicharset for the script if available.
146  string filename = script_dir + "/" +
147  unicharset->get_script_from_script_id(s) + ".unicharset";
148  UNICHARSET script_set;
149  if (script_set.load_from_file(filename.c_str())) {
150  unicharset->SetPropertiesFromOther(script_set);
151  } else if (s != unicharset->common_sid() && s != unicharset->null_sid()) {
152  tprintf("Failed to load script unicharset from:%s\n", filename.c_str());
153  }
154  }
155  for (int c = SPECIAL_UNICHAR_CODES_COUNT; c < unicharset->size(); ++c) {
156  if (unicharset->PropertiesIncomplete(c)) {
157  tprintf("Warning: properties incomplete for index %d = %s\n", c,
158  unicharset->id_to_unichar(c));
159  }
160  }
161 }
void SetPropertiesFromOther(const UNICHARSET &src)
Definition: unicharset.h:544
const char * get_script_from_script_id(int id) const
Definition: unicharset.h:853
#define tprintf(...)
Definition: tprintf.h:31
int common_sid() const
Definition: unicharset.h:883
int size() const
Definition: unicharset.h:338
bool PropertiesIncomplete(UNICHAR_ID unichar_id) const
Definition: unicharset.h:645
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:387
int get_script_table_size() const
Definition: unicharset.h:848
int null_sid() const
Definition: unicharset.h:882
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:288

◆ SetStringFlagValue()

void tesseract::SetStringFlagValue ( const char *  flag_name,
const char *  new_val 
)

Definition at line 89 of file commandlineflags.cpp.

89  {
90  STRING full_flag_name("FLAGS_");
91  full_flag_name += flag_name;
93  StringParam *p = ParamUtils::FindParam<StringParam>(
94  full_flag_name.string(), GlobalParams()->string_params, empty);
95  ASSERT_HOST(p != nullptr);
96  p->set_value(STRING(new_val));
97 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
Definition: strngs.h:45
#define ASSERT_HOST(x)
Definition: errcode.h:84
GenericVector< StringParam * > string_params
Definition: params.h:46

◆ SetupBasicProperties() [1/2]

void tesseract::SetupBasicProperties ( bool  report_errors,
UNICHARSET unicharset 
)
inline

Definition at line 38 of file unicharset_training_utils.h.

38  {
39  SetupBasicProperties(report_errors, false, unicharset);
40 }
void SetupBasicProperties(bool report_errors, UNICHARSET *unicharset)

◆ SetupBasicProperties() [2/2]

void tesseract::SetupBasicProperties ( bool  report_errors,
bool  decompose,
UNICHARSET unicharset 
)

Definition at line 40 of file unicharset_training_utils.cpp.

41  {
42  for (int unichar_id = 0; unichar_id < unicharset->size(); ++unichar_id) {
43  // Convert any custom ligatures.
44  const char* unichar_str = unicharset->id_to_unichar(unichar_id);
45  for (int i = 0; UNICHARSET::kCustomLigatures[i][0] != nullptr; ++i) {
46  if (!strcmp(UNICHARSET::kCustomLigatures[i][1], unichar_str)) {
47  unichar_str = UNICHARSET::kCustomLigatures[i][0];
48  break;
49  }
50  }
51 
52  // Convert the unichar to UTF32 representation
53  std::vector<char32> uni_vector = UNICHAR::UTF8ToUTF32(unichar_str);
54 
55  // Assume that if the property is true for any character in the string,
56  // then it holds for the whole "character".
57  bool unichar_isalpha = false;
58  bool unichar_islower = false;
59  bool unichar_isupper = false;
60  bool unichar_isdigit = false;
61  bool unichar_ispunct = false;
62 
63  for (char32 u_ch : uni_vector) {
64  if (u_isalpha(u_ch)) unichar_isalpha = true;
65  if (u_islower(u_ch)) unichar_islower = true;
66  if (u_isupper(u_ch)) unichar_isupper = true;
67  if (u_isdigit(u_ch)) unichar_isdigit = true;
68  if (u_ispunct(u_ch)) unichar_ispunct = true;
69  }
70 
71  unicharset->set_isalpha(unichar_id, unichar_isalpha);
72  unicharset->set_islower(unichar_id, unichar_islower);
73  unicharset->set_isupper(unichar_id, unichar_isupper);
74  unicharset->set_isdigit(unichar_id, unichar_isdigit);
75  unicharset->set_ispunctuation(unichar_id, unichar_ispunct);
76 
78  unicharset->set_script(unichar_id, uscript_getName(
79  uscript_getScript(uni_vector[0], err)));
80 
81  const int num_code_points = uni_vector.size();
82  // Obtain the lower/upper case if needed and record it in the properties.
83  unicharset->set_other_case(unichar_id, unichar_id);
84  if (unichar_islower || unichar_isupper) {
85  std::vector<char32> other_case(num_code_points, 0);
86  for (int i = 0; i < num_code_points; ++i) {
87  // TODO(daria): Ideally u_strToLower()/ustrToUpper() should be used.
88  // However since they deal with UChars (so need a conversion function
89  // from char32 or UTF8string) and require a meaningful locale string,
90  // for now u_tolower()/u_toupper() are used.
91  other_case[i] = unichar_islower ? u_toupper(uni_vector[i]) :
92  u_tolower(uni_vector[i]);
93  }
94  string other_case_uch = UNICHAR::UTF32ToUTF8(other_case);
95  UNICHAR_ID other_case_id =
96  unicharset->unichar_to_id(other_case_uch.c_str());
97  if (other_case_id != INVALID_UNICHAR_ID) {
98  unicharset->set_other_case(unichar_id, other_case_id);
99  } else if (unichar_id >= SPECIAL_UNICHAR_CODES_COUNT && report_errors) {
100  tprintf("Other case %s of %s is not in unicharset\n",
101  other_case_uch.c_str(), unichar_str);
102  }
103  }
104 
105  // Set RTL property and obtain mirror unichar ID from ICU.
106  std::vector<char32> mirrors(num_code_points, 0);
107  for (int i = 0; i < num_code_points; ++i) {
108  mirrors[i] = u_charMirror(uni_vector[i]);
109  if (i == 0) { // set directionality to that of the 1st code point
110  unicharset->set_direction(unichar_id,
111  static_cast<UNICHARSET::Direction>(
112  u_charDirection(uni_vector[i])));
113  }
114  }
115  string mirror_uch = UNICHAR::UTF32ToUTF8(mirrors);
116  UNICHAR_ID mirror_uch_id = unicharset->unichar_to_id(mirror_uch.c_str());
117  if (mirror_uch_id != INVALID_UNICHAR_ID) {
118  unicharset->set_mirror(unichar_id, mirror_uch_id);
119  } else if (report_errors) {
120  tprintf("Mirror %s of %s is not in unicharset\n",
121  mirror_uch.c_str(), unichar_str);
122  }
123 
124  // Record normalized version of this unichar.
125  string normed_str;
126  if (unichar_id != 0 &&
131  unichar_str, &normed_str) &&
132  !normed_str.empty()) {
133  unicharset->set_normed(unichar_id, normed_str.c_str());
134  } else {
135  unicharset->set_normed(unichar_id, unichar_str);
136  }
137  ASSERT_HOST(unicharset->get_other_case(unichar_id) < unicharset->size());
138  }
139  unicharset->post_load_setup();
140 }
void set_ispunctuation(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:450
void set_islower(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:435
void set_normed(UNICHAR_ID unichar_id, const char *normed)
Definition: unicharset.h:481
void set_direction(UNICHAR_ID unichar_id, UNICHARSET::Direction value)
Definition: unicharset.h:471
void set_isdigit(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:445
bool NormalizeUTF8String(UnicodeNormMode u_mode, OCRNorm ocr_normalize, GraphemeNorm grapheme_normalize, const char *str8, string *normalized)
Definition: normstrngs.cpp:147
#define tprintf(...)
Definition: tprintf.h:31
signed int char32
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
Definition: unicharset.h:682
int size() const
Definition: unicharset.h:338
void set_isupper(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:440
void set_mirror(UNICHAR_ID unichar_id, UNICHAR_ID mirror)
Definition: unicharset.h:476
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:207
void post_load_setup()
Definition: unicharset.cpp:894
#define ASSERT_HOST(x)
Definition: errcode.h:84
static TESS_API const char * kCustomLigatures[][2]
Definition: unicharset.h:151
void set_script(UNICHAR_ID unichar_id, const char *value)
Definition: unicharset.h:461
void set_isalpha(UNICHAR_ID unichar_id, bool value)
Definition: unicharset.h:430
void set_other_case(UNICHAR_ID unichar_id, UNICHAR_ID other_case)
Definition: unicharset.h:466
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:288
int UNICHAR_ID
Definition: unichar.h:35

◆ SkipChars() [1/2]

const char* tesseract::SkipChars ( const char *  str,
const char *  toskip 
)

Definition at line 211 of file paragraphs.cpp.

211  {
212  while (*str != '\0' && strchr(toskip, *str)) { str++; }
213  return str;
214 }

◆ SkipChars() [2/2]

const char* tesseract::SkipChars ( const char *  str,
bool(*)(int)  skip 
)

Definition at line 216 of file paragraphs.cpp.

216  {
217  while (*str != '\0' && skip(*str)) { str++; }
218  return str;
219 }

◆ SkipOne()

const char* tesseract::SkipOne ( const char *  str,
const char *  toskip 
)

Definition at line 221 of file paragraphs.cpp.

221  {
222  if (*str != '\0' && strchr(toskip, *str)) return str + 1;
223  return str;
224 }

◆ SoftmaxInPlace()

template<typename T >
void tesseract::SoftmaxInPlace ( int  n,
T *  inout 
)
inline

Definition at line 163 of file functions.h.

163  {
164  if (n <= 0) return;
165  // A limit on the negative range input to exp to guarantee non-zero output.
166  const T kMaxSoftmaxActivation = 86.0f;
167 
168  T max_output = inout[0];
169  for (int i = 1; i < n; i++) {
170  T output = inout[i];
171  if (output > max_output) max_output = output;
172  }
173  T prob_total = 0.0;
174  for (int i = 0; i < n; i++) {
175  T prob = inout[i] - max_output;
176  prob = exp(ClipToRange(prob, -kMaxSoftmaxActivation, static_cast<T>(0)));
177  prob_total += prob;
178  inout[i] = prob;
179  }
180  if (prob_total > 0.0) {
181  for (int i = 0; i < n; i++) inout[i] /= prob_total;
182  }
183 }
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:122

◆ sort_cmp()

template<typename T >
int tesseract::sort_cmp ( const void *  t1,
const void *  t2 
)

Definition at line 423 of file genericvector.h.

423  {
424  const T* a = static_cast<const T *> (t1);
425  const T* b = static_cast<const T *> (t2);
426  if (*a < *b) {
427  return -1;
428  } else if (*b < *a) {
429  return 1;
430  } else {
431  return 0;
432  }
433 }

◆ sort_ptr_cmp()

template<typename T >
int tesseract::sort_ptr_cmp ( const void *  t1,
const void *  t2 
)

Definition at line 440 of file genericvector.h.

440  {
441  const T* a = *static_cast<T* const*>(t1);
442  const T* b = *static_cast<T* const*>(t2);
443  if (*a < *b) {
444  return -1;
445  } else if (*b < *a) {
446  return 1;
447  } else {
448  return 0;
449  }
450 }

◆ SortByBoxBottom()

template<class BBC >
int tesseract::SortByBoxBottom ( const void *  void1,
const void *  void2 
)

Definition at line 409 of file bbgrid.h.

409  {
410  // The void*s are actually doubly indirected, so get rid of one level.
411  const BBC* p1 = *static_cast<const BBC* const*>(void1);
412  const BBC* p2 = *static_cast<const BBC* const*>(void2);
413  int result = p1->bounding_box().bottom() - p2->bounding_box().bottom();
414  if (result != 0)
415  return result;
416  result = p1->bounding_box().top() - p2->bounding_box().top();
417  if (result != 0)
418  return result;
419  result = p1->bounding_box().left() - p2->bounding_box().left();
420  if (result != 0)
421  return result;
422  return p1->bounding_box().right() - p2->bounding_box().right();
423 }

◆ SortByBoxLeft()

template<class BBC >
int tesseract::SortByBoxLeft ( const void *  void1,
const void *  void2 
)

Definition at line 373 of file bbgrid.h.

373  {
374  // The void*s are actually doubly indirected, so get rid of one level.
375  const BBC* p1 = *static_cast<const BBC* const*>(void1);
376  const BBC* p2 = *static_cast<const BBC* const*>(void2);
377  int result = p1->bounding_box().left() - p2->bounding_box().left();
378  if (result != 0)
379  return result;
380  result = p1->bounding_box().right() - p2->bounding_box().right();
381  if (result != 0)
382  return result;
383  result = p1->bounding_box().bottom() - p2->bounding_box().bottom();
384  if (result != 0)
385  return result;
386  return p1->bounding_box().top() - p2->bounding_box().top();
387 }

◆ SortByRating()

template<class BLOB_CHOICE >
int tesseract::SortByRating ( const void *  void1,
const void *  void2 
)

Definition at line 85 of file pieces.cpp.

85  {
86  const BLOB_CHOICE *p1 = *static_cast<const BLOB_CHOICE *const *>(void1);
87  const BLOB_CHOICE *p2 = *static_cast<const BLOB_CHOICE *const *>(void2);
88 
89  if (p1->rating() < p2->rating())
90  return 1;
91  return -1;
92 }
float rating() const
Definition: ratngs.h:79

◆ SortByUnicharID()

template<class BLOB_CHOICE >
int tesseract::SortByUnicharID ( const void *  void1,
const void *  void2 
)

Definition at line 77 of file pieces.cpp.

77  {
78  const BLOB_CHOICE *p1 = *static_cast<const BLOB_CHOICE *const *>(void1);
79  const BLOB_CHOICE *p2 = *static_cast<const BLOB_CHOICE *const *>(void2);
80 
81  return p1->unichar_id() - p2->unichar_id();
82 }
UNICHAR_ID unichar_id() const
Definition: ratngs.h:76

◆ SortRightToLeft()

template<class BBC >
int tesseract::SortRightToLeft ( const void *  void1,
const void *  void2 
)

Definition at line 391 of file bbgrid.h.

391  {
392  // The void*s are actually doubly indirected, so get rid of one level.
393  const BBC* p1 = *static_cast<const BBC* const*>(void1);
394  const BBC* p2 = *static_cast<const BBC* const*>(void2);
395  int result = p2->bounding_box().right() - p1->bounding_box().right();
396  if (result != 0)
397  return result;
398  result = p2->bounding_box().left() - p1->bounding_box().left();
399  if (result != 0)
400  return result;
401  result = p1->bounding_box().bottom() - p2->bounding_box().bottom();
402  if (result != 0)
403  return result;
404  return p1->bounding_box().top() - p2->bounding_box().top();
405 }

◆ SpanUTF8NotWhitespace()

unsigned int tesseract::SpanUTF8NotWhitespace ( const char *  text)

Definition at line 243 of file normstrngs.cpp.

243  {
244  int n_notwhite = 0;
245  for (UNICHAR::const_iterator it = UNICHAR::begin(text, strlen(text));
246  it != UNICHAR::end(text, strlen(text)); ++it) {
247  if (IsWhitespace(*it)) break;
248  n_notwhite += it.utf8_len();
249  }
250  return n_notwhite;
251 }
bool IsWhitespace(const char32 ch)
Definition: normstrngs.cpp:223

◆ SpanUTF8Whitespace()

unsigned int tesseract::SpanUTF8Whitespace ( const char *  text)

Definition at line 233 of file normstrngs.cpp.

233  {
234  int n_white = 0;
235  for (UNICHAR::const_iterator it = UNICHAR::begin(text, strlen(text));
236  it != UNICHAR::end(text, strlen(text)); ++it) {
237  if (!IsWhitespace(*it)) break;
238  n_white += it.utf8_len();
239  }
240  return n_white;
241 }
bool IsWhitespace(const char32 ch)
Definition: normstrngs.cpp:223

◆ StringFlagExists()

bool tesseract::StringFlagExists ( const char *  flag_name,
const char **  value 
)

Definition at line 48 of file commandlineflags.cpp.

48  {
49  STRING full_flag_name("FLAGS_");
50  full_flag_name += flag_name;
52  StringParam *p = ParamUtils::FindParam<StringParam>(
53  full_flag_name.string(), GlobalParams()->string_params, empty);
54  *value = (p != nullptr) ? p->string() : nullptr;
55  return p != nullptr;
56 }
tesseract::ParamsVectors * GlobalParams()
Definition: params.cpp:33
Definition: strngs.h:45
GenericVector< StringParam * > string_params
Definition: params.h:46

◆ StrongEvidenceClassify()

void tesseract::StrongEvidenceClassify ( int  debug_level,
GenericVector< RowScratchRegisters > *  rows,
int  row_start,
int  row_end,
ParagraphTheory theory 
)

Definition at line 1996 of file paragraphs.cpp.

1999  {
2000  if (!AcceptableRowArgs(debug_level, 2, __func__, rows, row_start, row_end))
2001  return;
2002 
2003  if (debug_level > 1) {
2004  tprintf("#############################################\n");
2005  tprintf("# StrongEvidenceClassify( rows[%d:%d) )\n", row_start, row_end);
2006  tprintf("#############################################\n");
2007  }
2008 
2009  RecomputeMarginsAndClearHypotheses(rows, row_start, row_end, 10);
2010  MarkStrongEvidence(rows, row_start, row_end);
2011 
2012  DebugDump(debug_level > 2, "Initial strong signals.", *theory, *rows);
2013 
2014  // Create paragraph models.
2015  ModelStrongEvidence(debug_level, rows, row_start, row_end, false, theory);
2016 
2017  DebugDump(debug_level > 2, "Unsmeared hypotheses.s.", *theory, *rows);
2018 
2019  // At this point, some rows are marked up as paragraphs with model numbers,
2020  // and some rows are marked up as either LT_START or LT_BODY. Now let's
2021  // smear any good paragraph hypotheses forward and backward.
2022  ParagraphModelSmearer smearer(rows, row_start, row_end, theory);
2023  smearer.Smear();
2024 }
void RecomputeMarginsAndClearHypotheses(GenericVector< RowScratchRegisters > *rows, int start, int end, int percentile)
#define tprintf(...)
Definition: tprintf.h:31
void ModelStrongEvidence(int debug_level, GenericVector< RowScratchRegisters > *rows, int row_start, int row_end, bool allow_flush_models, ParagraphTheory *theory)
void MarkStrongEvidence(GenericVector< RowScratchRegisters > *rows, int row_start, int row_end)

◆ StrongModel()

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 * kCrownLeft
Definition: paragraphs.cpp:46
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:48

◆ SumVectors()

void tesseract::SumVectors ( int  n,
const double *  v1,
const double *  v2,
const double *  v3,
const double *  v4,
const double *  v5,
double *  sum 
)
inline

Definition at line 209 of file functions.h.

211  {
212  for (int i = 0; i < n; ++i) {
213  sum[i] = v1[i] + v2[i] + v3[i] + v4[i] + v5[i];
214  }
215 }

◆ Tanh()

double tesseract::Tanh ( double  x)
inline

Definition at line 45 of file functions.h.

45  {
46  if (x < 0.0) return -Tanh(-x);
47  if (x >= (kTableSize - 1) / kScaleFactor) return 1.0;
48  x *= kScaleFactor;
49  int index = static_cast<int>(floor(x));
50  if (TanhTable[index] == 0.0 && index > 0) {
51  // Generate the entry.
52  TanhTable[index] = tanh(index / kScaleFactor);
53  }
54  if (index == kTableSize - 1) return TanhTable[kTableSize - 1];
55  if (TanhTable[index + 1] == 0.0) {
56  // Generate the entry.
57  TanhTable[index + 1] = tanh((index + 1) / kScaleFactor);
58  }
59  double offset = x - index;
60  return TanhTable[index] * (1.0 - offset) + TanhTable[index + 1] * offset;
61 }
double TanhTable[kTableSize]
Definition: functions.cpp:23
double Tanh(double x)
Definition: functions.h:45
const int kTableSize
Definition: functions.h:37
const double kScaleFactor
Definition: functions.h:39

◆ TextSupportsBreak()

bool tesseract::TextSupportsBreak ( const RowScratchRegisters before,
const RowScratchRegisters after 
)

Definition at line 1662 of file paragraphs.cpp.

1663  {
1664  if (before.ri_->ltr) {
1665  return before.ri_->rword_likely_ends_idea &&
1666  after.ri_->lword_likely_starts_idea;
1667  } else {
1668  return before.ri_->lword_likely_ends_idea &&
1669  after.ri_->rword_likely_starts_idea;
1670  }
1671 }

◆ TraceBlockOnReducedPix()

Pix * tesseract::TraceBlockOnReducedPix ( BLOCK block,
int  gridsize,
ICOORD  bleft,
int *  left,
int *  bottom 
)

Definition at line 258 of file bbgrid.cpp.

259  {
260  const 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
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
Definition: pdblock.h:59
ICOORDELT_LIST * points()
Definition: polyblk.h:42
Pix * GridReducedPix(const TBOX &box, int gridsize, ICOORD bleft, int *left, int *bottom)
Definition: bbgrid.cpp:212
Definition: rect.h:30
POLY_BLOCK * poly_block() const
Definition: pdblock.h:55
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
void setup_render(ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
Definition: points.cpp:86

◆ TraceOutlineOnReducedPix()

Pix * tesseract::TraceOutlineOnReducedPix ( C_OUTLINE outline,
int  gridsize,
ICOORD  bleft,
int *  left,
int *  bottom 
)

Definition at line 232 of file bbgrid.cpp.

233  {
234  const 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
inT32 pathlength() const
Definition: coutln.h:133
const TBOX & bounding_box() const
Definition: coutln.h:111
ICOORD step(int index) const
Definition: coutln.h:142
const ICOORD & start_pos() const
Definition: coutln.h:146
Pix * GridReducedPix(const TBOX &box, int gridsize, ICOORD bleft, int *left, int *bottom)
Definition: bbgrid.cpp:212
Definition: rect.h:30
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30

◆ UnicodeFor()

int tesseract::UnicodeFor ( const UNICHARSET u,
const WERD_CHOICE werd,
int  pos 
)

Definition at line 275 of file paragraphs.cpp.

275  {
276  if (!u || !werd || pos > werd->length())
277  return 0;
278  return UNICHAR(u->id_to_unichar(werd->unichar_id(pos)), -1).first_uni();
279 }
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:311
int length() const
Definition: ratngs.h:299
const char * id_to_unichar(UNICHAR_ID id) const
Definition: unicharset.cpp:288

◆ UniLikelyListItem()

bool tesseract::UniLikelyListItem ( const UNICHARSET u,
const WERD_CHOICE werd 
)

Definition at line 358 of file paragraphs.cpp.

358  {
359  if (werd->length() == 1 && LikelyListMarkUnicode(UnicodeFor(u, werd, 0)))
360  return true;
361 
362  UnicodeSpanSkipper m(u, werd);
363  int num_segments = 0;
364  int pos = 0;
365  while (pos < werd->length() && num_segments < 3) {
366  int numeral_start = m.SkipPunc(pos);
367  if (numeral_start > pos + 1) break;
368  int numeral_end = m.SkipRomans(numeral_start);
369  if (numeral_end == numeral_start) {
370  numeral_end = m.SkipDigits(numeral_start);
371  if (numeral_end == numeral_start) {
372  // If there's a single latin letter, we can use that.
373  numeral_end = m.SkipAlpha(numeral_start);
374  if (numeral_end - numeral_start != 1)
375  break;
376  }
377  }
378  // We got some sort of numeral.
379  num_segments++;
380  // Skip any trailing punctuation.
381  pos = m.SkipPunc(numeral_end);
382  if (pos == numeral_end)
383  break;
384  }
385  return pos == werd->length();
386 }
int UnicodeFor(const UNICHARSET *u, const WERD_CHOICE *werd, int pos)
Definition: paragraphs.cpp:275
bool LikelyListMarkUnicode(int ch)
Definition: paragraphs.cpp:329
int length() const
Definition: ratngs.h:299

◆ ValidBodyLine()

bool tesseract::ValidBodyLine ( const GenericVector< RowScratchRegisters > *  rows,
int  row,
const ParagraphModel model 
)

Definition at line 1278 of file paragraphs.cpp.

1279  {
1280  if (!StrongModel(model)) {
1281  tprintf("ValidBodyLine() should only be called with strong models!\n");
1282  }
1283  return StrongModel(model) &&
1284  model->ValidBodyLine(
1285  (*rows)[row].lmargin_, (*rows)[row].lindent_,
1286  (*rows)[row].rindent_, (*rows)[row].rmargin_);
1287 }
bool StrongModel(const ParagraphModel *model)
#define tprintf(...)
Definition: tprintf.h:31
bool ValidBodyLine(int lmargin, int lindent, int rindent, int rmargin) const
Definition: ocrpara.cpp:63

◆ ValidFirstLine()

bool tesseract::ValidFirstLine ( const GenericVector< RowScratchRegisters > *  rows,
int  row,
const ParagraphModel model 
)

Definition at line 1267 of file paragraphs.cpp.

1268  {
1269  if (!StrongModel(model)) {
1270  tprintf("ValidFirstLine() should only be called with strong models!\n");
1271  }
1272  return StrongModel(model) &&
1273  model->ValidFirstLine(
1274  (*rows)[row].lmargin_, (*rows)[row].lindent_,
1275  (*rows)[row].rindent_, (*rows)[row].rmargin_);
1276 }
bool ValidFirstLine(int lmargin, int lindent, int rindent, int rmargin) const
Definition: ocrpara.cpp:46
bool StrongModel(const ParagraphModel *model)
#define tprintf(...)
Definition: tprintf.h:31

◆ write_info()

bool tesseract::write_info ( FILE *  f,
const FontInfo fi 
)

Definition at line 164 of file fontinfo.cpp.

164  {
165  inT32 size = strlen(fi.name);
166  if (fwrite(&size, sizeof(size), 1, f) != 1) return false;
167  if (static_cast<int>(fwrite(fi.name, sizeof(*fi.name), size, f)) != size)
168  return false;
169  if (fwrite(&fi.properties, sizeof(fi.properties), 1, f) != 1) return false;
170  return true;
171 }
int32_t inT32
Definition: host.h:38

◆ write_set()

bool tesseract::write_set ( FILE *  f,
const FontSet fs 
)

Definition at line 238 of file fontinfo.cpp.

238  {
239  if (fwrite(&fs.size, sizeof(fs.size), 1, f) != 1) return false;
240  for (int i = 0; i < fs.size; ++i) {
241  if (fwrite(&fs.configs[i], sizeof(fs.configs[i]), 1, f) != 1) return false;
242  }
243  return true;
244 }

◆ write_spacing_info()

bool tesseract::write_spacing_info ( FILE *  f,
const FontInfo fi 
)

Definition at line 201 of file fontinfo.cpp.

201  {
202  inT32 vec_size = (fi.spacing_vec == NULL) ? 0 : fi.spacing_vec->size();
203  if (fwrite(&vec_size, sizeof(vec_size), 1, f) != 1) return false;
204  inT16 x_gap_invalid = -1;
205  for (int i = 0; i < vec_size; ++i) {
206  FontSpacingInfo *fs = fi.spacing_vec->get(i);
207  inT32 kern_size = (fs == NULL) ? -1 : fs->kerned_x_gaps.size();
208  if (fs == NULL) {
209  // Valid to have the identical fwrites. Writing invalid x-gaps.
210  if (fwrite(&(x_gap_invalid), sizeof(x_gap_invalid), 1, f) != 1 ||
211  fwrite(&(x_gap_invalid), sizeof(x_gap_invalid), 1, f) != 1 ||
212  fwrite(&kern_size, sizeof(kern_size), 1, f) != 1) {
213  return false;
214  }
215  } else {
216  if (fwrite(&(fs->x_gap_before), sizeof(fs->x_gap_before), 1, f) != 1 ||
217  fwrite(&(fs->x_gap_after), sizeof(fs->x_gap_after), 1, f) != 1 ||
218  fwrite(&kern_size, sizeof(kern_size), 1, f) != 1) {
219  return false;
220  }
221  }
222  if (kern_size > 0 && (!fs->kerned_unichar_ids.Serialize(f) ||
223  !fs->kerned_x_gaps.Serialize(f))) {
224  return false;
225  }
226  }
227  return true;
228 }
int16_t inT16
Definition: host.h:36
int32_t inT32
Definition: host.h:38

◆ WriteFile()

bool tesseract::WriteFile ( const string &  output_dir,
const string &  lang,
const string &  suffix,
const GenericVector< char > &  data,
FileWriter  writer 
)

Definition at line 36 of file lang_model_helpers.cpp.

38  {
39  if (lang.empty()) return true;
40  string dirname = output_dir + "/" + lang;
41  // Attempt to make the directory, but ignore errors, as it may not be a
42  // standard filesystem, and the writer will complain if not successful.
43 #if defined(_WIN32)
44  _mkdir(dirname.c_str());
45 #else
46  mkdir(dirname.c_str(), S_IRWXU | S_IRWXG);
47 #endif
48  string filename = dirname + "/" + lang + suffix;
49  if (writer == nullptr)
50  return SaveDataToFile(data, filename.c_str());
51  else
52  return (*writer)(data, filename.c_str());
53 }
bool SaveDataToFile(const GenericVector< char > &data, const STRING &filename)

◆ WriteRecoder()

bool tesseract::WriteRecoder ( const UNICHARSET unicharset,
bool  pass_through,
const string &  output_dir,
const string &  lang,
FileWriter  writer,
STRING radical_table_data,
TessdataManager traineddata 
)

Definition at line 85 of file lang_model_helpers.cpp.

88  {
89  UnicharCompress recoder;
90  // Where the unicharset is carefully setup already to contain a good
91  // compact encoding, use a pass-through recoder that does nothing.
92  // For scripts that have a large number of unicodes (Han, Hangul) we want
93  // to use the recoder to compress the symbol space by re-encoding each
94  // unicode as multiple codes from a smaller 'alphabet' that are related to the
95  // shapes in the character. Hangul Jamo is a perfect example of this.
96  // See the Hangul Syllables section, sub-section "Equivalence" in:
97  // http://www.unicode.org/versions/Unicode10.0.0/ch18.pdf
98  if (pass_through) {
99  recoder.SetupPassThrough(unicharset);
100  } else {
101  int null_char =
102  unicharset.has_special_codes() ? UNICHAR_BROKEN : unicharset.size();
103  tprintf("Null char=%d\n", null_char);
104  if (!recoder.ComputeEncoding(unicharset, null_char, radical_table_data)) {
105  tprintf("Creation of encoded unicharset failed!!\n");
106  return false;
107  }
108  }
109  TFile fp;
110  GenericVector<char> recoder_data;
111  fp.OpenWrite(&recoder_data);
112  if (!recoder.Serialize(&fp)) return false;
113  traineddata->OverwriteEntry(TESSDATA_LSTM_RECODER, &recoder_data[0],
114  recoder_data.size());
115  STRING encoding = recoder.GetEncodingAsString(unicharset);
116  recoder_data.init_to_size(encoding.length(), 0);
117  memcpy(&recoder_data[0], &encoding[0], encoding.length());
118  STRING suffix;
119  suffix.add_str_int(".charset_size=", recoder.code_range());
120  suffix += ".txt";
121  return WriteFile(output_dir, lang, suffix.string(), recoder_data, writer);
122 }
void add_str_int(const char *str, int number)
Definition: strngs.cpp:381
int size() const
Definition: genericvector.h:72
#define tprintf(...)
Definition: tprintf.h:31
int size() const
Definition: unicharset.h:338
bool has_special_codes() const
Definition: unicharset.h:721
Definition: strngs.h:45
bool WriteFile(const string &output_dir, const string &lang, const string &suffix, const GenericVector< char > &data, FileWriter writer)
void init_to_size(int size, T t)
inT32 length() const
Definition: strngs.cpp:193

◆ WriteShapeTable()

void tesseract::WriteShapeTable ( const STRING file_prefix,
const ShapeTable shape_table 
)

Definition at line 141 of file commontraining.cpp.

141  {
142  STRING shape_table_file = file_prefix;
143  shape_table_file += kShapeTableFileSuffix;
144  FILE* fp = fopen(shape_table_file.string(), "wb");
145  if (fp != nullptr) {
146  if (!shape_table.Serialize(fp)) {
147  fprintf(stderr, "Error writing shape table: %s\n",
148  shape_table_file.string());
149  }
150  fclose(fp);
151  } else {
152  fprintf(stderr, "Error creating shape table: %s\n",
153  shape_table_file.string());
154  }
155 }
bool Serialize(FILE *fp) const
Definition: shapetable.cpp:246
const char * string() const
Definition: strngs.cpp:198
Definition: strngs.h:45

◆ WriteUnicharset()

bool tesseract::WriteUnicharset ( const UNICHARSET unicharset,
const string &  output_dir,
const string &  lang,
FileWriter  writer,
TessdataManager traineddata 
)

Definition at line 71 of file lang_model_helpers.cpp.

73  {
74  GenericVector<char> unicharset_data;
75  TFile fp;
76  fp.OpenWrite(&unicharset_data);
77  if (!unicharset.save_to_file(&fp)) return false;
78  traineddata->OverwriteEntry(TESSDATA_LSTM_UNICHARSET, &unicharset_data[0],
79  unicharset_data.size());
80  return WriteFile(output_dir, lang, ".unicharset", unicharset_data, writer);
81 }
int size() const
Definition: genericvector.h:72
bool save_to_file(const char *const filename) const
Definition: unicharset.h:347
bool WriteFile(const string &output_dir, const string &lang, const string &suffix, const GenericVector< char > &data, FileWriter writer)

◆ YOutlierPieces()

void tesseract::YOutlierPieces ( WERD_RES word,
int  rebuilt_blob_index,
int  super_y_bottom,
int  sub_y_top,
ScriptPos leading_pos,
int *  num_leading_outliers,
ScriptPos trailing_pos,
int *  num_trailing_outliers 
)

Given a recognized blob, see if a contiguous collection of sub-pieces (chopped blobs) starting at its left might qualify as being a subscript or superscript letter based only on y position. Also do this for the right side.

Definition at line 46 of file superscript.cpp.

49  {
50  ScriptPos sp_unused1, sp_unused2;
51  int unused1, unused2;
52  if (!leading_pos) leading_pos = &sp_unused1;
53  if (!num_leading_outliers) num_leading_outliers = &unused1;
54  if (!trailing_pos) trailing_pos = &sp_unused2;
55  if (!num_trailing_outliers) num_trailing_outliers = &unused2;
56 
57  *num_leading_outliers = *num_trailing_outliers = 0;
58  *leading_pos = *trailing_pos = SP_NORMAL;
59 
60  int chopped_start = LeadingUnicharsToChopped(word, rebuilt_blob_index);
61  int num_chopped_pieces = word->best_state[rebuilt_blob_index];
62  ScriptPos last_pos = SP_NORMAL;
63  int trailing_outliers = 0;
64  for (int i = 0; i < num_chopped_pieces; i++) {
65  TBOX box = word->chopped_word->blobs[chopped_start + i]->bounding_box();
66  ScriptPos pos = SP_NORMAL;
67  if (box.bottom() >= super_y_bottom) {
68  pos = SP_SUPERSCRIPT;
69  } else if (box.top() <= sub_y_top) {
70  pos = SP_SUBSCRIPT;
71  }
72  if (pos == SP_NORMAL) {
73  if (trailing_outliers == i) {
74  *num_leading_outliers = trailing_outliers;
75  *leading_pos = last_pos;
76  }
77  trailing_outliers = 0;
78  } else {
79  if (pos == last_pos) {
80  trailing_outliers++;
81  } else {
82  trailing_outliers = 1;
83  }
84  }
85  last_pos = pos;
86  }
87  *num_trailing_outliers = trailing_outliers;
88  *trailing_pos = last_pos;
89 }
TWERD * chopped_word
Definition: pageres.h:201
inT16 top() const
Definition: rect.h:54
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
GenericVector< int > best_state
Definition: pageres.h:255
GenericVector< TBLOB * > blobs
Definition: blobs.h:436

◆ ZeroVector()

template<typename T >
void tesseract::ZeroVector ( int  n,
T *  vec 
)
inline

Definition at line 219 of file functions.h.

219  {
220  memset(vec, 0, n * sizeof(*vec));
221 }

Variable Documentation

◆ case_state_table

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.

◆ kAdamCorrectionIterations

const int tesseract::kAdamCorrectionIterations = 200000

Definition at line 31 of file weightmatrix.cpp.

◆ kAdamEpsilon

const double tesseract::kAdamEpsilon = 1e-8

Definition at line 33 of file weightmatrix.cpp.

◆ kAdamFlag

const int tesseract::kAdamFlag = 4

Definition at line 133 of file weightmatrix.cpp.

◆ kAdjacentLeaderSearchPadding

const int tesseract::kAdjacentLeaderSearchPadding = 2

Definition at line 120 of file tablefind.cpp.

◆ kAlignedFraction

const double tesseract::kAlignedFraction = 0.03125

Definition at line 38 of file alignedblob.cpp.

◆ kAlignedGapFraction

const double tesseract::kAlignedGapFraction = 0.75

Definition at line 42 of file alignedblob.cpp.

◆ kAlignmentNames

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

Definition at line 515 of file tabvector.cpp.

◆ kAllowBlobArea

const double tesseract::kAllowBlobArea = 0.05

Definition at line 61 of file tablefind.cpp.

◆ kAllowBlobHeight

const double tesseract::kAllowBlobHeight = 0.3

Definition at line 59 of file tablefind.cpp.

◆ kAllowBlobWidth

const double tesseract::kAllowBlobWidth = 0.4

Definition at line 60 of file tablefind.cpp.

◆ kAllowTextArea

const double tesseract::kAllowTextArea = 0.8

Definition at line 54 of file tablefind.cpp.

◆ kAllowTextHeight

const double tesseract::kAllowTextHeight = 0.5

Definition at line 52 of file tablefind.cpp.

◆ kAllowTextWidth

const double tesseract::kAllowTextWidth = 0.6

Definition at line 53 of file tablefind.cpp.

◆ kApostropheLikeUTF8

const char * tesseract::kApostropheLikeUTF8
Initial value:
= {
"'",
"`",
"\u2018",
"\u2019",
"\u2032",
NULL,
}

Definition at line 48 of file unicodes.cpp.

◆ kBestCheckpointFraction

const double tesseract::kBestCheckpointFraction = 31.0 / 32.0

Definition at line 68 of file lstmtrainer.cpp.

◆ kBigPartSizeRatio

const double tesseract::kBigPartSizeRatio = 1.75

Definition at line 47 of file colpartitiongrid.cpp.

◆ kBoxClipTolerance

const int tesseract::kBoxClipTolerance = 2

Definition at line 31 of file boxword.cpp.

◆ kBrokenCJKIterationFraction

const double tesseract::kBrokenCJKIterationFraction = 0.125

Definition at line 71 of file strokewidth.cpp.

◆ kBytesPer64BitNumber

const int tesseract::kBytesPer64BitNumber = 20

Max bytes in the decimal representation of inT64.

Definition at line 1711 of file baseapi.cpp.

◆ kBytesPerBoxFileLine

const int tesseract::kBytesPerBoxFileLine = (kBytesPerNumber + 1) * kNumbersPerBlob + 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 1709 of file baseapi.cpp.

◆ kBytesPerNumber

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

◆ kCellSplitColumnThreshold

const int tesseract::kCellSplitColumnThreshold = 0

Definition at line 40 of file tablerecog.cpp.

◆ kCellSplitRowThreshold

const int tesseract::kCellSplitRowThreshold = 0

Definition at line 39 of file tablerecog.cpp.

◆ kCertaintyScale

const float tesseract::kCertaintyScale = 7.0f

Definition at line 35 of file linerec.cpp.

◆ kCertOffset

const double tesseract::kCertOffset = -0.085

Definition at line 50 of file lstmrecognizer.cpp.

◆ kCJKAspectRatio

const double tesseract::kCJKAspectRatio = 1.25

Definition at line 65 of file strokewidth.cpp.

◆ kCJKAspectRatioIncrease

const double tesseract::kCJKAspectRatioIncrease = 1.0625

Definition at line 67 of file strokewidth.cpp.

◆ kCJKBrokenDistanceFraction

const double tesseract::kCJKBrokenDistanceFraction = 0.25

Definition at line 61 of file strokewidth.cpp.

◆ kCJKMaxComponents

const int tesseract::kCJKMaxComponents = 8

Definition at line 63 of file strokewidth.cpp.

◆ kCJKRadius

const int tesseract::kCJKRadius = 2

Definition at line 59 of file strokewidth.cpp.

◆ kColumnWidthFactor

const int tesseract::kColumnWidthFactor = 20

Pixel resolution of column width estimates.

Definition at line 42 of file tabfind.h.

◆ kCosMaxSkewAngle

const double tesseract::kCosMaxSkewAngle = 0.866025

Definition at line 60 of file tabfind.cpp.

◆ kCrackSpacing

const int tesseract::kCrackSpacing = 100

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

Definition at line 45 of file linefind.cpp.

◆ kCrownLeft

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

Definition at line 46 of file paragraphs.cpp.

◆ kCrownRight

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

Definition at line 48 of file paragraphs.cpp.

◆ kDefaultResolution

const int tesseract::kDefaultResolution = 300

Definition at line 71 of file pango_font_info.cpp.

◆ kDiacriticXPadRatio

const double tesseract::kDiacriticXPadRatio = 7.0

Definition at line 74 of file strokewidth.cpp.

◆ kDiacriticYPadRatio

const double tesseract::kDiacriticYPadRatio = 1.75

Definition at line 77 of file strokewidth.cpp.

◆ kDictRatio

const double tesseract::kDictRatio = 2.25

Definition at line 48 of file lstmrecognizer.cpp.

◆ kDoNotReverse

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

Definition at line 43 of file trie.cpp.

◆ kDoubleFlag

const int tesseract::kDoubleFlag = 128

Definition at line 137 of file weightmatrix.cpp.

◆ kErrClip

const double tesseract::kErrClip = 1.0f

Definition at line 68 of file lstm.cpp.

◆ kErrorGraphInterval

const int tesseract::kErrorGraphInterval = 1000

Definition at line 56 of file lstmtrainer.cpp.

◆ kExposureFactor

const int tesseract::kExposureFactor = 16

Definition at line 58 of file degradeimage.cpp.

◆ kFeaturePadding

const int tesseract::kFeaturePadding = 2

Definition at line 35 of file imagedata.h.

◆ kFontMergeDistance

const float tesseract::kFontMergeDistance = 0.025

Definition at line 52 of file mastertrainer.cpp.

◆ kForceReverse

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

Definition at line 45 of file trie.cpp.

◆ kGoodRowNumberOfColumnsLarge

const double tesseract::kGoodRowNumberOfColumnsLarge = 0.7

Definition at line 58 of file tablerecog.cpp.

◆ kGoodRowNumberOfColumnsSmall

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

Definition at line 54 of file tablerecog.cpp.

◆ kGoodRowNumberOfColumnsSmallSize

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

Definition at line 55 of file tablerecog.cpp.

◆ kGutterMultiple

const int tesseract::kGutterMultiple = 4

Definition at line 38 of file tabvector.cpp.

◆ kGutterToNeighbourRatio

const int tesseract::kGutterToNeighbourRatio = 3

Definition at line 40 of file tabvector.cpp.

◆ kHighConfidence

const double tesseract::kHighConfidence = 0.9375

Definition at line 64 of file lstmtrainer.cpp.

◆ kHistogramBuckets

const int tesseract::kHistogramBuckets = 16

Definition at line 330 of file weightmatrix.cpp.

◆ kHistogramSize

const int tesseract::kHistogramSize = 256

Definition at line 27 of file otsuthr.h.

◆ kHorizontalGapMergeFraction

const double tesseract::kHorizontalGapMergeFraction = 0.5

Definition at line 52 of file colfind.cpp.

◆ kHorizontalSpacing

const double tesseract::kHorizontalSpacing = 0.30

Definition at line 33 of file tablerecog.cpp.

◆ kHorzStrongTextlineAspect

const int tesseract::kHorzStrongTextlineAspect = 5

Definition at line 69 of file colpartition.cpp.

◆ kHorzStrongTextlineCount

const int tesseract::kHorzStrongTextlineCount = 8

Definition at line 65 of file colpartition.cpp.

◆ kHorzStrongTextlineHeight

const int tesseract::kHorzStrongTextlineHeight = 10

Definition at line 67 of file colpartition.cpp.

◆ kHyphenLikeUTF8

const char * tesseract::kHyphenLikeUTF8
Initial value:
= {
"-",
"\u05BE",
"\u2010",
"\u2011",
"\u2012",
"\u2013",
"\u2014",
"\u2015",
"\u2212",
"\uFE58",
"\uFE63",
"\uFF0D",
NULL,
}

The following are confusable internal word punctuation symbols which we normalize to the first variant when matching in dawgs.

Definition at line 32 of file unicodes.cpp.

◆ kImagePadding

const int tesseract::kImagePadding = 4

Definition at line 37 of file imagedata.h.

◆ kImprovementFraction

const double tesseract::kImprovementFraction = 15.0 / 16.0

Definition at line 66 of file lstmtrainer.cpp.

◆ kInfiniteDist

const float tesseract::kInfiniteDist = 999.0f

Definition at line 900 of file mastertrainer.cpp.

◆ kInputFile

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

◆ kInt8Flag

const int tesseract::kInt8Flag = 1

Definition at line 131 of file weightmatrix.cpp.

◆ kLargeTableProjectionThreshold

const double tesseract::kLargeTableProjectionThreshold = 0.45

Definition at line 110 of file tablefind.cpp.

◆ kLargeTableRowCount

const int tesseract::kLargeTableRowCount = 6

Definition at line 112 of file tablefind.cpp.

◆ kLatinChs

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

◆ kLearningRateDecay

const double tesseract::kLearningRateDecay = sqrt(0.5)

Definition at line 52 of file lstmtrainer.cpp.

◆ kLeftIndentAlignmentCountTh

const int tesseract::kLeftIndentAlignmentCountTh = 1

Definition at line 83 of file equationdetect.cpp.

◆ kLineCountReciprocal

const double tesseract::kLineCountReciprocal = 4.0

Definition at line 51 of file tabvector.cpp.

◆ kLinedTableMinHorizontalLines

const int tesseract::kLinedTableMinHorizontalLines = 3

Definition at line 43 of file tablerecog.cpp.

◆ kLinedTableMinVerticalLines

const int tesseract::kLinedTableMinVerticalLines = 3

Definition at line 42 of file tablerecog.cpp.

◆ kLineFindGridSize

const int tesseract::kLineFindGridSize = 50

Grid size used by line finder. Not very critical.

Definition at line 47 of file linefind.cpp.

◆ kLineFragmentAspectRatio

const double tesseract::kLineFragmentAspectRatio = 10.0

Definition at line 54 of file tabfind.cpp.

◆ kLineResidueAspectRatio

const double tesseract::kLineResidueAspectRatio = 8.0

Definition at line 98 of file strokewidth.cpp.

◆ kLineResiduePadRatio

const int tesseract::kLineResiduePadRatio = 3

Definition at line 100 of file strokewidth.cpp.

◆ kLineResidueSizeRatio

const double tesseract::kLineResidueSizeRatio = 1.75

Definition at line 102 of file strokewidth.cpp.

◆ kLineTrapLongest

const int tesseract::kLineTrapLongest = 4

Definition at line 91 of file strokewidth.cpp.

◆ kLineTrapShortest

const int tesseract::kLineTrapShortest = 2

Definition at line 93 of file strokewidth.cpp.

◆ kLRM

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

Definition at line 27 of file unicodes.cpp.

◆ kMarginFactor

const double tesseract::kMarginFactor = 1.1

Definition at line 48 of file tablerecog.cpp.

◆ kMarginOverlapFraction

const double tesseract::kMarginOverlapFraction = 0.25

Definition at line 45 of file colpartitiongrid.cpp.

◆ kMathDigitDensityTh1

const float tesseract::kMathDigitDensityTh1 = 0.25

Definition at line 78 of file equationdetect.cpp.

◆ kMathDigitDensityTh2

const float tesseract::kMathDigitDensityTh2 = 0.1

Definition at line 79 of file equationdetect.cpp.

◆ kMathItalicDensityTh

const float tesseract::kMathItalicDensityTh = 0.5

Definition at line 80 of file equationdetect.cpp.

◆ kMaxAmbigStringSize

const int tesseract::kMaxAmbigStringSize = UNICHAR_LEN * (MAX_AMBIG_SIZE + 1)

Definition at line 36 of file ambigs.cpp.

◆ kMaxBaselineError

const double tesseract::kMaxBaselineError = 0.4375

Definition at line 72 of file colpartition.cpp.

◆ kMaxBlobOverlapFactor

const double tesseract::kMaxBlobOverlapFactor = 4.0

Definition at line 80 of file tablefind.cpp.

◆ kMaxBlobWidth

const int tesseract::kMaxBlobWidth = 500

Definition at line 43 of file tablefind.cpp.

◆ kMaxBoxEdgeDiff

const inT16 tesseract::kMaxBoxEdgeDiff = 2

Definition at line 32 of file recogtraining.cpp.

◆ kMaxBoxesInDataPartition

const int tesseract::kMaxBoxesInDataPartition = 20

Definition at line 69 of file tablefind.cpp.

◆ kMaxBytesPerLine

const int tesseract::kMaxBytesPerLine
Initial value:
const int kNumbersPerBlob
Definition: baseapi.cpp:1698
#define UNICHAR_LEN
Definition: unichar.h:31
const int kBytesPer64BitNumber
Definition: baseapi.cpp:1711

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

◆ kMaxCaptionLines

const int tesseract::kMaxCaptionLines = 7

Definition at line 39 of file colpartitiongrid.cpp.

◆ kMaxCharTopRange

const int tesseract::kMaxCharTopRange = 48

Definition at line 66 of file fixxht.cpp.

◆ kMaxChoices

const int tesseract::kMaxChoices = 4

Definition at line 46 of file lstmrecognizer.cpp.

◆ kMaxCircleErosions

const int tesseract::kMaxCircleErosions = 8

Definition at line 56 of file pagesegmain.cpp.

◆ kMaxCJKSizeRatio

const int tesseract::kMaxCJKSizeRatio = 5

Definition at line 69 of file strokewidth.cpp.

◆ kMaxColorDistance

const int tesseract::kMaxColorDistance = 900

Definition at line 79 of file colpartition.cpp.

◆ kMaxColumnHeaderDistance

const int tesseract::kMaxColumnHeaderDistance = 4

Definition at line 88 of file tablefind.cpp.

◆ kMaxDiacriticDistanceRatio

const double tesseract::kMaxDiacriticDistanceRatio = 1.25

Definition at line 83 of file strokewidth.cpp.

◆ kMaxDiacriticGapToBaseCharHeight

const double tesseract::kMaxDiacriticGapToBaseCharHeight = 1.0

Definition at line 86 of file strokewidth.cpp.

◆ kMaxDistToPartSizeRatio

const double tesseract::kMaxDistToPartSizeRatio = 1.5

Definition at line 57 of file colfind.cpp.

◆ kMaxFillinMultiple

const int tesseract::kMaxFillinMultiple = 11

Definition at line 47 of file tabvector.cpp.

◆ kMaxGapInTextPartition

const double tesseract::kMaxGapInTextPartition = 4.0

Definition at line 72 of file tablefind.cpp.

◆ kMaxGutterWidthAbsolute

const double tesseract::kMaxGutterWidthAbsolute = 2.00

Definition at line 49 of file tabfind.cpp.

◆ kMaxIncompatibleColumnCount

const int tesseract::kMaxIncompatibleColumnCount = 2

Definition at line 49 of file colfind.cpp.

◆ kMaxInputHeight

const int tesseract::kMaxInputHeight = 48

Definition at line 29 of file input.cpp.

◆ kMaxIntSize

const int tesseract::kMaxIntSize = 22

Max string length of an int.

Definition at line 104 of file baseapi.cpp.

◆ kMaxLargeOverlapsWithMedium

const int tesseract::kMaxLargeOverlapsWithMedium = 12

Definition at line 44 of file ccnontextdetect.cpp.

◆ kMaxLargeOverlapsWithSmall

const int tesseract::kMaxLargeOverlapsWithSmall = 3

Definition at line 35 of file ccnontextdetect.cpp.

◆ kMaxLeaderGapFractionOfMax

const double tesseract::kMaxLeaderGapFractionOfMax = 0.25

Definition at line 55 of file colpartition.cpp.

◆ kMaxLeaderGapFractionOfMin

const double tesseract::kMaxLeaderGapFractionOfMin = 0.5

Definition at line 57 of file colpartition.cpp.

◆ kMaxLigature

const int tesseract::kMaxLigature = 0xfb17

Definition at line 46 of file ligature_table.cpp.

◆ kMaxLineLength

const int tesseract::kMaxLineLength = 1024

Definition at line 319 of file boxchar.cpp.

◆ kMaxLineResidue

const int tesseract::kMaxLineResidue = 6

Definition at line 53 of file linefind.cpp.

◆ kMaxMediumOverlapsWithSmall

const int tesseract::kMaxMediumOverlapsWithSmall = 12

Definition at line 40 of file ccnontextdetect.cpp.

◆ kMaxNeighbourDistFactor

const int tesseract::kMaxNeighbourDistFactor = 4

Definition at line 37 of file colpartitiongrid.cpp.

◆ kMaxNonLineDensity

const double tesseract::kMaxNonLineDensity = 0.25

Definition at line 58 of file linefind.cpp.

◆ kMaxOffsetDist

const int tesseract::kMaxOffsetDist = 32

Definition at line 32 of file intfeaturemap.cpp.

◆ kMaxPadFactor

const int tesseract::kMaxPadFactor = 6

Definition at line 34 of file colpartitiongrid.cpp.

◆ kMaxParagraphEndingLeftSpaceMultiple

const double tesseract::kMaxParagraphEndingLeftSpaceMultiple = 3.0

Definition at line 129 of file tablefind.cpp.

◆ kMaxPartitionSpacing

const double tesseract::kMaxPartitionSpacing = 1.75

Definition at line 62 of file colpartitiongrid.cpp.

◆ kMaxRaggedSearch

const int tesseract::kMaxRaggedSearch = 25

Definition at line 39 of file tabfind.cpp.

◆ kMaxRealDistance

const int tesseract::kMaxRealDistance = 2.0

Definition at line 37 of file detlinefit.cpp.

◆ kMaxRectangularFraction

const double tesseract::kMaxRectangularFraction = 0.75

Definition at line 46 of file imagefind.cpp.

◆ kMaxRectangularGradient

const double tesseract::kMaxRectangularGradient = 0.1

Definition at line 49 of file imagefind.cpp.

◆ kMaxRMSColorNoise

const int tesseract::kMaxRMSColorNoise = 128

Definition at line 76 of file colpartition.cpp.

◆ kMaxRowSize

const double tesseract::kMaxRowSize = 2.5

Definition at line 51 of file tablerecog.cpp.

◆ kMaxSameBlockLineSpacing

const double tesseract::kMaxSameBlockLineSpacing = 3

Definition at line 51 of file colpartition.cpp.

◆ kMaxSizeRatio

const double tesseract::kMaxSizeRatio = 1.5

Definition at line 53 of file colpartition.cpp.

◆ kMaxSkewFactor

const int tesseract::kMaxSkewFactor = 15

Definition at line 64 of file alignedblob.cpp.

◆ kMaxSmallNeighboursPerPix

const double tesseract::kMaxSmallNeighboursPerPix = 1.0 / 32

Definition at line 32 of file ccnontextdetect.cpp.

◆ kMaxSpacingDrift

const double tesseract::kMaxSpacingDrift = 1.0 / 72

Definition at line 45 of file colpartition.cpp.

◆ kMaxStaveHeight

const double tesseract::kMaxStaveHeight = 1.0

Definition at line 60 of file linefind.cpp.

◆ kMaxTableCellXheight

const double tesseract::kMaxTableCellXheight = 2.0

Definition at line 84 of file tablefind.cpp.

◆ kMaxTopSpacingFraction

const double tesseract::kMaxTopSpacingFraction = 0.25

Definition at line 48 of file colpartition.cpp.

◆ kMaxUnicharsPerCluster

const int tesseract::kMaxUnicharsPerCluster = 2000

Definition at line 50 of file mastertrainer.cpp.

◆ kMaxVerticalSearch

const int tesseract::kMaxVerticalSearch = 12

Definition at line 38 of file tabfind.cpp.

◆ kMaxVerticalSpacing

const int tesseract::kMaxVerticalSpacing = 500

Definition at line 41 of file tablefind.cpp.

◆ kMaxWinSize

const int tesseract::kMaxWinSize = 2000

Definition at line 51 of file network.cpp.

◆ kMaxXProjectionGapFactor

const double tesseract::kMaxXProjectionGapFactor = 2.0

Definition at line 139 of file tablefind.cpp.

◆ kMinAlignedGutter

const double tesseract::kMinAlignedGutter = 0.25

Definition at line 53 of file tabvector.cpp.

◆ kMinAlignedTabs

const int tesseract::kMinAlignedTabs = 4

Definition at line 54 of file alignedblob.cpp.

◆ kMinBaselineCoverage

const double tesseract::kMinBaselineCoverage = 0.5

Definition at line 74 of file colpartition.cpp.

◆ kMinBoxesInTextPartition

const int tesseract::kMinBoxesInTextPartition = 10

Definition at line 66 of file tablefind.cpp.

◆ kMinCaptionGapHeightRatio

const double tesseract::kMinCaptionGapHeightRatio = 0.5

Definition at line 43 of file colpartitiongrid.cpp.

◆ kMinCaptionGapRatio

const double tesseract::kMinCaptionGapRatio = 2.0

Definition at line 41 of file colpartitiongrid.cpp.

◆ kMinCertainty

const float tesseract::kMinCertainty = -20.0f

Definition at line 29 of file networkio.cpp.

◆ kMinChainTextValue

const int tesseract::kMinChainTextValue = 3

Definition at line 63 of file colpartition.cpp.

◆ kMinClusteredShapes

const int tesseract::kMinClusteredShapes = 1

Definition at line 48 of file mastertrainer.cpp.

◆ kMinColorDifference

const int tesseract::kMinColorDifference = 16

Definition at line 55 of file imagefind.cpp.

◆ kMinColumnWidth

const int tesseract::kMinColumnWidth = 2.0 / 3

Definition at line 33 of file colpartitionset.cpp.

◆ kMinDiacriticSizeRatio

const double tesseract::kMinDiacriticSizeRatio = 1.0625

Definition at line 80 of file strokewidth.cpp.

◆ kMinDivergenceRate

const double tesseract::kMinDivergenceRate = 50.0

Definition at line 45 of file lstmtrainer.cpp.

◆ kMinEvaluatedTabs

const int tesseract::kMinEvaluatedTabs = 3

Definition at line 56 of file tabfind.cpp.

◆ kMinFilledArea

const double tesseract::kMinFilledArea = 0.35

Definition at line 61 of file tablerecog.cpp.

◆ kMinFractionalLinesInColumn

const double tesseract::kMinFractionalLinesInColumn = 0.125

Definition at line 45 of file tabfind.cpp.

◆ kMinGoodTextPARatio

const double tesseract::kMinGoodTextPARatio = 1.5

Definition at line 60 of file ccnontextdetect.cpp.

◆ kMinGutterFraction

const double tesseract::kMinGutterFraction = 0.5

Definition at line 49 of file tabvector.cpp.

◆ kMinGutterWidthGrid

const double tesseract::kMinGutterWidthGrid = 0.5

Definition at line 54 of file colfind.cpp.

◆ kMinImageFindSize

const int tesseract::kMinImageFindSize = 100

Definition at line 51 of file imagefind.cpp.

◆ kMinLeaderCount

const int tesseract::kMinLeaderCount = 5

Definition at line 59 of file colpartition.cpp.

◆ kMinLigature

const int tesseract::kMinLigature = 0xfb00

Definition at line 45 of file ligature_table.cpp.

◆ kMinLineLengthFraction

const int tesseract::kMinLineLengthFraction = 4

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

Definition at line 43 of file linefind.cpp.

◆ kMinLinesInColumn

const int tesseract::kMinLinesInColumn = 10

Definition at line 41 of file tabfind.cpp.

◆ kMinMaxGapInTextPartition

const double tesseract::kMinMaxGapInTextPartition = 0.5

Definition at line 76 of file tablefind.cpp.

◆ kMinMusicPixelFraction

const double tesseract::kMinMusicPixelFraction = 0.75

Definition at line 62 of file linefind.cpp.

◆ kMinOutlierSamples

const int tesseract::kMinOutlierSamples = 5

Definition at line 37 of file trainingsampleset.cpp.

◆ kMinOverlapWithTable

const double tesseract::kMinOverlapWithTable = 0.6

Definition at line 100 of file tablefind.cpp.

◆ kMinParagraphEndingTextToWhitespaceRatio

const double tesseract::kMinParagraphEndingTextToWhitespaceRatio = 3.0

Definition at line 135 of file tablefind.cpp.

◆ kMinPointsForErrorCount

const int tesseract::kMinPointsForErrorCount = 16

Definition at line 34 of file detlinefit.cpp.

◆ kMinProb

const float tesseract::kMinProb = exp(kMinCertainty)

Definition at line 31 of file networkio.cpp.

◆ kMinRaggedGutter

const double tesseract::kMinRaggedGutter = 1.5

Definition at line 55 of file tabvector.cpp.

◆ kMinRaggedTabs

const int tesseract::kMinRaggedTabs = 5

Definition at line 52 of file alignedblob.cpp.

◆ kMinRampSize

const int tesseract::kMinRampSize = 1000

Definition at line 62 of file degradeimage.cpp.

◆ kMinRectangularFraction

const double tesseract::kMinRectangularFraction = 0.125

Definition at line 44 of file imagefind.cpp.

◆ kMinRectSize

const int tesseract::kMinRectSize = 10

Minimum sensible image size to be worth running tesseract.

Definition at line 87 of file baseapi.cpp.

◆ kMinRowsInTable

const int tesseract::kMinRowsInTable = 3

Definition at line 115 of file tablefind.cpp.

◆ kMinStallIterations

const int tesseract::kMinStallIterations = 10000

Definition at line 47 of file lstmtrainer.cpp.

◆ kMinStartedErrorRate

const int tesseract::kMinStartedErrorRate = 75

Definition at line 60 of file lstmtrainer.cpp.

◆ kMinStrongTextValue

const int tesseract::kMinStrongTextValue = 6

Definition at line 61 of file colpartition.cpp.

◆ kMinTabGradient

const double tesseract::kMinTabGradient = 4.0

Definition at line 60 of file alignedblob.cpp.

◆ kMinThickLineWidth

const int tesseract::kMinThickLineWidth = 12

Definition at line 49 of file linefind.cpp.

◆ kMinVerticalSearch

const int tesseract::kMinVerticalSearch = 3

Definition at line 37 of file tabfind.cpp.

◆ kMinWinSize

const int tesseract::kMinWinSize = 500

Definition at line 50 of file network.cpp.

◆ kMostlyOneDirRatio

const int tesseract::kMostlyOneDirRatio = 3

Definition at line 96 of file strokewidth.cpp.

◆ kNeighbourSearchFactor

const double tesseract::kNeighbourSearchFactor = 2.5

Definition at line 106 of file strokewidth.cpp.

◆ kNodeContNames

const char* tesseract::kNodeContNames[] = {"Anything", "OnlyDup", "NoDup"}

Definition at line 39 of file recodebeam.cpp.

◆ kNoiseOverlapAreaFactor

const double tesseract::kNoiseOverlapAreaFactor = 1.0 / 512

Definition at line 111 of file strokewidth.cpp.

◆ kNoiseOverlapGrowthFactor

const double tesseract::kNoiseOverlapGrowthFactor = 4.0

Definition at line 108 of file strokewidth.cpp.

◆ kNoisePadding

const int tesseract::kNoisePadding = 4

Definition at line 51 of file ccnontextdetect.cpp.

◆ kNullChar

const char* tesseract::kNullChar = "<nul>"

Definition at line 30 of file unicharcompress.cpp.

◆ kNumAdjustmentIterations

const int tesseract::kNumAdjustmentIterations = 100

Definition at line 54 of file lstmtrainer.cpp.

◆ kNumbersPerBlob

const int tesseract::kNumbersPerBlob = 5

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

Definition at line 1698 of file baseapi.cpp.

◆ kNumEndPoints

const int tesseract::kNumEndPoints = 3

Definition at line 28 of file detlinefit.cpp.

◆ kNumPagesPerBatch

const int tesseract::kNumPagesPerBatch = 100

Definition at line 58 of file lstmtrainer.cpp.

◆ kOldVarsFile

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

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

Definition at line 102 of file baseapi.cpp.

◆ kOriginalNoiseMultiple

const int tesseract::kOriginalNoiseMultiple = 8

Definition at line 47 of file ccnontextdetect.cpp.

◆ kParagraphEndingPreviousLineRatio

const double tesseract::kParagraphEndingPreviousLineRatio = 1.3

Definition at line 125 of file tablefind.cpp.

◆ kPDF

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

Definition at line 30 of file unicodes.cpp.

◆ kPhotoOffsetFraction

const double tesseract::kPhotoOffsetFraction = 0.375

Definition at line 54 of file ccnontextdetect.cpp.

◆ kPrime1

const int tesseract::kPrime1 = 17

Definition at line 34 of file trainingsampleset.cpp.

◆ kPrime2

const int tesseract::kPrime2 = 13

Definition at line 35 of file trainingsampleset.cpp.

◆ kRadicalRadix

const int tesseract::kRadicalRadix = 29

Definition at line 32 of file unicharcompress.cpp.

◆ kRaggedFraction

const double tesseract::kRaggedFraction = 2.5

Definition at line 40 of file alignedblob.cpp.

◆ kRaggedGapFraction

const double tesseract::kRaggedGapFraction = 1.0

Definition at line 44 of file alignedblob.cpp.

◆ kRaggedGutterMultiple

const int tesseract::kRaggedGutterMultiple = 5

Definition at line 51 of file tabfind.cpp.

◆ kRandomizingCenter

const int tesseract::kRandomizingCenter = 128

Definition at line 35 of file trainingsample.cpp.

◆ kRatingEpsilon

const double tesseract::kRatingEpsilon = 1.0 / 32

Definition at line 31 of file errorcounter.cpp.

◆ kRequiredColumns

const double tesseract::kRequiredColumns = 0.7

Definition at line 46 of file tablerecog.cpp.

◆ kReverseIfHasRTL

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

Definition at line 44 of file trie.cpp.

◆ kRGBRMSColors

const int tesseract::kRGBRMSColors = 4

Definition at line 36 of file colpartition.h.

◆ kRLE

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

Definition at line 29 of file unicodes.cpp.

◆ kRLM

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

Definition at line 28 of file unicodes.cpp.

◆ kRMSFitScaling

const double tesseract::kRMSFitScaling = 8.0

Definition at line 53 of file imagefind.cpp.

◆ kRotationRange

const float tesseract::kRotationRange = 0.02f

Definition at line 56 of file degradeimage.cpp.

◆ kRulingVerticalMargin

const int tesseract::kRulingVerticalMargin = 3

Definition at line 96 of file tablefind.cpp.

◆ kSaltnPepper

const int tesseract::kSaltnPepper = 5

Definition at line 60 of file degradeimage.cpp.

◆ kScaleFactor

const double tesseract::kScaleFactor = 256.0

Definition at line 39 of file functions.h.

◆ kSeedBlobsCountTh

const int tesseract::kSeedBlobsCountTh = 10

Definition at line 82 of file equationdetect.cpp.

◆ kSideSpaceMargin

const int tesseract::kSideSpaceMargin = 10

Definition at line 105 of file tablefind.cpp.

◆ kSimilarRaggedDist

const int tesseract::kSimilarRaggedDist = 50

Definition at line 45 of file tabvector.cpp.

◆ kSimilarVectorDist

const int tesseract::kSimilarVectorDist = 10

Definition at line 42 of file tabvector.cpp.

◆ ksizeofUniversalAmbigsFile

const int tesseract::ksizeofUniversalAmbigsFile = sizeof(kUniversalAmbigsFile)

Definition at line 27 of file universalambigs.h.

◆ kSizeRatioToReject

const float tesseract::kSizeRatioToReject = 2.0

Definition at line 104 of file strokewidth.cpp.

◆ kSmallTableProjectionThreshold

const double tesseract::kSmallTableProjectionThreshold = 0.35

Definition at line 109 of file tablefind.cpp.

◆ kSmoothDecisionMargin

const int tesseract::kSmoothDecisionMargin = 4

Definition at line 65 of file colpartitiongrid.cpp.

◆ kSplitPartitionSize

const double tesseract::kSplitPartitionSize = 2.0

Definition at line 47 of file tablefind.cpp.

◆ kSquareLimit

const int tesseract::kSquareLimit = 25

Definition at line 32 of file trainingsampleset.cpp.

◆ kStageTransitionThreshold

const double tesseract::kStageTransitionThreshold = 10.0

Definition at line 62 of file lstmtrainer.cpp.

◆ kStateClip

const double tesseract::kStateClip = 100.0

Definition at line 66 of file lstm.cpp.

◆ kStrokeWidthCJK

const double tesseract::kStrokeWidthCJK = 2.0

Definition at line 56 of file strokewidth.cpp.

◆ kStrokeWidthConstantTolerance

const double tesseract::kStrokeWidthConstantTolerance = 2.0

Definition at line 144 of file tablefind.cpp.

◆ kStrokeWidthFractionalTolerance

const double tesseract::kStrokeWidthFractionalTolerance = 0.25

Definition at line 143 of file tablefind.cpp.

◆ kStrokeWidthFractionCJK

const double tesseract::kStrokeWidthFractionCJK = 0.25

Definition at line 55 of file strokewidth.cpp.

◆ kStrokeWidthFractionTolerance

const double tesseract::kStrokeWidthFractionTolerance = 0.125

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

Definition at line 48 of file strokewidth.cpp.

◆ kStrokeWidthTolerance

const double tesseract::kStrokeWidthTolerance = 1.5

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

Definition at line 53 of file strokewidth.cpp.

◆ kSubTrainerMarginFraction

const double tesseract::kSubTrainerMarginFraction = 3.0 / 128

Definition at line 50 of file lstmtrainer.cpp.

◆ kTableColumnThreshold

const double tesseract::kTableColumnThreshold = 3.0

Definition at line 92 of file tablefind.cpp.

◆ kTableSize

const int tesseract::kTableSize = 4096

Definition at line 37 of file functions.h.

◆ kTabRadiusFactor

const int tesseract::kTabRadiusFactor = 5

Definition at line 35 of file tabfind.cpp.

◆ kTargetXScale

const int tesseract::kTargetXScale = 5

Definition at line 70 of file lstmtrainer.cpp.

◆ kTargetYScale

const int tesseract::kTargetYScale = 100

Definition at line 71 of file lstmtrainer.cpp.

◆ kTesseractReject

const char tesseract::kTesseractReject = '~'

Character returned when Tesseract couldn't recognize as anything.

Definition at line 89 of file baseapi.cpp.

◆ kTestChar

const int tesseract::kTestChar = -1

Definition at line 30 of file trainingsampleset.cpp.

◆ kThickLengthMultiple

const double tesseract::kThickLengthMultiple = 0.75

Definition at line 56 of file linefind.cpp.

◆ kThinLineFraction

const int tesseract::kThinLineFraction = 20

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

Definition at line 41 of file linefind.cpp.

◆ kTinyEnoughTextlineOverlapFraction

const double tesseract::kTinyEnoughTextlineOverlapFraction = 0.25

Definition at line 49 of file colpartitiongrid.cpp.

◆ kUnclearDensityTh

const float tesseract::kUnclearDensityTh = 0.25

Definition at line 81 of file equationdetect.cpp.

◆ kUniChs

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

◆ kUniversalAmbigsFile

const char tesseract::kUniversalAmbigsFile

Definition at line 26 of file universalambigs.h.

◆ kUNLVReject

const char tesseract::kUNLVReject = '~'

Character used by UNLV error counter as a reject.

Definition at line 91 of file baseapi.cpp.

◆ kUNLVSuspect

const char tesseract::kUNLVSuspect = '^'

Character used by UNLV as a suspect marker.

Definition at line 93 of file baseapi.cpp.

◆ kUTF8LineSeparator

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

Definition at line 25 of file unicodes.cpp.

◆ kUTF8ParagraphSeparator

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

Definition at line 26 of file unicodes.cpp.

◆ kVerticalSpacing

const double tesseract::kVerticalSpacing = -0.2

Definition at line 36 of file tablerecog.cpp.

◆ kVLineAlignment

const int tesseract::kVLineAlignment = 3

Definition at line 46 of file alignedblob.cpp.

◆ kVLineGutter

const int tesseract::kVLineGutter = 1

Definition at line 48 of file alignedblob.cpp.

◆ kVLineMinLength

const int tesseract::kVLineMinLength = 500

Definition at line 56 of file alignedblob.cpp.

◆ kVLineSearchSize

const int tesseract::kVLineSearchSize = 150

Definition at line 50 of file alignedblob.cpp.

◆ kWorstDictCertainty

const float tesseract::kWorstDictCertainty = -25.0f

Definition at line 37 of file linerec.cpp.

◆ kXWinFrameSize

const int tesseract::kXWinFrameSize = 30

Definition at line 53 of file network.cpp.

◆ kYWinFrameSize

const int tesseract::kYWinFrameSize = 80

Definition at line 54 of file network.cpp.

◆ LogisticTable

double tesseract::LogisticTable

Definition at line 24 of file functions.cpp.

◆ RTLReversePolicyNames

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

Definition at line 47 of file trie.cpp.

◆ TanhTable

double tesseract::TanhTable

Definition at line 23 of file functions.cpp.

◆ textord_show_tables

bool tesseract::textord_show_tables = false

"Show table regions"

Definition at line 146 of file tablefind.cpp.

◆ textord_tabfind_find_tables

bool tesseract::textord_tabfind_find_tables = true

"run table detection"

Definition at line 67 of file colfind.cpp.

◆ textord_tabfind_only_strokewidths

bool tesseract::textord_tabfind_only_strokewidths = false

"Only run stroke widths"

Definition at line 45 of file strokewidth.cpp.

◆ textord_tabfind_show_blocks

bool tesseract::textord_tabfind_show_blocks = false

"Show final block bounds"

Definition at line 66 of file colfind.cpp.

◆ textord_tabfind_show_color_fit

bool tesseract::textord_tabfind_show_color_fit = false

"Show stroke widths"

Definition at line 30 of file colpartitiongrid.cpp.

◆ textord_tabfind_show_columns

bool tesseract::textord_tabfind_show_columns = false

"Show column bounds"

Definition at line 65 of file colfind.cpp.

◆ textord_tabfind_show_finaltabs

bool tesseract::textord_tabfind_show_finaltabs = false

"Show tab vectors"

Definition at line 63 of file tabfind.cpp.

◆ textord_tabfind_show_initial_partitions

bool tesseract::textord_tabfind_show_initial_partitions = false

"Show partition bounds"

Definition at line 60 of file colfind.cpp.

◆ textord_tabfind_show_initialtabs

bool tesseract::textord_tabfind_show_initialtabs = false

"Show tab candidates"

Definition at line 62 of file tabfind.cpp.

◆ textord_tabfind_show_partitions

int tesseract::textord_tabfind_show_partitions = 0

"Show partition bounds, waiting if >1"

Definition at line 64 of file colfind.cpp.

◆ textord_tabfind_show_reject_blobs

bool tesseract::textord_tabfind_show_reject_blobs = false

"Show blobs rejected as noise"

Definition at line 62 of file colfind.cpp.

◆ textord_tabfind_show_strokewidths

int tesseract::textord_tabfind_show_strokewidths = 0

"Show stroke widths"

Definition at line 44 of file strokewidth.cpp.

◆ textord_tablefind_recognize_tables

bool tesseract::textord_tablefind_recognize_tables = false

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

Definition at line 152 of file tablefind.cpp.

◆ textord_tablefind_show_mark

bool tesseract::textord_tablefind_show_mark = false

"Debug table marking steps in detail"

Definition at line 148 of file tablefind.cpp.

◆ textord_tablefind_show_stats

bool tesseract::textord_tablefind_show_stats = false

"Show page stats used in table finding"

Definition at line 150 of file tablefind.cpp.

◆ textord_tabvector_vertical_box_ratio

double tesseract::textord_tabvector_vertical_box_ratio = 0.5

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

Definition at line 61 of file tabvector.cpp.

◆ textord_tabvector_vertical_gap_fraction

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 58 of file tabvector.cpp.

◆ tprintfMutex

CCUtilMutex tesseract::tprintfMutex

Definition at line 60 of file ccutil.cpp.