[英]How can I read an image using cv2.imread after having done the drive.mount from colab?
from google.colab import drive
drive.mount('/gdrive')
安装驱动器并复制并粘贴身份验证代码后,我终于可以在“/gdrive/My\ Drive/”中看到我的文件,通过在这里选择一个图像,我实际上可以检查:
filePath = '/gdrive/My\ Drive/img.png'
!ls -l $filePath
将返回所需的文件(我的 root 权限为 600),所以我确定 filePath 实际上是指我要读取的图像。 但是os.path.isfile(filePath)
将返回False
并且cv2.imread(filePath)
将返回None
。
为什么? 我实际上缺少哪个概念?
谢谢
如果您使用的是 bash 命令(以!
开头),则使用反斜杠转义空格是正确的。
但是,由于您在执行cv2.imread
时处于 python 环境中,因此您不再需要逃避。
尝试删除 escaping 反斜杠
filePath = '/gdrive/My Drive/img.png'
image = cv2.imread(filePath)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.