繁体   English   中英

FileNotFoundError: [Errno 2] 没有这样的文件或目录?

[英]FileNotFoundError: [Errno 2] No such file or directory?

我想要从照片中提取 url 的代码,但错误 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)`

outPut:

    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'

你能帮助我吗??。

确保您已经安装了所有依赖项和库。

pytesseractimagetesseract

之后,您需要放置图像的完整路径。 例如,假设您的图像位于/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的原因。 刚刚在这里测试了代码,一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM