python3 识别图片文字
1、下载相关组件
安装:pip install Pillow 或下载:https://pypi.org/project/Pillow/5.2.0/ ,https://pypi.org/project/Pillow/5.2.0/#files,Pillow-5.2.0-cp36-cp36m-win_amd64.whl
下载后:在C:\Python36\Scripts目录下:pip install Pillow-5.2.0-cp36-cp36m-win_amd64.whl
安装:pip3 install pytesseract 或下载安装:pytesseract-0.2.4.tar.gz 或 https://pypi.org/project/pytesseract/#files
下载:tesseract-ocr-w64-setup-v4.0.0-beta.1.20180608.exe 安装,参见:图片文字OCR识别-tesseract-ocr
2、实例程序
#coding:utf8import os
from PIL import Image
import pytesseract
file=r"D:\work\python36_crawl\pictureParser\中文.png"
# file=r"D:\work\python36_crawl\pictureParser\英文.png"
if os.path.exists(file):
image = Image.open(file)
# 英文
# vcode = pytesseract.image_to_string(image,"eng")
vcode = pytesseract.image_to_string(image, "chi_sim")
print(vcode)
验证码相关链接:https://zhuanlan.zhihu.com/p/30871712
以上是 python3 识别图片文字 的全部内容, 来源链接: utcz.com/z/387974.html