TESSERACT(1)

๐Ÿ’… TESSERACT(1) โ€” the OCR engine that eats and leaves no crumbs

okay bestie so you've wandered into the tesseract manual page and honestly? iconic. this is the command-line OCR engine, and in this house "OCR" means optical character recognition โ€” you feed it an image and it hands you back the actual text. it's giving "i can read your screenshots." ๐Ÿ’–

โœจ NAME โœจ

tesseract โ€” the command-line OCR engine. that's the whole name section, we're literally at the door, come in ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

tesseract FILE OUTPUTBASE [OPTIONS]... [CONFIGFILE]...

like that's it. that's the shape of your whole life with this tool. FILE goes in, OUTPUTBASE comes out, and everything in between is your options and config files doing their little thing โœจ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so the lore is actually kind of unhinged: tesseract(1) is a commercial quality OCR engine that was originally developed at HP between 1985 and 1995. 1985!! your parents were probably not even speaking yet ๐Ÿ˜ญ

in 1995, this engine was among the top 3 evaluated by UNLV. yes, top three. the way it was out there competing in 1995 being evaluated and everything.

then it was open-sourced by HP and UNLV in 2005, and it's been developed at Google until 2018. so the rรฉsumรฉ is: HP โžก๏ธ UNLV โžก๏ธ open source โžก๏ธ Google. that's a main character career arc, no cap ๐Ÿ‘‘


๐ŸŽ€ IN/OUT ARGUMENTS ๐ŸŽ€

๐Ÿ“ฅ FILE

the name of the input file. and here's the tea, it can be either an image file or a text file โ€” flexible queen behavior ๐Ÿ’…

  • most image file formats are supported โ€” basically anything readable by Leptonica.
  • if it's a text file, that file lists the names of all input images โ€” one image name per line. and then the results will be combined in a single file for each output file format (txt, pdf, hocr, xml). batch mode, we love to see it โœจ
  • if FILE is stdin or - then the standard input is used. keyed in from the void, iykyk ๐ŸŒˆ

๐Ÿ“ค OUTPUTBASE

the basename of the output file โ€” like, the stem, and the appropriate extension gets appended to it. by default the output will be a text file with .txt added to the basename, unless there are one or more parameters set which explicitly specify the desired output. so if you asked for something specific, you get that specific something. periodt

if OUTPUTBASE is stdout or - then the standard output is used ๐Ÿ’€ (in the good way, where it just prints at you)


โญ OPTIONS โญ

  • -c CONFIGVAR=VALUE โ€” set the value for parameter CONFIGVAR to VALUE. and you can stack em! multiple -c arguments are allowed. more -c, more power ๐Ÿซถ
  • --dpi N โ€” specify the resolution N in DPI for the input image(s). a typical value for N is 300. without this option, the resolution is read from the metadata included in the image. and if an image does not include that information, Tesseract tries to guess it ๐Ÿ™ˆ (it's doing its best, okay)
  • -l LANG, -l SCRIPT โ€” the language or script to use. if none is specified, eng (English) is assumed. multiple languages may be specified, separated by plus characters (+). Tesseract uses 3-character ISO 639-2 language codes โ€” see the LANGUAGES AND SCRIPTS section below, that's where the full list lives ๐Ÿ‘‡
  • --psm N โ€” set Tesseract to only run a subset of layout analysis and assume a certain form of image. literally you're telling it "bestie don't overthink this, it's one line of text." the options for N are:
0  = Orientation and script detection (OSD) only.
1  = Automatic page segmentation with OSD.
2  = Automatic page segmentation, but no OSD, or OCR. (not implemented)
3  = Fully automatic page segmentation, but no OSD. (Default)
4  = Assume a single column of text of variable sizes.
5  = Assume a single uniform block of vertically aligned text.
6  = Assume a single uniform block of text.
7  = Treat the image as a single text line.
8  = Treat the image as a single word.
9  = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
11 = Sparse text. Find as much text as possible in no particular order.
12 = Sparse text with OSD.
13 = Raw line. Treat the image as a single text line,
     bypassing hacks that are Tesseract-specific.
note that 2 is literally marked "(not implemented)". it's a vibe, not a feature ๐Ÿ’€
  • --oem N โ€” specify OCR Engine mode. the options for N are:
0  = Original Tesseract only.
1  = Neural nets LSTM only.
2  = Tesseract + LSTM.
3  = Default, based on what is available.
  • --tessdata-dir PATH โ€” specify the location of the tessdata path. tell it where the brain lives ๐Ÿง 
  • --user-patterns FILE โ€” specify the location of the user patterns file.
  • --user-words FILE โ€” specify the location of the user words file.

๐Ÿงš CONFIGFILE

the name of a config to use. the name can be:

  • a file in tessdata/configs or tessdata/tessconfigs, or
  • an absolute or relative file path.

a config is a plain text file which contains a list of parameters and their values, one per line, with a space separating parameter from value. simple. clean. aesthetic โœจ

interesting config files include:

  • alto โ€” output in ALTO format (OUTPUTBASE.xml).
  • hocr โ€” output in hOCR format (OUTPUTBASE.hocr).
  • page โ€” output in PAGE format (OUTPUTBASE.page.xml). the output can be customized with the flags:
    • page_xml_polygon โ€” create polygons instead of bounding boxes (default: true)
    • page_xml_level โ€” create the PAGE file on 0=linelevel or 1=wordlevel (default: 0)
  • pdf โ€” output PDF (OUTPUTBASE.pdf).
  • tsv โ€” output TSV (OUTPUTBASE.tsv).
  • txt โ€” output plain text (OUTPUTBASE.txt).
  • get.images โ€” write processed input images to file (OUTPUTBASE.processedPAGENUMBER.tif).
  • logfile โ€” redirect debug messages to file (tesseract.log).
  • lstm.train โ€” output files used by LSTM training (OUTPUTBASE.lstmf).
  • makebox โ€” write box file (OUTPUTBASE.box).
  • quiet โ€” redirect debug messages to /dev/null. shhh ๐Ÿคซ

it is possible to select several config files, for example:

tesseract image.png demo alto hocr pdf txt

will create four output files โ€” demo.alto, demo.hocr, demo.pdf and demo.txt โ€” with the OCR results. four files, one command. multitasking icon behavior ๐Ÿ‘‘

Nota bene: the options -l LANG, -l SCRIPT and --psm N must occur before any CONFIGFILE. like, order matters, bestie. put them first or the whole thing gets weird. this is not a drill ๐Ÿšจ

๐Ÿ’œ SINGLE OPTIONS ๐Ÿ’œ

these are the solo acts, the one-and-done flags:

  • -h, --help โ€” show help message.
  • --help-extra โ€” show extra help for advanced users. for the girlies who want more.
  • --help-psm โ€” show page segmentation modes.
  • --help-oem โ€” show OCR Engine modes.
  • -v, --version โ€” returns the current version of the tesseract(1) executable.
  • --list-langs โ€” list available languages for the tesseract engine. can be used with --tessdata-dir PATH. very much a "what do i actually have installed" vibe check ๐Ÿ”
  • --print-parameters โ€” print tesseract parameters.

๐ŸŒˆ LANGUAGES AND SCRIPTS ๐ŸŒˆ

so, to recognize some text with Tesseract, it is normally necessary to specify the language(s) or script(s) of the text (unless it's English text, which is supported by default). you do that with -l LANG or -l SCRIPT. English girlies get a free pass, everyone else gotta introduce themselves ๐Ÿ’…

selecting a language automatically also selects the language specific character set and dictionary (word list). two for one, slay.

selecting a script typically selects all characters of that script, which can be from different languages. the dictionary which is included also contains a mix from different languages. in most cases, a script also supports English. so it is possible to recognize a language that has not been specifically trained for by using traineddata for the script it is written in. loophole found, loophole ate ๐Ÿ”ฅ

more than one language or script may be specified by using +. example:

tesseract myimage.png myimage -l eng+deu+fra

https://github.com/tesseract-ocr/tessdata_fast provides fast language and script models which are also part of Linux distributions.

for Tesseract 4, tessdata_fast includes traineddata files for the following languages:

afr (Afrikaans), amh (Amharic), ara (Arabic), asm (Assamese), aze (Azerbaijani), aze_cyrl (Azerbaijani - Cyrillic), bel (Belarusian), ben (Bengali), bod (Tibetan), bos (Bosnian), bre (Breton), bul (Bulgarian), cat (Catalan; Valencian), ceb (Cebuano), ces (Czech), chi_sim (Chinese simplified), chi_tra (Chinese traditional), chr (Cherokee), cos (Corsican), cym (Welsh), dan (Danish), deu (German), deu_latf (German Fraktur Latin), div (Dhivehi), dzo (Dzongkha), ell (Greek, Modern, 1453-), eng (English), enm (English, Middle, 1100-1500), epo (Esperanto), equ (Math / equation detection module), est (Estonian), eus (Basque), fas (Persian), fao (Faroese), fil (Filipino), fin (Finnish), fra (French), frm (French, Middle, ca.1400-1600), fry (West Frisian), gla (Scottish Gaelic), gle (Irish), glg (Galician), grc (Greek, Ancient, to 1453), guj (Gujarati), hat (Haitian; Haitian Creole), heb (Hebrew), hin (Hindi), hrv (Croatian), hun (Hungarian), hye (Armenian), iku (Inuktitut), ind (Indonesian), isl (Icelandic), ita (Italian), ita_old (Italian - Old), jav (Javanese), jpn (Japanese), kan (Kannada), kat (Georgian), kat_old (Georgian - Old), kaz (Kazakh), khm (Central Khmer), kir (Kirghiz; Kyrgyz), kmr (Kurdish Kurmanji), kor (Korean), kor_vert (Korean vertical), lao (Lao), lat (Latin), lav (Latvian), lit (Lithuanian), ltz (Luxembourgish), mal (Malayalam), mar (Marathi), mkd (Macedonian), mlt (Maltese), mon (Mongolian), mri (Maori), msa (Malay), mya (Burmese), nep (Nepali), nld (Dutch; Flemish), nor (Norwegian), oci (Occitan post 1500), ori (Oriya), osd (Orientation and script detection module), pan (Panjabi; Punjabi), pol (Polish), por (Portuguese), pus (Pushto; Pashto), que (Quechua), ron (Romanian; Moldavian; Moldovan), rus (Russian), san (Sanskrit), sin (Sinhala; Sinhalese), slk (Slovak), slv (Slovenian), snd (Sindhi), spa (Spanish; Castilian), spa_old (Spanish; Castilian - Old), sqi (Albanian), srp (Serbian), srp_latn (Serbian - Latin), sun (Sundanese), swa (Swahili), swe (Swedish), syr (Syriac), tam (Tamil), tat (Tatar), tel (Telugu), tgk (Tajik), tha (Thai), tir (Tigrinya), ton (Tonga), tur (Turkish), uig (Uighur; Uyghur), ukr (Ukrainian), urd (Urdu), uzb (Uzbek), uzb_cyrl (Uzbek - Cyrillic), vie (Vietnamese), yid (Yiddish), yor (Yoruba)

like. that's the whole world in a list and it's beautiful ๐Ÿ˜ญ

to use a non-standard language pack named foo.traineddata, set the TESSDATA_PREFIX environment variable so the file can be found at TESSDATA_PREFIX/tessdata/foo.traineddata and give Tesseract the argument -l foo. DIY language, we respect the hustle ๐Ÿซถ

for Tesseract 4, tessdata_fast includes traineddata files for the following scripts:

Arabic, Armenian, Bengali, Canadian_Aboriginal, Cherokee, Cyrillic, Devanagari, Ethiopic, Fraktur, Georgian, Greek, Gujarati, Gurmukhi, HanS (Han simplified), HanS_vert (Han simplified, vertical), HanT (Han traditional), HanT_vert (Han traditional, vertical), Hangul, Hangul_vert (Hangul vertical), Hebrew, Japanese, Japanese_vert (Japanese vertical), Kannada, Khmer, Lao, Latin, Malayalam, Myanmar, Oriya (Odia), Sinhala, Syriac, Tamil, Telugu, Thaana, Thai, Tibetan, Vietnamese.

the same languages and scripts are available from https://github.com/tesseract-ocr/tessdata_best. tessdata_best provides slow language and script models. these models are needed for training. they also can give better OCR results, but the recognition takes much more time. trade-off queen โ€” accuracy or speed, pick your fighter โš–๏ธ

both tessdata_fast and tessdata_best only support the LSTM OCR engine. important!! don't come crying to me when the legacy engine doesn't show up to the party ๐Ÿ’€

there is a third repository, https://github.com/tesseract-ocr/tessdata, with models which support both the Tesseract 3 legacy OCR engine and the Tesseract 4 LSTM OCR engine. the versatile one. the one that gets along with everybody ๐ŸŒˆ

๐ŸŽ€ CONFIG FILES AND AUGMENTING WITH USER DATA ๐ŸŽ€

ok so tesseract config files are literally just lines of parameter-value pairs, space separated. that's it. that's the whole format bestie ๐Ÿ’…

the parameters themselves are documented as flags in the source code, like this one living in tesseractclass.h:

STRING_VAR_H(tessedit_char_blacklist, "", "Blacklist of chars not to
recognize");

these parameters can enable or disable different features of the engine, and they can make it load (or not load) different data. so for instance โ€” let's say you wanna OCR in English, but you want to suppress the normal dictionary and load an alternative word list plus an alternative list of patterns. those two files are the most commonly used extra data files, fyi.

so if your language pack is sitting in /path/to/eng.traineddata and the hocr config is in /path/to/configs/hocr, create three new files:

/path/to/eng.user-words:

the
quick
brown
fox
jumped

/path/to/eng.user-patterns:

1-\d\d\d-GOOG-411
www.\n\\\*.com

/path/to/configs/bazaar:

load_system_dawg     F
load_freq_dawg       F
user_words_suffix    user-words
user_patterns_suffix user-patterns

now, if you pass the word bazaar as a CONFIGFILE to Tesseract, it will โœจ not โœจ bother loading the system dictionary or the dictionary of frequent words, and it'll load and use the eng.user-words and eng.user-patterns files you provided. the first one is a simple word list, one per line. the format of the second one is documented in dict/trie.h on read_pattern_list() ๐Ÿซถ


โœจ PARAMETERS โœจ

Tesseract parameters control the behaviour of the OCR engine, and you can set them with the -c option (like -c tessedit_char_whitelist=0123456789) or by dropping them in a CONFIGFILE. the example above restricts recognized characters to digits only, no cap. run --print-parameters to list every available parameter with its current value and a lil short description ๐Ÿ’–

the engine column tells you which OCR engine modes support a parameter:

  • Both โ€” works with both the LSTM and Legacy engines
  • LSTM โ€” only applies to the neural-network LSTM engine (OEM 1 or 2)
  • Legacy โ€” only applies to the legacy Tesseract engine (OEM 0 or 2)

๐ŸŒˆ OUTPUT FORMAT PARAMETERS ๐ŸŒˆ

  • tessedit_create_txt โ€” bool, default: 0, [Both]. write plain-text output to a .txt file. this is the default output format when nothing (no config file, no -c option) overrides it.
  • tessedit_create_hocr โ€” bool, default: 0, [Both]. write hOCR output to a .hocr file. hOCR is an HTML-based format that encodes the OCR results together with their bounding boxes and confidences. use the hocr config file to enable this format. the hOCR specification lives at https://kba.github.io/hocr-spec/1.2/ if you wanna see the details of the output format ๐Ÿ‘‘
  • hocr_font_info โ€” bool, default: 0, [Both]. add per-word font metadata to hOCR output. when it's on, each word span includes x_font (font name) and x_fsize (point size) attributes in its title field. the font info comes from the recognition results and is most reliable with the Legacy OCR engine โ€” the LSTM engine may produce less precise font names ๐Ÿ˜ญ
  • hocr_char_boxes โ€” bool, default: 0, [Both]. add per-character bounding-box coordinates to hOCR output as ocrx_cinfo spans. heads up though: character-level bounding boxes may be less precise when you're using the LSTM engine, because LSTM operates at the line level and character positions are approximated from the line result. see also lstm_choice_mode for LSTM-specific character alternative output ๐Ÿ’ซ
  • tessedit_create_alto โ€” bool, default: 0, [Both]. write ALTO XML output to a .xml file. ALTO (Analyzed Layout and Text Object) is a standard XML schema for describing the layout and content of pages. use the alto config file to enable this format.
  • tessedit_create_page_xml โ€” bool, default: 0, [Both]. write PAGE XML output to a .page.xml file. PAGE (Page Analysis and Ground Truth Elements) is a standard XML format that's widely used in digital humanities projects, library and archive workflows, and document annotation tools like Transkribus and eScriptorium. spec is at https://github.com/PRImA-Research-Lab/PAGE-XML. use the page config file to enable this format ๐Ÿฆ‹
  • page_xml_polygon โ€” bool, default: 1, [Both]. when writing PAGE XML output, create polygon outlines around text regions instead of simple bounding boxes.
  • page_xml_level โ€” int, default: 0, [Both]. granularity of PAGE XML output: 0 = line level, 1 = word level.
  • tessedit_create_tsv โ€” bool, default: 0, [Both]. write tab-separated-values output to a .tsv file. every recognized word comes out as one row with its bounding box, confidence and text. use the tsv config file to enable this format.
  • tessedit_create_pdf โ€” bool, default: 0, [Both]. write a searchable PDF to a .pdf file. the PDF contains the original image with an invisible text layer for copy-paste and searching. use the pdf config file to enable this format ๐Ÿ“„
  • textonly_pdf โ€” bool, default: 0, [Both]. write a text-only PDF (no image, just invisible text) to a .pdf file.
  • tessedit_create_boxfile โ€” bool, default: 0, [Both]. write a Tesseract box file (.box) that lists each recognized character with its bounding box, one per line. either engine can produce it. these files are primarily used as ground truth for legacy engine training ๐Ÿงš
  • tessedit_create_wordstrbox โ€” bool, default: 0, [Both]. write a WordStr-format box file (.box). similar to tessedit_create_boxfile but records whole words instead of individual characters.
  • tessedit_create_lstmbox โ€” bool, default: 0, [LSTM]. write an LSTM box file (.box) suitable for LSTM training.
  • preserve_interword_spaces โ€” bool, default: 0, [Both]. preserve multiple consecutive inter-word spaces in the output instead of collapsing them down to a single space.

๐ŸŒธ CHARACTER SET PARAMETERS ๐ŸŒธ

  • tessedit_char_whitelist โ€” string, default: "", [Both]. restrict the set of characters Tesseract will recognize to only the ones listed in this string (allowlist). for example, setting this to 0123456789 makes Tesseract return only digits. an empty value (the default) means all characters in the trained data are allowed ๐Ÿ’œ
  • tessedit_char_blacklist โ€” string, default: "", [Both]. stop Tesseract from recognizing the characters listed in this string. characters in this list will never show up in the output. this exclusion list is applied after the allowlist (tessedit_char_whitelist).
  • tessedit_char_unblacklist โ€” string, default: "", [Both]. re-allow specific characters that got excluded by tessedit_char_blacklist. characters in this list override the exclusion list, and it applies to both the LSTM and Legacy engines ๐Ÿ‘‘

๐Ÿฆ‹ IMAGE PROCESSING PARAMETERS ๐Ÿฆ‹

  • thresholding_method โ€” int, default: 0, [Both]. pick the algorithm used to convert a greyscale image to binary before OCR: 0 = Otsu global thresholding (default); 1 = LeptonicaOtsu (tiled Otsu, better for uneven lighting); 2 = Sauvola local adaptive thresholding (best for heavily degraded documents) ๐Ÿ”ฅ
  • thresholding_window_size โ€” double, default: 0.33, [Both]. window size (multiplied by image DPI) used to compute local statistics for the Sauvola thresholding method (thresholding_method = 2).
  • thresholding_kfactor โ€” double, default: 0.34, [Both]. sensitivity factor for Sauvola thresholding (thresholding_method = 2). controls how much the local variance reduces the threshold. typical range: 0.2 โ€” 0.5. higher values produce more aggressive thresholding.
  • thresholding_tile_size โ€” double, default: 0.33, [Both]. desired tile size (multiplied by image DPI) for the LeptonicaOtsu tiled thresholding method (thresholding_method = 1).
  • thresholding_smooth_kernel_size โ€” double, default: 0, [Both]. kernel size for smoothing the threshold array produced by LeptonicaOtsu (thresholding_method = 1). use 0 for no smoothing.
  • thresholding_score_fraction โ€” double, default: 0.1, [Both]. fraction of the maximum Otsu score used by LeptonicaOtsu (thresholding_method = 1). use 0.0 for standard Otsu behaviour; 0.1 is recommended for better robustness โœจ
  • tessedit_do_invert โ€” bool, default: 1, [Both]. deprecated โ€” will be removed in a future release ๐Ÿ’€ when enabled, Tesseract tries OCR on an inverted (white-on-black) copy of lines whose mean confidence falls below invert_threshold and keeps whichever result has higher confidence. to disable automatic inversion, set invert_threshold = 0 rather than setting this parameter to 0.
  • invert_threshold โ€” double, default: 0.7, [Both]. mean confidence threshold below which Tesseract will also attempt OCR on the inverted image. lower values make inversion less likely. set it to 0 to disable automatic inversion entirely (this is preferred over setting tessedit_do_invert = 0, which is deprecated ๐Ÿซถ).
  • user_defined_dpi โ€” int, default: 0, [Both]. override the resolution of the input image in DPI. use this when the image metadata has a wrong or missing DPI value. a value of 0 means the resolution gets read from the image metadata or guessed automatically. this parameter is equivalent to the --dpi command-line option; when --dpi is given on the command line it just sets this parameter ๐Ÿ’…
  • textord_heavy_nr โ€” bool, default: 0, [Both]. aggressively remove noise blobs during page layout analysis. when it's disabled (the default), Tesseract applies a moderate noise threshold that preserves most legitimate characters. enabling this raises the threshold significantly, which can improve results on scans with heavy speckle or background noise โ€” but it may also remove small legitimate characters like punctuation marks, diacritics or small symbols ๐Ÿ˜ญ useful for OCR-ing degraded or low-quality document scans where accuracy on punctuation matters less than overall text extraction.

๐Ÿ“ DICTIONARY PARAMETERS ๐Ÿ“

  • load_system_dawg โ€” bool, default: 1, [Both]. load the main system word list (DAWG) from the traineddata file. disabling this can speed up recognition and may improve results when you're OCR-ing content that doesn't resemble natural language (codes, identifiers, etc.).
  • load_freq_dawg โ€” bool, default: 1, [Both]. load the list of frequent words from the traineddata file.
  • load_unambig_dawg โ€” bool, default: 1, [Legacy]. load the list of unambiguous words from the traineddata file.
  • load_punc_dawg โ€” bool, default: 1, [Legacy]. load the dawg containing punctuation patterns from the traineddata file.
  • load_number_dawg โ€” bool, default: 1, [Legacy]. load the dawg containing number patterns from the traineddata file ๐ŸŽ€
  • load_bigram_dawg (bool, default: 1) [Legacy] โ€” loads the dawg with the special word bigrams out of the traineddata file.
  • user_words_file (string, default: "") [Both] โ€” path to a plain-text file of extra words (one per line) that Tesseract should treat as legit dictionary words.
  • user_words_suffix (string, default: "") [Both] โ€” a filename suffix (relative to the tessdata directory) for a per-language file of extra valid words. So like, if you set this to user-words, Tesseract goes looking for eng.user-words when it's using the English model. iykyk.
  • user_patterns_file (string, default: "") [Both] โ€” path to a plain-text file of extra pattern strings (one per line) that Tesseract should accept as valid words. In the pattern language, backslash-escaped sequences specify character classes: \d = any digit; \c = any letter; \a = any lowercase letter; \A = any uppercase letter; \n = any alphanumeric character; \p = any punctuation character. All other characters match themselves. Example: 1-\d\d\d-GOOG-411 matches a phone-number-ish string. These are structural templates, not regular expressions, bestie. For the full pattern syntax, see dict/trie.h in the Tesseract source.
  • user_patterns_suffix (string, default: "") [Both] โ€” a filename suffix (relative to the tessdata directory) for a per-language file of extra patterns.

โœจ LSTM ENGINE PARAMETERS โœจ

Okay so these ones only actually do anything when you're running the LSTM OCR engine (--oem 1 or --oem 2). Like, they're literally only meaningful there ๐Ÿ’…

  • lstm_use_matrix (bool, default: 1) [LSTM] โ€” uses the ratings matrix and beam search during LSTM decoding. Turn it off and you get a simpler, faster greedy decoding strategy instead, which might be fine for super clean, high-quality images but generally gives lower accuracy. So like, risky vibe ngl.
  • lstm_choice_mode (int, default: 0) [LSTM] โ€” enables alternative character hypotheses in hOCR output (requires tessedit_create_hocr = 1): 0 = disabled (that's the default); 1 = include per-timestep alternative choices; 2 = extract alternative choices from the CTC output mapped per character. Also peep hocr_char_boxes for character bounding-box output ๐Ÿ‘€
  • lstm_choice_iterations (int, default: 5) [LSTM] โ€” how many cascading beam-search iterations happen when lstm_choice_mode is non-zero.
  • lstm_rating_coefficient (double, default: 5) [LSTM] โ€” a scaling factor applied to LSTM character ratings. Smaller values = higher (better) confidence scores and they preserve more info before the zero cut-off. Default is 5, periodt.

๐ŸŒˆ LEGACY ENGINE PARAMETERS ๐ŸŒˆ

These ones apply only when you're using the legacy Tesseract engine (--oem 0 or --oem 2, and it requires a traineddata file that includes the legacy model, like the ones from https://github.com/tesseract-ocr/tessdata).

  • tessedit_enable_bigram_correction (bool, default: 1) [Legacy] โ€” applies bigram-based correction to improve recognition of adjacent word pairs that commonly show up together (e.g. "is a", "in the", "New York"). The correction uses a bigram dictionary from the traineddata file to re-score word hypotheses in context. Iconic behaviour, honestly.
  • tessedit_enable_dict_correction (bool, default: 0) [Legacy] โ€” uses the dictionary to post-correct uncertain word hypotheses.
  • tessedit_fix_fuzzy_spaces (bool, default: 1) [Legacy] โ€” tries to fix spaces that got ambiguously classified as inter-word or inter-character gaps. The eternal struggle ๐Ÿ˜ญ
  • language_model_penalty_non_dict_word (double, default: 0.15) [Legacy] โ€” a penalty added to the score of word hypotheses that aren't in the dictionary. Crank it up to bias recognition harder towards dictionary words.
  • language_model_penalty_non_freq_dict_word (double, default: 0.1) [Legacy] โ€” an extra penalty for words that are in the dictionary but aren't in the list of frequent words.
  • language_model_penalty_case (double, default: 0.1) [Legacy] โ€” penalty applied when a recognised word's capitalisation doesn't match the surrounding context.
  • language_model_penalty_script (double, default: 0.5) [Legacy] โ€” penalty applied when a recognised character belongs to a different script from the surrounding text.
  • language_model_penalty_punc (double, default: 0.2) [Legacy] โ€” penalty for punctuation usage that's inconsistent with the language model.
  • wordrec_enable_assoc (bool, default: 1) [Legacy] โ€” enables the associator, which considers combinations of character fragments when forming word hypotheses. Turning it off might speed things up, but you pay for it in accuracy on fragmented characters. Trade-offs, bestie ๐Ÿ’€

๐Ÿซถ DEBUG PARAMETERS ๐Ÿซถ

  • debug_file (string, default: "") [Both] โ€” redirects Tesseract's debug/diagnostic output to this file instead of stderr. Set it to /dev/null (or just use the quiet config file) to suppress all that debug noise entirely.
  • tessedit_write_params_to_file (string, default: "") [Both] โ€” if you set this to a filename, Tesseract writes the values of all its parameters to that file when it starts up. So useful for capturing the effective config for debugging or reproducibility. Lowkey a lifesaver.

๐ŸŒธ ENVIRONMENT VARIABLES ๐ŸŒธ

  • TESSDATA_PREFIX โ€” if TESSDATA_PREFIX is set to a path, then that path gets used to find the tessdata directory with the language and script recognition models and config files. Using --tessdata-dir PATH is the recommended alternative though.
  • OMP_THREAD_LIMIT โ€” if the tesseract executable was built with multithreading support, it normally uses four CPU cores for the OCR process. That can be faster for a single image, but it gives bad performance if the host computer has less than four CPU cores or if you're doing OCR on many images. Only a single CPU core is used with OMP_THREAD_LIMIT=1.

๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

Okay storytime, because this engine has lore.

The engine was developed at Hewlett Packard Laboratories Bristol and at Hewlett Packard Co, Greeley Colorado between 1985 and 1994, with some more changes made in 1996 to port to Windows, and some C++izing in 1998. A lot of the code was written in C, and then some more was written in C++. The C++ code makes heavy use of a list system using macros. This predates STL, was portable before STL, and is more efficient than STL lists โ€” but it has the big negative that if you do get a segmentation violation, it is hard to debug. Not me crying over segfaults ๐Ÿ’€

Version 2.00 brought Unicode (UTF-8) support, six languages, and the ability to train Tesseract.

Tesseract was included in UNLV's Fourth Annual Test of OCR Accuracy. See https://github.com/tesseract-ocr/docs/blob/main/AT-1995.pdf. Since Tesseract 2.00, scripts are now included so literally anyone can reproduce some of these tests. See https://tesseract-ocr.github.io/tessdoc/TestingTesseract.html for more details.

Tesseract 3.00 added a bunch of new languages, including Chinese, Japanese, and Korean. It also introduced a new, single-file based system of managing language data.

Tesseract 3.02 added BiDirectional text support, the ability to recognize multiple languages in a single image, and improved layout analysis.

Tesseract 4 adds a new neural net (LSTM) based OCR engine which is focused on line recognition, but it also still supports the legacy Tesseract OCR engine of Tesseract 3 which works by recognizing character patterns. Compatibility with Tesseract 3 is enabled by --oem 0. This also needs traineddata files which support the legacy engine, for example those from the tessdata repository (https://github.com/tesseract-ocr/tessdata).

For further details, see the release notes in the Tesseract documentation (https://tesseract-ocr.github.io/tessdoc/ReleaseNotes.html).

๐Ÿฆ‹ RESOURCES ๐Ÿฆ‹

๐Ÿ’œ SEE ALSO ๐Ÿ’œ

ambiguous_words(1), cntraining(1), combine_tessdata(1), dawg2wordlist(1), shape_training(1), mftraining(1), unicharambigs(5), unicharset(5), unicharset_extractor(1), wordlist2dawg(1)

Go read them, bestie, they're all part of the same friend group โœจ

๐ŸŽ€ AUTHOR ๐ŸŽ€

Tesseract development was led at Hewlett-Packard and Google by Ray Smith. The development team has included:

Ahmad Abdulkader, Chris Newton, Dan Johnson, Dar-Shyang Lee, David Eger, Eric Wiseblatt, Faisal Shafait, Hiroshi Takenaka, Joe Liu, Joern Wanke, Mark Seaman, Mickey Namiki, Nicholas Beato, Oded Fuhrmann, Phil Cheatle, Pingping Xiu, Pong Eksombatchai (Chantat), Ranjith Unnikrishnan, Raquel Romano, Ray Smith, Rika Antonova, Robert Moss, Samuel Charron, Sheelagh Lloyd, Shobhit Saxena, and Thomas Kielbus.

For a list of contributors see https://github.com/tesseract-ocr/tesseract/blob/main/AUTHORS.

โญ COPYING โญ

Licensed under the Apache License, Version 2.0


And that's the whole page, bestie ๐Ÿ’– This is TESSERACT(1) โ€” source and version stamped 2026-09-28 in the footer, dated the same day. Now go OCR something iconic. Slay ๐Ÿซถโœจ
๐Ÿ“ฆ where this page comes from