pythonopencvreadimage

Google Colab: TypeError: Image data of dtype object cannot be converted to float


I know there are similar questions and I have checked on that but it did not work. I try to open an image with cv2 in google colab using this code:

path='/content/group.jpg'
img = cv2.imread(path)

plt.imshow(img)
plt.show()

But it was error.

enter image description here

I have checked on the image path and it is right. Can anyone please help me? Thank you :)


Solution

  • The issue in hand is related to the path of the image.

    Your cv2.imread path and the path variable possibly point to different locations. Try locating the image you want in the file browser. If you then right click on it, you would get the ability to copy the path of the file. You must use that path to load the image and it would work.

    path='/content/group.jpg'
    img = cv2.imread(path)
    
    plt.imshow(img)
    plt.show()