'why this unicode error occurs for reading and diplaying image? [duplicate]

im getting unicode error for this code

img=cv2.imread("C:\Users\chinthakani priyanka\Desktop\pythonjupiter\cat.jpeg")
cv2.imshow("cats",img)
cv2.waitKey(60)

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape



Solution 1:[1]

The error is most probably on the path format. Try using forward slashes ("/") instead of backward slashes (" \ "). So, the code would be as it follows:

img=cv2.imread("C:/Users/chinthakani priyanka/Desktop/pythonjupiter/cat.jpeg")
cv2.imshow("cats",img)
cv2.waitKey(60)

If this doesn't work, you can also try adding and 'r' before the path string, so it converts it to a 'raw string'. This way:

img=cv2.imread(r"C:\Users\chinthakani priyanka\Desktop\pythonjupiter\cat.jpeg")
cv2.imshow("cats",img)
cv2.waitKey(60)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1