SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
笔者环境:
win10
vscode
在vscode中编写opencv代码读取图片时,报错SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
源代码:
# _*_ coding:utf-8 _*_
import cv2
img = cv2.imread("C:\Users\lenovo\Desktop\python\python_vision\image0.JPG")
cv2.imshow("image",img)
cv2.waitKey(0)
修改,将读取路径加上r
# _*_ coding:utf-8 _*_
import cv2
img = cv2.imread(r"C:\Users\lenovo\Desktop\python\python_vision\image0.JPG")
cv2.imshow("image",img)
cv2.waitKey(0)