简体   繁体   English

PYTHON OCR Tesseract中的错误

[英]Error in PYTHON OCR Tesseract

When running my python OCR script from CMD, I get this error. 从CMD运行python OCR脚本时,出现此错误。 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 . 您的主要问题是文件夹\\Users ,由于\\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. 另一种解决方案是使用'\\\\Users'这样'\\\\Users'双反斜杠,但为什么要打扰呢。

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

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