1

I write this simple program to read an image stored in google drive, but I receive this response when I executed it :

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)

After execution :

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'
Anil_M
  • 10,893
  • 6
  • 47
  • 74
3loum m3arif
  • 11
  • 1
  • 2

1 Answers1

0

'Nonetype' means your image wasn't loaded properly. I guess your path to the file should start with /content as it usually does working with Google Drive:

img = cv2.imread('/content/drive/my-drive/1.png')

You can also check the path in the left-panel file explorer via right mouse click (by copying the full path).

ans
  • 378
  • 1
  • 5
  • 18
  • in fact it's not a problem of read because I try the two manner but it can't work correctely – 3loum m3arif Nov 02 '21 at 20:16
  • @3loumm3arif, what does the [following checking](https://stackoverflow.com/questions/23628325/cv2-imread-checking-if-image-is-being-read) says? Was your image really been loaded? – ans Nov 03 '21 at 09:10