4

I have mounted my Google drive to my colab notebook:

from google.colab import drive
drive.mount("/content/gdrive")

I can import csv files through it, in my case:

df = pd.read_csv("/content/gdrive/MyDrive/colab/heart-disease.csv")

But when I try to import images in markdown/text in colab nothing happens:

![](/content/gdrive/MyDrive/colab/6-step-ml-framework.png)

Here's my directory on Google drive:

Directory

Chris
  • 1,206
  • 2
  • 15
  • 35
game movie
  • 107
  • 1
  • 1
  • 8

2 Answers2

8

You can using OpenCV in colab by import cv2 as cv, read image by img = cv.imread('/content/gdrive/MyDrive/colab/6-step-ml-framework.png'), convert image to numpy array using img = np.float32(img)

Mr. For Example
  • 4,173
  • 1
  • 9
  • 19
  • how do i print the photo out? – game movie Dec 15 '20 at 06:16
  • There many ways, you can using `matplotlib` as usual, or `from google.colab.patches import cv2_imshow` then `cv2_imshow(img)`, check out this [image processing tutorial on colab](https://colab.research.google.com/github/xn2333/OpenCV/blob/master/Image_Processing_in_Python_Final.ipynb#scrollTo=Tz7UAjxjfMuz) – Mr. For Example Dec 15 '20 at 06:23
  • in markdown text i want to use this Image – game movie Dec 15 '20 at 06:30
  • @gamemovie it seems you cannot directly using it, but you could do so by follow [this](https://stackoverflow.com/questions/50670920/how-to-insert-an-inline-image-in-google-colaboratory-from-google-drive), or just upload it from your PC – Mr. For Example Dec 15 '20 at 06:45
1

@Mr. For Example you should not use np.float(img), because OpenCV's method imread has converted it to np.array already

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30812887) – Tom Aarsen Jan 20 '22 at 15:39