我想从照片中提取网址的代码,但错误FileNotFound不要停止显示给我 输入:
`from PIL import Image, ImageEnhance, ImageFilter
from pytesseract import image_to_string
from pytesseract import image_to_boxes
im = Image.open("oic.png")
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
im.save('temp2.jpg')
text = image_to_string(Image.open('temp2.jpg'))
print(text)`
输出:
Traceback (most recent call last):
File "V:\Project\***********\Exstract url form photo\test tow.py", line 170, in <module>
text = image_to_string(Image.open('temp2.jpg'))
File "C:\Users\fahad\AppData\Roaming\Python\Python38\site-packages\pytesseract\pytesseract.py", line 346, in image_to_string
return {
File "C:\Users\fahad\AppData\Roaming\Python\Python38\site-packages\pytesseract\pytesseract.py", line 349, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\fahad\AppData\Roaming\Python\Python38\site-packages\pytesseract\pytesseract.py", line 262, in run_and_get_output
with open(filename, 'rb') as output_file:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\fahad\\AppData\\Local\\Temp\\tess_mizb9wo_.txt'
你能帮我吗?
答案 0 :(得分:0)
确保已安装所有依赖项和库。
tesseract
,image
和pytesseract
之后,您需要为图像添加完整路径。例如,假设您的图片位于/Users/Desktop
中。请参见下面的示例:
from PIL import Image, ImageEnhance, ImageFilter
from pytesseract import image_to_string
from pytesseract import image_to_boxes
im = Image.open("/Users/Desktop/oic.png")
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
im.save('/Users/Desktop/temp2.jpg')
text = image_to_string(Image.open('/Users/Desktop/temp2.jpg'))
print(text)
这就是为什么您收到错误File not found
的原因。刚刚在这里测试了代码,一切正常。