2

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 :)

4
  • Can you show on which line does the error occur? Commented Aug 17, 2021 at 0:26
  • You define the path and don't use it. You should have img = cv2.imread(path) Commented Aug 17, 2021 at 0:30
  • Ah yes, pardon me. I tried many ways and ended copied that. I have edited my question. Thank you @aminrd Commented Aug 17, 2021 at 0:43
  • Hi @SamirAhmane I have edited my questions with a screenshoot. Can you please take a look? Than kyou Commented Aug 17, 2021 at 0:44

1 Answer 1

3

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()
Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thank you for your answer. I have tried that and it also gave error.
@mstd Could you show what your error is?
Sure, it is said: TypeError: Image data of dtype object cannot be converted to float. I have also edited my question
plt.imshow(plt.imread(path)) please try using this
Ahh, I see. The problem is, the file is corrupt. I try another file and it works! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.