tesseract.1.asc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. TESSERACT(1)
  2. ============
  3. :doctype: manpage
  4. NAME
  5. ----
  6. tesseract - command-line OCR engine
  7. SYNOPSIS
  8. --------
  9. *tesseract* 'FILE' 'OUTPUTBASE' ['OPTIONS']... ['CONFIGFILE']...
  10. DESCRIPTION
  11. -----------
  12. tesseract(1) is a commercial quality OCR engine originally developed at HP
  13. between 1985 and 1995. In 1995, this engine was among the top 3 evaluated by
  14. UNLV. It was open-sourced by HP and UNLV in 2005, and has been developed
  15. at Google until 2018.
  16. IN/OUT ARGUMENTS
  17. ----------------
  18. 'FILE'::
  19. The name of the input file.
  20. This can either be an image file or a text file. +
  21. Most image file formats (anything readable by Leptonica) are supported. +
  22. A text file lists the names of all input images (one image name per line).
  23. The results will be combined in a single file for each output file format
  24. (txt, pdf, hocr, xml). +
  25. If 'FILE' is `stdin` or `-` then the standard input is used.
  26. 'OUTPUTBASE'::
  27. The basename of the output file (to which the appropriate extension
  28. will be appended). By default the output will be a text file
  29. with `.txt` added to the basename unless there are one or more
  30. parameters set which explicitly specify the desired output. +
  31. If 'OUTPUTBASE' is `stdout` or `-` then the standard output is used.
  32. [[TESSDATADIR]]
  33. OPTIONS
  34. -------
  35. *-c* 'CONFIGVAR=VALUE'::
  36. Set value for parameter 'CONFIGVAR' to VALUE. Multiple *-c* arguments are allowed.
  37. *--dpi* 'N'::
  38. Specify the resolution 'N' in DPI for the input image(s).
  39. A typical value for 'N' is `300`. Without this option,
  40. the resolution is read from the metadata included in the image.
  41. If an image does not include that information, Tesseract tries to guess it.
  42. *-l* 'LANG'::
  43. *-l* 'SCRIPT'::
  44. The language or script to use.
  45. If none is specified, `eng` (English) is assumed.
  46. Multiple languages may be specified, separated by plus characters.
  47. Tesseract uses 3-character ISO 639-2 language codes
  48. (see <<LANGUAGES,*LANGUAGES AND SCRIPTS*>>).
  49. *--psm* 'N'::
  50. Set Tesseract to only run a subset of layout analysis and assume
  51. a certain form of image. The options for 'N' are:
  52. 0 = Orientation and script detection (OSD) only.
  53. 1 = Automatic page segmentation with OSD.
  54. 2 = Automatic page segmentation, but no OSD, or OCR. (not implemented)
  55. 3 = Fully automatic page segmentation, but no OSD. (Default)
  56. 4 = Assume a single column of text of variable sizes.
  57. 5 = Assume a single uniform block of vertically aligned text.
  58. 6 = Assume a single uniform block of text.
  59. 7 = Treat the image as a single text line.
  60. 8 = Treat the image as a single word.
  61. 9 = Treat the image as a single word in a circle.
  62. 10 = Treat the image as a single character.
  63. 11 = Sparse text. Find as much text as possible in no particular order.
  64. 12 = Sparse text with OSD.
  65. 13 = Raw line. Treat the image as a single text line,
  66. bypassing hacks that are Tesseract-specific.
  67. *--oem* 'N'::
  68. Specify OCR Engine mode. The options for 'N' are:
  69. 0 = Original Tesseract only.
  70. 1 = Neural nets LSTM only.
  71. 2 = Tesseract + LSTM.
  72. 3 = Default, based on what is available.
  73. *--tessdata-dir* 'PATH'::
  74. Specify the location of tessdata path.
  75. *--user-patterns* 'FILE'::
  76. Specify the location of user patterns file.
  77. *--user-words* 'FILE'::
  78. Specify the location of user words file.
  79. [[CONFIGFILE]]
  80. 'CONFIGFILE'::
  81. The name of a config to use. The name can be a file in `tessdata/configs`
  82. or `tessdata/tessconfigs`, or an absolute or relative file path.
  83. A config is a plain text file which contains a list of parameters and
  84. their values, one per line, with a space separating parameter from value. +
  85. Interesting config files include:
  86. * *alto* -- Output in ALTO format ('OUTPUTBASE'`.xml`).
  87. * *hocr* -- Output in hOCR format ('OUTPUTBASE'`.hocr`).
  88. * *page* -- Output in PAGE format ('OUTPUTBASE'`.page.xml`).
  89. The output can be customized with the flags:
  90. page_xml_polygon -- Create polygons instead of bounding boxes (default: true)
  91. page_xml_level -- Create the PAGE file on 0=linelevel or 1=wordlevel (default: 0)
  92. * *pdf* -- Output PDF ('OUTPUTBASE'`.pdf`).
  93. * *tsv* -- Output TSV ('OUTPUTBASE'`.tsv`).
  94. * *txt* -- Output plain text ('OUTPUTBASE'`.txt`).
  95. * *get.images* -- Write processed input images to file ('OUTPUTBASE'`.processedPAGENUMBER.tif`).
  96. * *logfile* -- Redirect debug messages to file (`tesseract.log`).
  97. * *lstm.train* -- Output files used by LSTM training ('OUTPUTBASE'`.lstmf`).
  98. * *makebox* -- Write box file ('OUTPUTBASE'`.box`).
  99. * *quiet* -- Redirect debug messages to '/dev/null'.
  100. It is possible to select several config files, for example
  101. `tesseract image.png demo alto hocr pdf txt` will create four output files
  102. `demo.alto`, `demo.hocr`, `demo.pdf` and `demo.txt` with the OCR results.
  103. *Nota bene:* The options *-l* 'LANG', *-l* 'SCRIPT' and *--psm* 'N'
  104. must occur before any 'CONFIGFILE'.
  105. SINGLE OPTIONS
  106. --------------
  107. *-h, --help*::
  108. Show help message.
  109. *--help-extra*::
  110. Show extra help for advanced users.
  111. *--help-psm*::
  112. Show page segmentation modes.
  113. *--help-oem*::
  114. Show OCR Engine modes.
  115. *-v, --version*::
  116. Returns the current version of the tesseract(1) executable.
  117. *--list-langs*::
  118. List available languages for tesseract engine.
  119. Can be used with *--tessdata-dir* 'PATH'.
  120. *--print-parameters*::
  121. Print tesseract parameters.
  122. [[LANGUAGES]]
  123. LANGUAGES AND SCRIPTS
  124. ---------------------
  125. To recognize some text with Tesseract, it is normally necessary to specify
  126. the language(s) or script(s) of the text (unless it is English text which is
  127. supported by default) using *-l* 'LANG' or *-l* 'SCRIPT'.
  128. Selecting a language automatically also selects the language specific
  129. character set and dictionary (word list).
  130. Selecting a script typically selects all characters of that script
  131. which can be from different languages. The dictionary which is included
  132. also contains a mix from different languages.
  133. In most cases, a script also supports English.
  134. So it is possible to recognize a language that has not been specifically
  135. trained for by using traineddata for the script it is written in.
  136. More than one language or script may be specified by using `+`.
  137. Example: `tesseract myimage.png myimage -l eng+deu+fra`.
  138. https://github.com/tesseract-ocr/tessdata_fast provides fast language and
  139. script models which are also part of Linux distributions.
  140. For Tesseract 4, `tessdata_fast` includes traineddata files for the
  141. following languages:
  142. *afr* (Afrikaans),
  143. *amh* (Amharic),
  144. *ara* (Arabic),
  145. *asm* (Assamese),
  146. *aze* (Azerbaijani),
  147. *aze_cyrl* (Azerbaijani - Cyrilic),
  148. *bel* (Belarusian),
  149. *ben* (Bengali),
  150. *bod* (Tibetan),
  151. *bos* (Bosnian),
  152. *bre* (Breton),
  153. *bul* (Bulgarian),
  154. *cat* (Catalan; Valencian),
  155. *ceb* (Cebuano),
  156. *ces* (Czech),
  157. *chi_sim* (Chinese simplified),
  158. *chi_tra* (Chinese traditional),
  159. *chr* (Cherokee),
  160. *cos* (Corsican),
  161. *cym* (Welsh),
  162. *dan* (Danish),
  163. *deu* (German),
  164. *deu_latf* (German Fraktur Latin),
  165. *div* (Dhivehi),
  166. *dzo* (Dzongkha),
  167. *ell* (Greek, Modern, 1453-),
  168. *eng* (English),
  169. *enm* (English, Middle, 1100-1500),
  170. *epo* (Esperanto),
  171. *equ* (Math / equation detection module),
  172. *est* (Estonian),
  173. *eus* (Basque),
  174. *fas* (Persian),
  175. *fao* (Faroese),
  176. *fil* (Filipino),
  177. *fin* (Finnish),
  178. *fra* (French),
  179. *frm* (French, Middle, ca.1400-1600),
  180. *fry* (West Frisian),
  181. *gla* (Scottish Gaelic),
  182. *gle* (Irish),
  183. *glg* (Galician),
  184. *grc* (Greek, Ancient, to 1453),
  185. *guj* (Gujarati),
  186. *hat* (Haitian; Haitian Creole),
  187. *heb* (Hebrew),
  188. *hin* (Hindi),
  189. *hrv* (Croatian),
  190. *hun* (Hungarian),
  191. *hye* (Armenian),
  192. *iku* (Inuktitut),
  193. *ind* (Indonesian),
  194. *isl* (Icelandic),
  195. *ita* (Italian),
  196. *ita_old* (Italian - Old),
  197. *jav* (Javanese),
  198. *jpn* (Japanese),
  199. *kan* (Kannada),
  200. *kat* (Georgian),
  201. *kat_old* (Georgian - Old),
  202. *kaz* (Kazakh),
  203. *khm* (Central Khmer),
  204. *kir* (Kirghiz; Kyrgyz),
  205. *kmr* (Kurdish Kurmanji),
  206. *kor* (Korean),
  207. *kor_vert* (Korean vertical),
  208. *lao* (Lao),
  209. *lat* (Latin),
  210. *lav* (Latvian),
  211. *lit* (Lithuanian),
  212. *ltz* (Luxembourgish),
  213. *mal* (Malayalam),
  214. *mar* (Marathi),
  215. *mkd* (Macedonian),
  216. *mlt* (Maltese),
  217. *mon* (Mongolian),
  218. *mri* (Maori),
  219. *msa* (Malay),
  220. *mya* (Burmese),
  221. *nep* (Nepali),
  222. *nld* (Dutch; Flemish),
  223. *nor* (Norwegian),
  224. *oci* (Occitan post 1500),
  225. *ori* (Oriya),
  226. *osd* (Orientation and script detection module),
  227. *pan* (Panjabi; Punjabi),
  228. *pol* (Polish),
  229. *por* (Portuguese),
  230. *pus* (Pushto; Pashto),
  231. *que* (Quechua),
  232. *ron* (Romanian; Moldavian; Moldovan),
  233. *rus* (Russian),
  234. *san* (Sanskrit),
  235. *sin* (Sinhala; Sinhalese),
  236. *slk* (Slovak),
  237. *slv* (Slovenian),
  238. *snd* (Sindhi),
  239. *spa* (Spanish; Castilian),
  240. *spa_old* (Spanish; Castilian - Old),
  241. *sqi* (Albanian),
  242. *srp* (Serbian),
  243. *srp_latn* (Serbian - Latin),
  244. *sun* (Sundanese),
  245. *swa* (Swahili),
  246. *swe* (Swedish),
  247. *syr* (Syriac),
  248. *tam* (Tamil),
  249. *tat* (Tatar),
  250. *tel* (Telugu),
  251. *tgk* (Tajik),
  252. *tha* (Thai),
  253. *tir* (Tigrinya),
  254. *ton* (Tonga),
  255. *tur* (Turkish),
  256. *uig* (Uighur; Uyghur),
  257. *ukr* (Ukrainian),
  258. *urd* (Urdu),
  259. *uzb* (Uzbek),
  260. *uzb_cyrl* (Uzbek - Cyrilic),
  261. *vie* (Vietnamese),
  262. *yid* (Yiddish),
  263. *yor* (Yoruba)
  264. To use a non-standard language pack named `foo.traineddata`, set the
  265. `TESSDATA_PREFIX` environment variable so the file can be found at
  266. `TESSDATA_PREFIX/tessdata/foo.traineddata` and give Tesseract the
  267. argument *-l* `foo`.
  268. For Tesseract 4, `tessdata_fast` includes traineddata files for the
  269. following scripts:
  270. *Arabic*,
  271. *Armenian*,
  272. *Bengali*,
  273. *Canadian_Aboriginal*,
  274. *Cherokee*,
  275. *Cyrillic*,
  276. *Devanagari*,
  277. *Ethiopic*,
  278. *Fraktur*,
  279. *Georgian*,
  280. *Greek*,
  281. *Gujarati*,
  282. *Gurmukhi*,
  283. *HanS* (Han simplified),
  284. *HanS_vert* (Han simplified, vertical),
  285. *HanT* (Han traditional),
  286. *HanT_vert* (Han traditional, vertical),
  287. *Hangul*,
  288. *Hangul_vert* (Hangul vertical),
  289. *Hebrew*,
  290. *Japanese*,
  291. *Japanese_vert* (Japanese vertical),
  292. *Kannada*,
  293. *Khmer*,
  294. *Lao*,
  295. *Latin*,
  296. *Malayalam*,
  297. *Myanmar*,
  298. *Oriya* (Odia),
  299. *Sinhala*,
  300. *Syriac*,
  301. *Tamil*,
  302. *Telugu*,
  303. *Thaana*,
  304. *Thai*,
  305. *Tibetan*,
  306. *Vietnamese*.
  307. The same languages and scripts are available from
  308. https://github.com/tesseract-ocr/tessdata_best.
  309. `tessdata_best` provides slow language and script models.
  310. These models are needed for training. They also can give better OCR results,
  311. but the recognition takes much more time.
  312. Both `tessdata_fast` and `tessdata_best` only support the LSTM OCR engine.
  313. There is a third repository, https://github.com/tesseract-ocr/tessdata,
  314. with models which support both the Tesseract 3 legacy OCR engine and the
  315. Tesseract 4 LSTM OCR engine.
  316. CONFIG FILES AND AUGMENTING WITH USER DATA
  317. ------------------------------------------
  318. Tesseract config files consist of lines with parameter-value pairs (space
  319. separated). The parameters are documented as flags in the source code like
  320. the following one in tesseractclass.h:
  321. `STRING_VAR_H(tessedit_char_blacklist, "",
  322. "Blacklist of chars not to recognize");`
  323. These parameters may enable or disable various features of the engine, and
  324. may cause it to load (or not load) various data. For instance, let's suppose
  325. you want to OCR in English, but suppress the normal dictionary and load an
  326. alternative word list and an alternative list of patterns -- these two files
  327. are the most commonly used extra data files.
  328. If your language pack is in '/path/to/eng.traineddata' and the hocr config
  329. is in '/path/to/configs/hocr' then create three new files:
  330. '/path/to/eng.user-words':
  331. [verse]
  332. the
  333. quick
  334. brown
  335. fox
  336. jumped
  337. '/path/to/eng.user-patterns':
  338. [verse]
  339. 1-\d\d\d-GOOG-411
  340. www.\n\\\*.com
  341. '/path/to/configs/bazaar':
  342. [verse]
  343. load_system_dawg F
  344. load_freq_dawg F
  345. user_words_suffix user-words
  346. user_patterns_suffix user-patterns
  347. Now, if you pass the word 'bazaar' as a <<CONFIGFILE,'CONFIGFILE'>> to
  348. Tesseract, Tesseract will not bother loading the system dictionary nor
  349. the dictionary of frequent words and will load and use the 'eng.user-words'
  350. and 'eng.user-patterns' files you provided. The former is a simple word list,
  351. one per line. The format of the latter is documented in 'dict/trie.h'
  352. on 'read_pattern_list()'.
  353. ENVIRONMENT VARIABLES
  354. ---------------------
  355. *`TESSDATA_PREFIX`*::
  356. If the `TESSDATA_PREFIX` is set to a path, then that path is used to
  357. find the `tessdata` directory with language and script recognition
  358. models and config files.
  359. Using <<TESSDATADIR,*--tessdata-dir* 'PATH'>> is the recommended alternative.
  360. *`OMP_THREAD_LIMIT`*::
  361. If the `tesseract` executable was built with multithreading support,
  362. it will normally use four CPU cores for the OCR process. While this
  363. can be faster for a single image, it gives bad performance if the host
  364. computer provides less than four CPU cores or if OCR is made for many images.
  365. Only a single CPU core is used with `OMP_THREAD_LIMIT=1`.
  366. HISTORY
  367. -------
  368. The engine was developed at Hewlett Packard Laboratories Bristol and at
  369. Hewlett Packard Co, Greeley Colorado between 1985 and 1994, with some more
  370. changes made in 1996 to port to Windows, and some $$C++$$izing in 1998. A
  371. lot of the code was written in C, and then some more was written in $$C++$$.
  372. The $$C++$$ code makes heavy use of a list system using macros. This predates
  373. STL, was portable before STL, and is more efficient than STL lists, but has
  374. the big negative that if you do get a segmentation violation, it is hard to
  375. debug.
  376. Version 2.00 brought Unicode (UTF-8) support, six languages, and the ability
  377. to train Tesseract.
  378. Tesseract was included in UNLV's Fourth Annual Test of OCR Accuracy.
  379. See <https://github.com/tesseract-ocr/docs/blob/main/AT-1995.pdf>.
  380. Since Tesseract 2.00,
  381. scripts are now included to allow anyone to reproduce some of these tests.
  382. See <https://tesseract-ocr.github.io/tessdoc/TestingTesseract.html> for more
  383. details.
  384. Tesseract 3.00 added a number of new languages, including Chinese, Japanese,
  385. and Korean. It also introduced a new, single-file based system of managing
  386. language data.
  387. Tesseract 3.02 added BiDirectional text support, the ability to recognize
  388. multiple languages in a single image, and improved layout analysis.
  389. Tesseract 4 adds a new neural net (LSTM) based OCR engine which is focused
  390. on line recognition, but also still supports the legacy Tesseract OCR engine of
  391. Tesseract 3 which works by recognizing character patterns. Compatibility with
  392. Tesseract 3 is enabled by `--oem 0`. This also needs traineddata files which
  393. support the legacy engine, for example those from the tessdata repository
  394. (https://github.com/tesseract-ocr/tessdata).
  395. For further details, see the release notes in the Tesseract documentation
  396. (<https://tesseract-ocr.github.io/tessdoc/ReleaseNotes.html>).
  397. RESOURCES
  398. ---------
  399. Main web site: <https://github.com/tesseract-ocr> +
  400. User forum: <https://groups.google.com/g/tesseract-ocr> +
  401. Documentation: <https://tesseract-ocr.github.io/> +
  402. Information on training: <https://tesseract-ocr.github.io/tessdoc/Training-Tesseract.html>
  403. SEE ALSO
  404. --------
  405. ambiguous_words(1), cntraining(1), combine_tessdata(1), dawg2wordlist(1),
  406. shape_training(1), mftraining(1), unicharambigs(5), unicharset(5),
  407. unicharset_extractor(1), wordlist2dawg(1)
  408. AUTHOR
  409. ------
  410. Tesseract development was led at Hewlett-Packard and Google by Ray Smith.
  411. The development team has included:
  412. Ahmad Abdulkader, Chris Newton, Dan Johnson, Dar-Shyang Lee, David Eger,
  413. Eric Wiseblatt, Faisal Shafait, Hiroshi Takenaka, Joe Liu, Joern Wanke,
  414. Mark Seaman, Mickey Namiki, Nicholas Beato, Oded Fuhrmann, Phil Cheatle,
  415. Pingping Xiu, Pong Eksombatchai (Chantat), Ranjith Unnikrishnan, Raquel
  416. Romano, Ray Smith, Rika Antonova, Robert Moss, Samuel Charron, Sheelagh
  417. Lloyd, Shobhit Saxena, and Thomas Kielbus.
  418. For a list of contributors see
  419. <https://github.com/tesseract-ocr/tesseract/blob/main/AUTHORS>.
  420. COPYING
  421. -------
  422. Licensed under the Apache License, Version 2.0