如何使用pytesseract从图像获取文本?

时间:2019-04-11 08:01:21

标签: python-3.x anaconda python-imaging-library spyder python-tesseract

我有一种情况,我必须从图像中获取一些文本。但是尝试这样做时出现以下错误:

runfile('/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py', 
wdir='/Users/vivekchowdary/Documents/untitled folder')
Traceback (most recent call last):

File "<ipython-input-3-95284fad16df>", line 1, in <module>
runfile('/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py', 
wdir='/Users/vivekchowdary/Documents/untitled folder')

File "/anaconda3/lib/python3.7/site- 
packages/spyder_kernels/customize/spydercustomize.py", line 704, in 
runfile
execfile(filename, namespace)

File "/anaconda3/lib/python3.7/site- 
packages/spyder_kernels/customize/spydercustomize.py", line 108, in 
execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py", line 3, in <module>
from pytesseract import *

File "/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py", line 6, in <module>
text = image_to_string(image_file)

NameError: name 'image_to_string' is not defined

我使用了以下代码:

`from PIL import Image
from matplotlib import pyplot as plt
from pytesseract import *
image_file='/Users/vivekchowdary/Documents/untitled 
folder/Scan0013.jpg'
im=Image.open(image_file)
text = image_to_string(image_file)
print ("=====output=======\n")
print (text)`

我的预期结果是,它必须从“ jpg”图像中提取所有文本并将其打印在屏幕上。

0 个答案:

没有答案