python-OCR图片识别库--tesserocr

1 介绍

OCR,即Optical Character Recognition,光学字符识别,是指通过扫描字符,然后通过其形状将其翻译成电子文本的过程。对于图形验证码来说,它们都是一些不规则的字符,这些字符确实是由字符稍加扭曲变换得到的内容。

2. 条件

tesserocr 安装之前必须安装 tesseract

相关链接:

相关学习信息:

  1. Python tesserocr模块使用示例
  2. win10下安装tesserocr失败(问题已解决,见文末)

3. 安装出现的问题

查看安装 tesseract-ocr 和 tesserocr 以及出现的问题

print(pip._internal.pep425tags.get_supported())

[('cp37', 'cp37m', 'win32'), ('cp37', 'none', 'win32'), ('py3', 'none', 'win32'), ('cp37', 'none', 'any'), ('cp
3', 'none', 'any'), ('py37', 'none', 'any'), ('py3', 'none', 'any'), ('py36', 'none', 'any'), ('py35', 'none',
'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('p
y30', 'none', 'any')]

原来是py37, win32

通过pip3 install tesserocr-2.2.2-cp36-cp36m-win32.whl, 在window 上 还是报错。

4. 解决tesseract安装问题

  • 官方推荐:
Installation
Windows
The proposed downloads consist of stand-alone packages containing all the Windows libraries needed for execution. This means that no additional installation of tesseract is required on your system.
#### pip

Download the wheel file corresponding to your Windows platform and Python installation from [simonflueckiger/tesserocr-windows_build/releases](https://github.com/simonflueckiger/tesserocr-windows_build/releases) and install them via:
pip install <package_name>.whl

这里的package_name, 是从(https://github.com/sirfz/tesserocr/releases)
下载的,对应自己的版本与环境。

下载之后,安装之后,调试代码还是报错

File "tesserocr.pyx", line 2401, in tesserocr._tesserocr.image_to_textRuntimeError: Failed to init API, possibly an invalid tessdata path: C:\\

NO
原因: :stand-alone packages 虽然包含了 Windows 下所需的所有库,但并是不包含语言数据文件(language data files)。并且数据文件需要被统一放置在 tessdata\ 文件夹中,并置于 C:\Python36 内。

  • 实践
    无需安装 tesseract ,只需克隆 tesseract 仓库的主分支,然后将其中的 tessdata\ 文件夹复制到 Python36\中。接下来,通过 tessdata_fast 仓库下载 eng.traineddata 语言文件,并放置于 tessdata\ 内即可。
image.png
  • 代码
from PIL import Image
import tesserocr

image = Image.open('./photo/image.jpg')
result = tesserocr.image_to_text(image)
print(result)

# 有些读取不出,需要二值化去杂

PS: 若你觉得可以、还行、过得去、甚至不太差的话,可以“关注或点赞”一下,就此谢过!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    小迈克阅读 3,129评论 1 3
  • 第一步安装 Tesserocr的安装爬虫过程中难免会遇到各种各样的验证码,而大多数验证码还是图形验证码,这时候我们...
    何苦_python_java阅读 8,679评论 0 1
  • 转载请注明出处:https://www.jianshu.com/u/5e6f798c903a 环境:Win10_6...
    import_hello阅读 7,025评论 1 6
  • 在爬虫过程中,难免会遇到各种各样的验证码,而大多数验证码还是图形验证码,这时候我们可以直接用OCR来识别。 1. ...
    Einbahn_2018阅读 8,116评论 1 2
  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,343评论 0 3

友情链接更多精彩内容