Python - tesserocr

安装

教程:https://cuiqingcai.com/31102.html

自己在安装过程中遇到的错误:

RuntimeError: Tesseract library not found in LIBPATH: []

可以直接使用whl 文件来安装:
1.下载whl文件地址:https://github.com/simonflueckiger/tesserocr-windows_build/releases

2.复制文件到项目venv/Scripts文件路径下

3.pip install tesserocr-2.5.2-cp310-cp310-win_amd64.whl

识别验证码

# 方式一:
image = Image.open('test.png')
print(f'image type:{type(image)}') # out:image type:<class 'PIL.PngImagePlugin.PngImageFile'>
test = tesserocr.image_to_text(image)
print(test) # out:. f.4 3._1.-.

# 方式二:
print(tesserocr.file_to_text('test.png'))   #out: . f.4 3._1.-.

发现并不是想要的图片验证码,因此需要进一步处理:
整体正确率不高

image = Image.open('test3.png')
image = image.convert('L')
threshold = 50  # 英文 threshold:阀,门槛的意思
array = np.array(image)
array = np.where(array > threshold, 255, 0)
image = Image.fromarray(array.astype('uint8'))
print(f'result:{tesserocr.image_to_text(image)}')

posted @   chuangzhou  阅读(490)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示