我试图用Python从多个图像中提取文本
这是我的代码
from PIL import Image
from pytesseract import pytesseract
import os
#Define path to tessaract.exe
path_to_tesseract = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
#Define path to images folder
path_to_images = r'C:\Users\vIBRancy\Desktop\quantic_trust _file\images'
#Point tessaract_cmd to tessaract.exe
pytesseract.tesseract_cmd = path_to_tesseract
#Get the file names in the directory
for root, dirs, file_names in os.walk(path_to_images):
#Iterate over each file name in the folder
for file_name in file_names:
#Open image with PIL
img = Image.open(path_to_images + file_name)
#Extract text from image
text = pytesseract.image_to_string(img, lang = 'eng')
with open('quantictrustfiles.txt','w') as file:
file.write(text)
print(text)
,这是终端的响应:
PS C:\Users\vIBRancy\Desktop\quantic_trust _file> & C:/Users/vIBRancy/AppData/Local/Programs/Python/Python39/python.exe "c:/Users/vIBRancy/Desktop/quantic_trust _file/quantict_trust_file.py"
Traceback (most recent call last):
File "c:\Users\vIBRancy\Desktop\quantic_trust _file\quantict_trust_file.py", line 19, in <module>
img = Image.open(path_to_images + file_name)
File "C:\Users\vIBRancy\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 3068, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\vIBRancy\\Desktop\\quantic_trust _file\\imagesIMG_0096.jpeg'
我不知道该怎么办。任何人都可以提供帮助。
This is my code
from PIL import Image
from pytesseract import pytesseract
import os
#Define path to tessaract.exe
path_to_tesseract = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
#Define path to images folder
path_to_images = r'C:\Users\vIBRancy\Desktop\quantic_trust _file\images'
#Point tessaract_cmd to tessaract.exe
pytesseract.tesseract_cmd = path_to_tesseract
#Get the file names in the directory
for root, dirs, file_names in os.walk(path_to_images):
#Iterate over each file name in the folder
for file_name in file_names:
#Open image with PIL
img = Image.open(path_to_images + file_name)
#Extract text from image
text = pytesseract.image_to_string(img, lang = 'eng')
with open('quantictrustfiles.txt','w') as file:
file.write(text)
print(text)
Here is the response from the terminal:
PS C:\Users\vIBRancy\Desktop\quantic_trust _file> & C:/Users/vIBRancy/AppData/Local/Programs/Python/Python39/python.exe "c:/Users/vIBRancy/Desktop/quantic_trust _file/quantict_trust_file.py"
Traceback (most recent call last):
File "c:\Users\vIBRancy\Desktop\quantic_trust _file\quantict_trust_file.py", line 19, in <module>
img = Image.open(path_to_images + file_name)
File "C:\Users\vIBRancy\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 3068, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\vIBRancy\\Desktop\\quantic_trust _file\\imagesIMG_0096.jpeg'
I don't know what to do. Anyone to help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论