文字识别 pytesseract

可以使用Python中的OCR技术来实现图片提取文字。OCR(Optical Character Recognition)光学字符识别技术,可以识别图像中的文字并将其转换为文本。常用的Python OCR库包括pytesseract、opencv-python等。

以下是一个简单的示例代码,使用pytesseract库实现图片文字提取:

import pytesseract
from PIL import Image

# 打开图片文件
image = Image.open('image.png')

# 使用pytesseract库提取文字
text = pytesseract.image_to_string(image, lang='chi_sim+eng')

print(text)


其中,'image.png’为要提取文字的图片文件名,lang='eng’指定使用英语语言进行识别。如果需要识别其他语言,则需要下载对应的语言包并进行配置。

安装方法:

Ubuntu
You can install Tesseract and its developer tools on Ubuntu by simply running:

pip install pytesseract

sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
sudo apt install tesseract-ocr-chi-sim

Note for Ubuntu users: In case apt is unable to find the package try adding universe entry to the sources.list file as shown below.

sudo vi /etc/apt/sources.list

Copy the first line “deb http://archive.ubuntu.com/ubuntu bionic main” and paste it as shown below on the next line.
If you are using a different release of ubuntu, then replace bionic with the respective release name.

deb http://archive.ubuntu.com/ubuntu bionic universe

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值