首页 > 编程语言 >python使用 pytesseract + tesseract-ocr 进行验证码识别

python使用 pytesseract + tesseract-ocr 进行验证码识别

时间:2023-03-18 14:22:44浏览次数:36  
标签:tesseract python image 验证码 识别 pytesseract ocr

使用 pytesseract + tesseract-ocr 进行验证码识别,需要安装的第三方库:pytesseract 、tesseract-ocr,在使用pytesseract 之前,必须安装tesseract-ocr,因为 pytesseract 依赖于tesseract-ocr,否则无法使用。

1、tesseract-ocr下载安装与配置:tesseract-ocr下载安装与配置

2、pytesseract 安装:pip install pytesseract

3、修改pytesseract.py脚本

在python的安装目录下找到pytesseract 的安装路径,在pytesseract 文件夹下的pytesseract.py脚本中,用记事本打开pytesseract.py,通过ctrl+f快速搜索功能定位tesseract_cmd,修改后面的文件路径。

4、用pytesseract识别验证码

from PIL import Image
import pytesseract

# 用pytesseract识别验证码
# 1:打开需要识别的图片
image = Image.open(r'image\code.png')
# 2:pytesseract识别为字符串
code = pytesseract.image_to_string(image)
# 3:输出识别的内容
print(code)

标签:tesseract,python,image,验证码,识别,pytesseract,ocr
From: https://www.cnblogs.com/henuyuxiang/p/17230555.html

相关文章