我写了这个简单的程序来读取存储在google drive中的图像,但是当我执行它时,我收到了这样的响应:
from google.colab.patches import cv2_imshow
from google.colab import drive
drive.mount('/content/drive')
import cv2
img = cv2.imread('/drive/my-drive/1.png')
cv2_imshow(img)
执行后:
AttributeError Traceback (most recent call last)
<ipython-input-96-d0027ef4e25a> in <module>()
----> 1 cv2_imshow(img)
/usr/local/lib/python3.7/dist-packages/google/colab/patches/__init__.py in cv2_imshow(a)
20 image.
21 """
---> 22 a = a.clip(0, 255).astype('uint8')
23 # cv2 stores colors as BGR; convert to RGB
24 if a.ndim == 3:
AttributeError: 'NoneType' object has no attribute 'clip'
'Nonetype'表示您的图像没有正确加载。我猜你的文件路径应该从/content
开始,因为它通常与Google Drive一起工作:
img = cv2.imread('/content/drive/my-drive/1.png')
您还可以通过右键单击(通过复制完整路径)在左面板文件资源管理器中检查路径。