Windows环境下使用pytesseract识别图片验证码

本文指导如何安装tesseract和tesserocr,包括从特定网址下载软件和语言包,并配置环境变量。接着介绍了如何通过pip安装pytesseract,以及使用tesseract命令行工具进行基本操作,如查看可用语言和帮助信息。最后展示了pytesseract在Python中的用法,用于识别图像中的文字,包括指定语言、获取边界框和详细数据等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装tesserocr前应先安装tesseract,tesserocr和tesseract安装时,必须安装对应版本

参考博客:

https://blog.csdn.net/qq_41895190/article/details/82696550

https://www.cnblogs.com/zhangxinqi/p/9297292.html#_label2

1.tesseract下载地址:

https://digi.bib.uni-mannheim.de/tesseract/

2.下载语言包太慢,可以直接从Github上下载zip的语言包压缩文件,解压后将tessdata-master中的文件复制到Tesseract的安装目录中的tessdata下,tesseract-ocr语言包下载地址:

https://github.com/tesseract-ocr/tessdata

3.配置环境变量,将C:\Program Files (x86)\Tesseract-OCR添加到环境变量中

4.安装pytesseract

pip install pytesseract

5.tesseract命令

#显示安装的语言包
tesseract --list-langs

#显示帮助
tesseract --help
tesseract --help-extra
tesseract --version

6.使用pytessercat识别验证码

from PIL import Image
import pytesseract

# 如果PATH中没有tesseract可执行文件,请指定tesseract路径
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\01403087\AppData\Local\Tesseract-OCR\tesseract.exe"

# 打印识别的图像的字符串
print(pytesseract.image_to_string(Image.open('test.png')))

# 指定语言识别图像字符串,eng为英语
print(pytesseract.image_to_string(Image.open('test.png'), lang='eng'))

# 获取图像边界框
print(pytesseract.image_to_boxes(Image.open('test.png')))

# 获取包含边界框,置信度,行和页码的详细数据
print(pytesseract.image_to_data(Image.open('test.png')))

# 获取方向和脚本检测
print(pytesseract.image_to_osd(Image.open('test.png')))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值