python OCR 图片识别之pytesseract
Python比较吸引人的一点就是有丰富的第三方库,图像、数据、机器学习、优化算法、图、UI.......你能想到的,Python可能都会找到第三方库,ocr也不例外。
这里要推荐的库就是pytesseract
,你可以像调用numpy、matplotlib、tensorflow那样直接在Python代码中调用pytesseract,实现图像文字的识别。

pip install pytesseract
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
# 简单的把图像转化成文字
print(pytesseract.image_to_string(Image.open(''test.png'')))
# 指定图像中的语言
print(pytesseract.image_to_string(Image.open('test-european.jpg'),lang = 'fra'))


pytesseract支持Python 2.7或者3.5+,需要用到PIL或者pillow。这里比较重要的是,还需要安装tesseract后端引擎。
因此,在使用pytesseract之前,需要在windows、Linux或者mac上安装tesseract。

最后修改:2022 年 12 月 05 日
如果觉得我的文章对你有用,请随意赞赏