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)}')
本文来自博客园,作者:chuangzhou,转载请注明原文链接:https://www.cnblogs.com/czzz/p/16920474.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!