简体   繁体   English

无法从 D 驱动器 [OpenCV] [Python] 读取或写入图像

[英]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?有没有办法用 OpenCV 在 D 盘上写入或读取图像?

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.当我读取图像时, cv2.imread 返回无。 When I try to write on D Drive an image which I read from C Drive, it doesn't do anything.当我尝试在 D 驱动器上写入从 C 驱动器读取的图像时,它什么也没做。

you need to specify your path with r strings.您需要使用 r 字符串指定您的路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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