简体   繁体   中英

Can't read or write images from D Drive [OpenCV] [Python]

Is there a way to write or read images on D Drive with OpenCV?

writing_directory = "D:/path/"
...
image_path = "D:/path/image.bmp"
image = cv2.imread(image_path)
...
cv2.imwrite(f"{writing_directory}written_image.bmp", image)

When I read the image, cv2.imread returns None. When I try to write on D Drive an image which I read from C Drive, it doesn't do anything.

you need to specify your path with r strings.

writing_directory = "D:/path/"
...
image = cv2.imread(r"D:/path/image.bmp")
...
cv2.imwrite(fr"{writing_directory}written_image.bmp", image)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM