如何解决如何遍历目录中的图像?
我的目录中有猫图像。我想手动对这些图像应用数据增强。
我的目录为php artisan optimize:clear
。
此目录中的图像带有两种类型的标签/名称:
-
Downloads/Images/Cats/
,cat1_001.png
,... -
cat1_002.png
,cat2_001.png
,...
指定两种类型的猫图像。
那么如何仅从python目录中迭代带有标签1的图像?
解决方法
您可以这样做:
import os
directory_in_str = 'Downloads/Images/Cats/'
directory = os.fsencode(directory_in_str)
for file in os.listdir(directory):
filename = os.fsdecode(file)
if(filename.startswith('cat1_') and filename.endswith('.png')):
print(filename)
# do your staff here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。