主页 > 知识库 > Python实现OCR识别之pytesseract案例详解

Python实现OCR识别之pytesseract案例详解

热门标签:百应电话机器人总部 成都呼叫中心外呼系统哪家强 无锡智能外呼系统好用吗 宿州电话机器人哪家好 南昌地图标注 地图标注与注销 旅游厕所地图标注怎么弄 电梯新时达系统外呼显示e 西青语音电销机器人哪家好

Python实现OCR识别:pytesseract

Python常用pytesseract进行图片上的文字识别,即OCR识别,完整的代码比较简单,只要下面一行即可,但是实际使用时环境配置上容易出错。

from PIL import Image
import pytesseract
 
text = pytesseract.image_to_string(Image.open('/Users/alice/Documents/Develop/PythonCode/textinphoto.PNG'))
print(text)

因此使用前,需要先安装pillow和pytesseract依赖包。

然而运行时仍然报错,raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

原因是因为未安装tesseract,然后使用pip3 install tesseract之后仍然提示错误,如图:

alicedembp:~ alice$ pip3 install tesseract
Requirement already satisfied: tesseract in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.1.3)
alicedembp:~ alice$ tesseract
-bash: tesseract: command not found

无法使用,往上找了很多教程,说是要使用brew安装,于是得以解决,步骤为:

  • 先安装brew
alicedembp:~ alice$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 再使用brew安装leptonica
alicedembp:~ alice$ brew install leptonica
  • 使用brew安装tesseract
alicedembp:~ alice$ brew install tesseract
  • 安装成功,通过命令行tesseract -v的方式查看是否成功,出现版本号则为安装成功
alicedembp:~ alice$ tesseract
Usage:
  tesseract --help | --help-extra | --version
  tesseract --list-langs
  tesseract imagename outputbase [options...] [configfile...]
 
OCR options:
  -l LANG[+LANG]        Specify language(s) used for OCR.
NOTE: These options must occur before any configfile.
 
Single options:
  --help                Show this help message.
  --help-extra          Show extra help for advanced users.
  --version             Show version information.
  --list-langs          List available languages for tesseract engine.
 
alicedembp:~ alice$ tesseract -v
tesseract 4.0.0
 leptonica-1.78.0
  libgif 5.1.4 : libjpeg 9c : libpng 1.6.36 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.2 : libopenjp2 2.3.1
 Found AVX2
 Found AVX
 Found SSE

接下来就可以直接使用了,使用如下代码:

alicedembp:~ alice$ tesseract /Users/alice/Documents/Develop/PythonCode/textinphoto.png /Users/alice/Documents/Develop/PythonCode/output.txt

打开textinphoto.PNG的图片,将文字输出到output.txt,图片如下

运行成功,产生output.txt文档,里面的文本为图片中识别出的文字。

到此这篇关于Python实现OCR识别之pytesseract案例详解的文章就介绍到这了,更多相关python OCR识别之pytesseract内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
  • python3使用Pillow、tesseract-ocr与pytesseract模块的图片识别的方法
  • python3光学字符识别模块tesserocr与pytesseract的使用详解
  • python PaddleOCR库用法及知识点详解
  • python EasyOCR库实例用法介绍
  • python muggle_ocr库用法及实例代码
  • python 如何做一个识别率百分百的OCR
  • Python 实现任意区域文字识别(OCR)操作

标签:雅安 潍坊 渭南 赣州 西安 七台河 许昌 辛集

巨人网络通讯声明:本文标题《Python实现OCR识别之pytesseract案例详解》,本文关键词  Python,实现,OCR,识别,之,pytesseract,;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 下面列出与本文章《Python实现OCR识别之pytesseract案例详解》相关的同类信息!
  • 本页收集关于Python实现OCR识别之pytesseract案例详解的相关信息资讯供网民参考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推荐文章