I am learning the basics of OpenCV and while running the following piece of code in google colab, it gives an error.
from google.colab.patches import cv2_imshow
import cv2
img=cv2.imread("geeks14.png")
cv2_imshow(img)
The error is
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-569c91be5363> in <module>()
2 import cv2
3 img=cv2.imread("geeks14.png")
----> 4 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
CodePudding user response:
The issue isn't cv2_imshow
.
The issue is that imread()
returned None
. It could not read the given path as an image file.
Check the usual reasons for imread()
failing, such as:
- file isn't there (look up what relative paths are relative to, or use absolute paths)
- file is corrupted
- file has a format that is not supported by OpenCV
- you don't have access rights
- system is broken in some way
CodePudding user response:
Please check in colab if file geeks14.png is present there or not. You need to upload Check sample SS here!