0
点赞
收藏
分享

微信扫一扫

python ocr使用

言午栩 2022-06-27 阅读 36
pip install pillow
pip install pytesseract
pip install tesseract-ocr## 若安装失败去下载http://jaist.dl.sourceforge.net/project/tesseract-ocr-alt/
USAGE
try:
import Image
except ImportError:
from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = '<full_path_to_your_tesseract_executable>'
# Include the above line, if you don't have tesseract executable in your PATH
# Example tesseract_cmd: 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))
Add the following config, if you have tessdata error like: “Error opening data file…”

tessdata_dir_config = '--tessdata-dir "<replace_with_your_tessdata_dir_path>"'
# Example config: '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
# It's important to add double quotes around the dir path.若该目录下没有chi_sim.traineddata则去http://jaist.dl.sourceforge.net/project/tesseract-ocr-alt/

pytesseract.image_to_string(image, lang='chi_sim', config=tessdata_dir_config)

 


举报

相关推荐

0 条评论