网站的结构类型,代理记账公司收费标准,如何进行在线营销,网站建设的功能都需要有哪些方面During handling of the above exception, another exception occurred解决方案 前言解决方案总结 前言
今天在写python读取图片中的内容的脚本的时候#xff0c;常用的图像处理库包括Pillow和OpenCV。以下是使用Pillow库读取图片中的计算公式的示例代码#xff1a;
from P… During handling of the above exception, another exception occurred解决方案 前言解决方案总结 前言
今天在写python读取图片中的内容的脚本的时候常用的图像处理库包括Pillow和OpenCV。以下是使用Pillow库读取图片中的计算公式的示例代码
from PIL import Image
import pytesseract# 读取图片
img Image.open(formula.png)# 将图片转换为灰度图像
img img.convert(L)# 使用pytesseract识别图片中的文本
formula pytesseract.image_to_string(img)# 输出识别结果
print(formula)遇到了如下问题
解决方案
通过核对代码内容文件名称和文件路径等没有问题包括把代码放到Linux上面跑都没有问题。
最后发现错误的原因是在Python2和Python3中tesseract所在的路径没有作为环境路径变量添加到Windows中。
在使pytesseract在windows上运行的步骤
从https://www.continuum.io/downloads安装Python2或Python3从http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe安装tesseract for windows将tesseract目录作为PATH环境变量添加到windows中
最后再执行代码脚本
from PIL import Image
import pytesseract# 读取图片
img Image.open(formula.png)# 将图片转换为灰度图像
img img.convert(L)# 使用pytesseract识别图片中的文本
formula pytesseract.image_to_string(img)# 输出识别结果
print(formula)成功了。。。
总结
无论什么时候不能忽视细节常见的问题都是最简单、直接、基础的因素产生的。