你好呀~

Tesseract图片文字识别

  如何进行图文识别?

  百度api收费的,自己训练模型集费时费力,有没有训练好的库,我们拿过来直接用的呢?

  有,那就是tesseract。

 

安装

  pipenv install pytesseract

  pipenv install pillow

  官方下载tesseract-OCR,http://www.softpedia.com/get/Programming/Other-Programming-Files/Tesseract-OCR.shtml,安装的时候记得在语言那里勾选中文即可。

 

使用

  

import pytesseract
from PIL import Image


def recognize(img: str, lang: str = 'chi_sim'):
    """
    lang: 'eng', 'chi_sim'
    """
    img = Image.open(img)
    s = pytesseract.image_to_string(img, lang=lang)
    print(s)


recognize('img.png')

 

posted @ 2022-03-11 14:54  测神  阅读(80)  评论(0编辑  收藏  举报