简体   繁体   中英

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

i want code for extract url from photo but error FileNotFound don`t stop show me input:

 `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'

can you help me??.

Be sure you already installed all the dependencies and libraries.

tesseract , image and pytesseract

After that you need to put the full path for your image. For example, let's assume that your image is in /Users/Desktop . See the example below:

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)

This is why you got the error File not found . Just tested the code here and everything works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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