import cv2
image = cv2.imread("beach.jpg", cv2.IMREAD_COLOR)
cv2.imshow("C:\\Users\\farha\\Downloads\\WALLPAPER\\beach.jpg", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Error: cv2.imshow("C:\Users\farha\Downloads\WALLPAPER\beach.jpg", image) cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
CodePudding user response:
When cv2
can't read image then it doesn't raise error but it returns None
and later it may gives error in other lines when it tries to use this None
to display image (or change color, or edit image)
You should use full path in imread()
- imshow
needs text for widow's title, it doesn't have to be path to image.
image = cv2.imread("C:\\Users\\farha\\Downloads\\WALLPAPER\\beach.jpg", cv2.IMREAD_COLOR)
if image is None:
print("I can't read image")
else:
cv2.imshow("My Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()