https://digi.bib.uni-mannheim.de/tesseract/
链接:https://pan.baidu.com/s/1CLPSf2TahIGaeL7zRCTQDg
提取码:x0kn
3.1配置TESSDATA_PREFIX变量
3.2配置Path变量
C:\Users\特昂糖>tesseract -v tesseract 4.00.00alpha leptonica-1.74.1 libgif 4.1.6(?) : libjpeg 8d (libjpeg-turbo 1.5.0) : libpng 1.6.20 : libtiff 4.0.6 : zlib 1.2.8 : libwebp 0.4.3 : libopenjp2 2.1.0
tesseract --list-langs
命令可查看当前软件支持的语言C:\Users\特昂糖> tesseract --list-langs List of available languages (2): eng osd
到https://github.com/tesseract-ocr/tessdata下载需要的的语言包,如下图,红框内为中文简体语言包,下载后将该包直接放在程序安装目录的tessdata
文件夹里面即可。
安装命令:pip install pytesseract
C:\特昂糖>pip install pytesseract WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) Collecting pytesseract Using cached pytesseract-0.3.9-py2.py3-none-any.whl (14 kB) Collecting Pillow>=8.0.0 Downloading Pillow-9.1.0-cp39-cp39-win_amd64.whl (3.3 MB) ---------------------------------------- 0.0/3.3 MB ? eta -:--:-- ERROR: Operation cancelled by user WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages)
因为网络缘故下载不下来,用国内的源下载:
C:\Users\特昂糖>pip install pytesseract -i https://pypi.douban.com/simple WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) Looking in indexes: https://pypi.douban.com/simple Collecting pytesseract Downloading https://pypi.doubanio.com/packages/8b/0d/6efe2a9bddf1b1efe82a86fdd057f4affaeebd14347f32d03bbbbc45821c/pytesseract-0.3.9-py2.py3-none-any.whl (14 kB) Collecting Pillow>=8.0.0 Downloading https://pypi.doubanio.com/packages/a1/ce/d3bf90ccf0c32dfd24ab88d8aaa84fb7c08a339803ed679d809b92a3e41a/Pillow-9.1.0-cp39-cp39-win_amd64.whl (3.3 MB) ---------------------------------------- 3.3/3.3 MB 3.2 MB/s eta 0:00:00 Requirement already satisfied: packaging>=21.3 in f:\python3\lib\site-packages (from pytesseract) (21.3) Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in f:\python3\lib\site-packages (from packaging>=21.3->pytesseract) (3.0.6) WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) Installing collected packages: Pillow, pytesseract WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) Successfully installed Pillow-9.1.0 pytesseract-0.3.9 WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages) WARNING: Ignoring invalid distribution -ip (f:\python3\lib\site-packages)
import pytesseract from PIL import Image file=r'F:/png/db63fc936bb07673a375423ce2d2cf8.png' image=Image.open(file) print(pytesseract.image_to_string(image,lang='chi_sim'))
输出结果:
元 日 王 安 石 ( 宋 代 爆 竹 声 中 一 岁 除 , 春 风 送 暖 入 属 苏 。 干 门 万 户 瞳 嘻 日 , 总 把 新 桃 换 旧 符 。