python - GOOGLE COLAB:cv2.imread 返回 NoneType
问题描述
我无法cv2.imread
在谷歌 colab 中使用。我试过这样;
import cv2
img = cv2.imread('/content/gdrive/My Drive/path_to_image/1.png')
print(type(img))
>> `<class 'NoneType'>`
我不知道为什么它会发出这个!我在下面再次尝试...使用r
img = cv2.imread(r'/content/gdrive/My Drive/path_to_image/1.png')
我不知道为什么它会返回一个NoneType
对象。图片路径没有问题。我尝试了以下链接,但未能成功。
cv2.imread 总是返回 NoneType
解决方案
我希望我的解决方案对某人有所帮助。就我而言,调用img = cv2.imread('/content/gdrive/My Drive/path_to_image/1.png')
实际上是 FASTER RCNN 中函数的一部分。我无法解决互联网上的任何其他现有方法。最后我像下面那样做了,它奏效了。
首先,我认为问题是cv2.imread()
不承认My Drive
.. My
&之间的空间Drive
。虽然我从一开始就认识到这一点,但我的尝试如下所示。
"/content/gdrive/'My Drive'/path_to_image/1.png"
但简单地投入My Drive
一个single quotation
没有工作!
在我的情况下,它必须如下所示;
"/content/gdrive/"+"My Drive"+"/path_to_image/1.png"
编辑:
我想出了另一个解决方案来克服"My Drive"
Colab 中这个烦人的问题。
第1步:
from google.colab import drive
drive.mount("/content/drive/")
第2步:
import os
os.getcwd()
!mkdir MyDrive # make a directory called MyDrive
第 3 步:
!mount --bind /content/drive/My\ Drive /content/MyDrive
推荐阅读
- lodash - 如何使用 lodash 同时遍历两个数组
- c# - 有没有办法像在 javascript 中一样在 C# 中交替使用单引号和双引号?
- html - 我应该用文件输入在 Android 上打开谁的画廊?
- python - Python 包文件夹结构
- python - 格式化整个excel工作表 - Python
- oracle - Oracle - 从层次结构表中结束子节点
- python-3.x - 用于循环的 Django cms 模板在渲染期间会自行中断
- javascript - 无法让 api 数组从数组中输出 1 个第一个元素,它只在 jquery/javascript 中一次输出所有元素
- sql - 通过 VBA 连接执行长查询
- firebase - 如何使用 Flutter 从 Firestore 中的 ListView 获得无限滚动