-6
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'

Han Izza
  • 1
  • 2
  • 1
    you should use full path in `imread()`, not in `imshow()`. You could also check what you have in `image`. When `cv2` can't read image then it doesn't raise error but it returns `None` and later you may get error in other lines when you try to use this `None` to display (or change color, or edit image) – furas Oct 17 '21 at 08:04
  • if you follow some tutorial then you could add link for this tutorial - and add it in question, not in comment. – furas Oct 17 '21 at 08:07

1 Answers1

0

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()
furas
  • 134,197
  • 12
  • 106
  • 148