【问题标题】:Python OpenCV- Problems reading files on WindowsPython OpenCV - 在 Windows 上读取文件时出现问题
【发布时间】:2019-03-08 18:18:10
【问题描述】:

我需要读取一个包含大量 .bmp 文件的文件夹,并将所有图像放在一组图像上。我不知道如何处理地址。我正在做这样的事情:

adress = "c:/Users/My Name/Desktop/assignment/*.bmp"

imageArray = [cv2.imread(file) for file in glob.glob(adress)]

numImg = len(imageArray)

在 assignment 文件夹中,有一个 Images 文件夹,里面有我需要的所有图像。如何使这项工作?

【问题讨论】:

    标签: python python-3.x opencv image-processing opencv3.0


    【解决方案1】:

    先改变工作目录:

    如果你先切换到感兴趣的目录,可能会更容易。

    import glob, os
    os.chdir("/mydir")
    
    image_type = "*.bmp"
    
    imageArray = [cv2.imread(file) for file in glob.glob(image_type)]
    
    numImg = len(imageArray)
    

    这个LINK 有一些关于读取目录中文件的好信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 2016-07-02
      • 1970-01-01
      • 2012-06-06
      相关资源
      最近更新 更多