• Tesseract pytesseract的安装和使用


    Tesseract是开源的OCR引擎,可以识别的图片里的文字,支持unicode(UTF-8)编码,100多种语言,需要下载相应语言的训练数据。

    安装:

    有两种方法,一种是通过编译源码,比较麻烦。我使用的是另外一种方法,在windows下,使用编译好的二进制文件。

    安装文件下载地址:https://sourceforge.net/projects/tesseract-ocr-alt/files/

    最新训练数据下载地址:https://github.com/tesseract-ocr/tessdata

    建议使用稳定的3.0版本,我试用的4.0开发版报错。

    注意选中Registry settings,也就是把Path和TESSDATA_PREFIX环境变量自动配置好。

    如果要识别中文,就把中文训练数据选中。

    使用:

    安装完成之后,就可以在命令行下执行识别图片了。

    命令行下执行:

      1 tesseract test.png stdout 

    都可以识别。

    但是识别中文或者是中英文混合的时候,识别率不高。

    tesseract cs.png stdout -l eng+chi_sim

    Python封装模块pytesseract:

    tesseract有很多语言的封装包,这里只介绍下python的pytesseract。

    源码地址:https://github.com/madmaze/pytesseract

    可以直接使用pip安装:

    pip install pytesseract

    使用示例:

    from PIL import Image
    import pytesseract
    print(pytesseract.image_to_string(Image.open('test.png')))
    print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))

    注意事项:

    需要先安装好PIL和tesseract,并且可以在命令行里可以使用。

  • 相关阅读:
    客户端验证用户名和密码
    特殊日期提示
    python 多态这一部分的知识点相关应用
    类的继承
    栈,队列的应用
    生成器与for循环的纠葛
    类(class)的形成过程
    报错信息看着哇
    死脑筋要活用(我只放贴图)01
    正则运算跟py语言的结合,知识点层出不穷
  • 原文地址:https://www.cnblogs.com/lilongsy/p/6373439.html
Copyright © 2020-2023  润新知