OCR (Optical character recognition) is a technology that converts handwritten or printed text in images into machine-encoded text.
tesseract-ocr is developed by Google and supports more than 100 languages
Document tessdoc:
https://tesseract-ocr.github.io/
https://tesseract-ocr.github.io/tessdoc/Installation.html
https://github.com/tesseract-ocr/tessdoc
Windows Tesseract download address: https://digi.bib.uni-mannheim.de/tesseract/
Select tesseract-ocr-w64-setup-v5.0.1.20220118.exe
If checked, Additional...
the training data will be downloaded, installed D:\Tesseract-OCR
, and D:\Tesseract-OCR
added to the environment variables.
C:\Users\Administrator.DESKTOP-TPJL4TC>tesseract
Usage:
tesseract --help | --help-extra | --version
tesseract --list-langs
tesseract imagename outputbase [options...] [configfile...]
OCR options:
-l LANG[+LANG] Specify language(s) used for OCR.
NOTE: These options must occur before any configfile.
Single options:
--help Show this help message.
--help-extra Show extra help for advanced users.
--version Show version information.
--list-langs List available languages for tesseract engine.
C:\Users\Administrator.DESKTOP-TPJL4TC>tesseract --version
tesseract v5.0.1.20220118
leptonica-1.78.0
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
Found AVX2
Found AVX
Found FMA
Found SSE4.1
Found libarchive 3.5.0 zlib/1.2.11 liblzma/5.2.3 bz2lib/1.0.6 liblz4/1.7.5 libzstd/1.4.5
Found libcurl/7.77.0-DEV Schannel zlib/1.2.11 zstd/1.4.5 libidn2/2.0.4 nghttp2/1.31.0
View supported language packs
tesseract --list-langs
If you forget to check the training data, you can also download it separately https://digi.bib.uni-mannheim.de/tesseract/tessdata_fast/ and put it D:\Tesseract-OCR\tessdata
in the directory
Recognize text in pictures, by default only English and numbers can be recognized
tesseract 图片地址 存放识别结果的文本文件路径
比如
tesseract D:\dev\php\magook\trunk\server\go-opencv\detectcarband\licence_plate.jpg D:\dev\php\magook\trunk\server\go-opencv\detectcarband\licence_plate
If you want to recognize Chinese, you need to add the language pack name
tesseract D:\dev\php\magook\trunk\server\go-opencv\detectcarband\licence_plate.jpg D:\dev\php\magook\trunk\server\go-opencv\detectcarband\licence_plate -l chi_sim
In fact, it is not very accurate. For example, the following license plate
The recognition result is外.730V7
C:\Users\Administrator.DESKTOP-TPJL4TC> tesseract --help-extra
Usage:
tesseract --help | --help-extra | --help-psm | --help-oem | --version
tesseract --list-langs [--tessdata-dir PATH]
tesseract --print-fonts-table [options...] [configfile...]
tesseract --print-parameters [options...] [configfile...]
tesseract imagename|imagelist|stdin outputbase|stdout [options...] [configfile...]
OCR options:
--tessdata-dir PATH Specify the location of tessdata path.
--user-words PATH Specify the location of user words file.
--user-patterns PATH Specify the location of user patterns file.
--dpi VALUE Specify DPI for input image.
--loglevel LEVEL Specify logging level. LEVEL can be
ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL or OFF.
-l LANG[+LANG] Specify language(s) used for OCR.
-c VAR=VALUE Set value for config variables.
Multiple -c arguments are allowed.
--psm NUM Specify page segmentation mode.
--oem NUM Specify OCR Engine mode.
NOTE: These options must occur before any configfile.
Page segmentation modes:
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.
OCR Engine modes:
0 Legacy engine only.
1 Neural nets LSTM engine only.
2 Legacy + LSTM engines.
3 Default, based on what is available.
Single options:
-h, --help Show minimal help message.
--help-extra Show extra help for advanced users.
--help-psm Show page segmentation modes.
--help-oem Show OCR Engine modes.
-v, --version Show version information.
--list-langs List available languages for tesseract engine.
--print-fonts-table Print tesseract fonts table.
--print-parameters Print tesseract parameters.