简体   繁体   中英

Error in PYTHON OCR Tesseract

When running my python OCR script from CMD, I get this error. Is it a problem with the picture or my code??

error log

D:\Documents\Everything Programming\_Not Hacking\Bots\Discord Bots\python img recog>imgrecog.py
  File "D:\Documents\Everything Programming\_Not Hacking\Bots\Discord Bots\python img recog\imgrecog.py", line 3
    print(pytesseract.image_to_string(Image.open('C:\Users\[MY NAME]\Desktop\letrs.jpg')))
                                                ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

code

import pytesseract
from PIL import Image

print(pytesseract.image_to_string(Image.open('C:\Users\[MY NAME]\Desktop\letrs.jpg')))

Use slashes / instead of backslashes \\ and you should be fine. Your main problem es de folder , \\Users which is trying to be interpreted because of the \\U . So just stay away from backslashes when coding and your code should work. Other solution is to put double backslash like '\\\\Users' but why bother.

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