Yes it works if image exist on disk
you should write (tutorials here ):
import cv2 as cv
import sys
img = cv.imread("starry_night.jpg")
if img is None:
sys.exit("Could not read the image.")
cv.imshow("Display window", img)
k = cv.waitKey(0)
if k == ord("s"):
cv.imwrite("starry_night.png", img)
k = cv.waitKey(0)
give full path to image