Python通过pytesseract库实现识别图片中的文字

作者:空空star 时间:2021-12-02 14:43:03 

前言

大家好,我是空空star,本篇给大家分享一下通过Python的pytesseract库识别图片中的文字。

本篇所用软件相关版本:

macOS 11.6.5
Python 3.8.9
pytesseract 0.3.10
Pillow 9.4.0

一、pytesseract

1.pytesseract是什么

Pytesseract是一个Python的OCR库,它可以识别图片中的文本并将其转换成文本形式。Pytesseract基于Google的Tesseract OCR引擎,具有较高的准确性和可靠性。它可以读取多种格式的图片,包括PNG、JPEG、GIF等。Pytesseract可以应用于自然语言处理、数据挖掘、OCR识别等领域。

2.安装pytesseract

pip install pytesseract

3.查看pytesseract版本

pip show pytesseract

Name: pytesseract
Version: 0.3.10
Summary: Python-tesseract is a python wrapper for Google’s Tesseract-OCR
Home-page: https://github.com/madmaze/pytesseract
Author: Samuel Hoffstaetter
Author-email: samuel@hoffstaetter.com
License: Apache License 2.0
Requires: packaging, Pillow
Required-by:

4.安装PIL

Pillow库是Python图像处理库,pytesseract使用它来处理图像。

pip install pillow

5.查看PIL版本

pip show pillow

Name: Pillow
Version: 9.4.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark@python-pillow.org
License: HPND
Requires:
Required-by: image, imageio, matplotlib, pytesseract, wordcloud

二、Tesseract OCR

1.Tesseract OCR是什么

Tesseract OCR是一种开源的OCR(Optical Character Recognition,光学字符识别)引擎,它能够将图像中的文本内容识别并转换为可编辑的文本格式。它最初由惠普实验室开发,现在由谷歌维护和更新。Tesseract OCR支持超过100种语言,包括中文、英文、法文、德文等。它可以在多种操作系统上运行,包括Windows、Linux、macOS等。Tesseract OCR被广泛应用于数字化文档、自动化数据输入、智能搜索等方面。

2.安装Tesseract OCR

macOS下:

brew install tesseract

3.安装 Tesseract OCR 语言包

macOS下:

brew install tesseract-lang

三、使用方法

1.引入库

import pytesseract
from PIL import Image

2.打开图片文件

img = Image.open("demo.png")

3.使用Tesseract进行文字识别

text = pytesseract.image_to_string(img, lang='chi_sim')

4.输出识别结果

print(text)

原图

Python通过pytesseract库实现识别图片中的文字

识别出的文字截图

Python通过pytesseract库实现识别图片中的文字

来源:https://blog.csdn.net/weixin_38093452/article/details/130507160

标签:Python,pytesseract,图片,文字
0
投稿

猜你喜欢

  • 解决Pyinstaller打包软件失败的一个坑

    2022-05-31 21:47:14
  • django 自定义filter 判断if var in list的例子

    2022-09-25 16:11:37
  • 深入理解Python异常处理的哲学

    2023-07-27 06:11:28
  • Python实现查找系统盘中需要找的字符

    2022-10-02 02:35:50
  • 一个简单的JS显示日期代码

    2009-02-10 12:34:00
  • ASP ajax分页教程一

    2011-04-10 10:51:00
  • 让ThinkPHP支持大小写url地址访问的方法

    2023-11-17 02:28:37
  • python编写接口测试文档(以豆瓣搜索为例)

    2023-09-21 17:39:49
  • 一些不错的js函数ajax

    2023-08-25 14:01:38
  • vscode配置与python虚拟环境切换的几种方式总结

    2023-09-04 07:09:28
  • 布同 Python中文问题解决方法(总结了多位前人经验,初学者必看)

    2021-01-02 08:46:49
  • django实现日志按日期分割

    2023-07-20 04:25:21
  • 合理利用页面标签元素有利用搜索引擎收录

    2008-11-03 11:49:00
  • Go语言编程中字符串切割方法小结

    2023-06-16 01:41:24
  • Python dict和defaultdict使用实例解析

    2022-12-24 20:44:19
  • discuz 跨域整合的记录文件

    2023-07-23 14:17:27
  • Python读取配置文件的实战操作

    2021-08-12 19:48:09
  • Python实现基于HTTP文件传输实例

    2021-10-23 13:24:53
  • javascript新闻图片轮换类

    2009-01-09 12:57:00
  • Python语法快速入门指南

    2021-10-18 11:36:00
  • asp之家 网络编程 m.aspxhome.com