乐趣区

关于python:mac-安装tesseract与pytesseract使用

tesseract 装置配置

装置依赖

brew install automake autoconf libtool
brew install pkgconfig
brew install icu4c
brew install leptonica

# Packages required for training tools.
brew install pango

# Optional packages for extra features.
brew install libarchive

# Optional package for builds using g++.
brew install gcc

下载解压 tesseract

tesseract

编译装置

cd tesseract-4.1.1
./autogen.sh
mkdir build
cd build

# Optionally add CXX=g++-8 to the configure command if you really want to use a different compiler.
../configure PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/libarchive/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig
make -j

# Optionally install Tesseract.
sudo make install

# Optionally build and install training tools.
make training
sudo make training-install

下载 eng.traineddata

eng.traineddata
这里只有下载其中的 eng.traineddata 就行了,如果须要其余的语言则按需下载,不须要全副都下载了,全副下载的话 3g 左右,比拟大。

测试

$ tesseract 0384.jpg stdout
0 3 8 4

看报错门路,把 eng.traineddata 文件拷贝到缺失门路下,再次测试

pytesseract 应用

参考

依赖包装置

pip install pytesseract

导入应用

import pytesseract as pt
from PIL import Image
image = Image.open('0384.jpeg')
text = pt.image_to_string(image)
print(text)
退出移动版