python 图像识别转文字

rom PIL import Image
import pytesseract
#上面都是导包,只需要下面这一行就能实现图片文字识别
#text=pytesseract.image_to_string(Image.open('1531730550.jpg'),lang='chi_sim') #设置为中文文字的识别
image = Image.open('1531733536(1).jpg')
code = pytesseract.image_to_string(image)   #设置为英文或阿拉伯字母的识别
print(code)

1、需要导入pillow,pytesseract

pip3 install pillow
pip3 install pytesseract

2、需要安装Tesseract-OCR,如需要转为中文,则需要中文补丁

测试是否安装成功:cmd输入tesseract -v

 

上图则表示成功安装

3、简单演示(复杂的图片可能识别不出)

原文地址:https://www.cnblogs.com/wang666/p/9318947.html