Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Google CoLab中处理许多图像-从Anaconda迁移_Python_Image Processing_Google Colaboratory - Fatal编程技术网

Python 在Google CoLab中处理许多图像-从Anaconda迁移

Python 在Google CoLab中处理许多图像-从Anaconda迁移,python,image-processing,google-colaboratory,Python,Image Processing,Google Colaboratory,我一直在使用GoogleColab编写python脚本,到目前为止,使用“只需代码”非常方便 我想开始处理图像,我正在寻找一个脚本,它可以处理100多个图像或更多图像,但不确定在Colab中执行此操作的可接受方法是“没有本地驱动器” 原始代码: import cv2 as cv import glob def get_imgs(path_to_imgs): all_files = glob.glob(path_to_imgs + "**/*.png") re

我一直在使用GoogleColab编写python脚本,到目前为止,使用“只需代码”非常方便

我想开始处理图像,我正在寻找一个脚本,它可以处理100多个图像或更多图像,但不确定在Colab中执行此操作的可接受方法是“没有本地驱动器”

原始代码:

import cv2 as cv
import glob

def get_imgs(path_to_imgs):
    all_files = glob.glob(path_to_imgs + "**/*.png")
    return ( cv.imread(file, flags=cv.IMREAD_GRAYSCALE) for file in all_files)


def show_img(img):
    cv.imshow('window_name', img)
    cv.waitKey(0)
    cv.destroyAllWindows()


for each_img in get_imgs('./myImages/'):
    if counter == 10:
        break
    show_img(each_img)
到目前为止,我已经研究过将所有图像存储在自己的驱动器上(并使用access键将Colab连接到驱动器,有点不舒服),或者将它们存储在原始github上

在这两种情况下,我都无法使它在构造函数中工作,我认为主要是因为我无法像在本地那样遍历“文件夹”


有什么想法和建议吗?

在Google Colab中,左侧栏上有一个小文件夹图标。然后,您可能必须单击新文件系统侧栏顶部的文件夹图标。这允许您访问虚拟机的所有文件夹。要上载大型图像数据集,您可以单击“文件上载”按钮,或使用wget通过原始Github下载。

除了@DraperDuck的有用答案之外,我想为您指出另一个选项:

就我个人而言,我更喜欢装载驱动器并使用数据集访问以前设置的文件夹:

from google.colab import drive
drive.mount('/content/drive')
(旁注:我不记得
cv2.imshow
是否由Colab Jupyter笔记本环境处理(通常
cv2.imshow
需要操作系统窗口系统),但如果失败,您可以使用matplotlib(
plt.imshow
)在笔记本中显示图像)