读取多个文件夹中的图像 [英] Reading images in multiple folders

查看:61
本文介绍了读取多个文件夹中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读取多个文件上的图像时遇到问题.我有一个像这样的文件:

I am facing a problem with reading images on multiple files. I have a file like this:

现在,我想读取文件rgb中的所有图像,但是文件rgb中也有3个文件夹(00,01,02),其中包含图像.如何读取3个文件夹00,01,02中的所有图像.此外,在文件夹注释中,我还有3个名为00、01和02的文件夹,但是在这3个文件夹中,它包含2种文件,分别是txt和npy.我只想阅读txt文件,该怎么办?
"rgb"图像我将用来训练模型的文件,而txt文件将用作标签

Now, I want to read all images in file rgb, but in file rgb also have 3 folders(00,01,02) that containing images in this. How can I read all images in 3 folders 00,01,02. Furthermore, in the folder annotation, I also have 3 folders named 00, 01, and 02, but in these 3 folders, it contains 2 kind of files which is txt and npy. I just want to read txt file, what should I do?
The images in "rgb" file I will use to train the model, and txt files will be used as labels

推荐答案

pathlib.Path()允许通配符匹配您要查找的内容. ** 是与所有子目录"匹配的通配符,而 * 与文件名中的任何内容匹配:

pathlib.Path() allows wildcards to match what your are looking for. ** is a wildcard that matches "all subdirectories", and * matches anything in the filename:

from pathlib import Path

p = Path('Videos frame')

for f in p.glob('rgb/**/*.png'): # or whatever your image type is...
    print(f)

for f in p.glob('annotation/**/*.txt'):
    print(f)

这篇关于读取多个文件夹中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆