浅尝python的图像识别

目的

对python中的图像识别进行简单的测试和使用

环境

  • win64系统
  • anaconda
  • 需要下载的软件:tesseract
  • 需要下载的python包:pytesseract,pillow
  • 一张记录英文的图片

环境的搭建

1、tesseract的下载:

下载链接:https://digi.bib.uni-mannheim.de/tesseract/

tesseract下载后需要对环境变量进行配置:

右击我的电脑/此电脑->属性->高级系统设置->环境变量->Path->编辑->新建->
添加自己下载的软件目录,类似于“D:\Tesseract-OCR”

2、pytesseract和pillow包的下载:

在Anaconda Prompt中依次执行命令:

conda install pytesseract
conda install pillow

本人在执行命令时总是在报错:

PackagesNotFoundError: The following packages are not available from current channels:pytesseract

后来添加了清华的镜像源仓库后pytesseract包和pillow包直接下载成功

3、将一张名为test.png的图片放置在notebooks项目文件同一目录

代码

import pytesseract
from PIL import Image
im = Image.open('test.png')
string = pytesseract.image_to_string(im)
print(string)

当执行后会发现报错:

tesseract is not installed or it's not in your PATH. See README file for more information

解决办法:

1、找到pytesseract包的文件:D:\anaconda3\Lib\site-packages\pytesseract\pytesseract.py

2、将pytesseract.py文件中的 tesseract_cmd = 'tesseract'
修改为 tesseract_cmd = r'D:\Tesseract-OCR\tesseract.exe '

本人的anaconda和tesseract都放置在D盘中,如果您的软件放置的位置不同,可按您的具体安装情况寻找配置文件和修改

效果

test.png

得到的结果:

兄弟们 tesseract中文包的下载一直被墙,偶得一大佬分享的语言包,我这里给大家分享出来,大家且行且珍惜:
链接:https://pan.baidu.com/s/1ZVqKZepLq5-_kMJDfjOWiQ
提取码:8b4g

参考的链接:https://www.jb51.net/article/187678.htm

posted @ 2024-07-12 17:12  酒暖=  阅读(2)  评论(0编辑  收藏  举报