我正在开发代码,将图像转换为文本使用以下代码。在执行代码时,我看到了下面的错误。我真的不明白是什么导致了这个问题。有人能帮我找出问题所在吗? from PIL import Image
import PIL.Image
from pytesseract import image_to_string
import pytesseract
img = Image.open('C:\\Users\\Documents\\convert_image_to_text\\Sample.png')
pytesseract.pytesseract.tesseract_cmd = 'C:\AppData\Local\Tesseract-OCR\tesseract.exe'
text = pytesseract.image_to_string('C:\\Users\\Documents\\convert_image_to_text\\Sample.png')
print(text)以下是错误: File "C:/Users/Documents/convert_image_to_text/program_to_convert_image_to_text.py", line 21, in
text=image_to_string(img)
NameError: name 'img' is not defined
|