Files
zjsh_yolov11/yolo11_obb/txt_1.py

34 lines
1.3 KiB
Python
Raw Permalink Normal View History

2025-09-05 14:29:33 +08:00
import os
# ================== 配置参数 ==================
# 图片所在的文件夹路径
2026-03-10 13:58:21 +08:00
image_folder = '/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/ailaidete/bag' # 修改为你的图片文件夹路径
2025-09-05 14:29:33 +08:00
# 输出的txt文件路径
2026-03-10 13:58:21 +08:00
output_txt = '/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/ailaidete/bag/image_list.txt' # 修改为你想保存的路径
2025-09-05 14:29:33 +08:00
# 支持的图片格式
image_extensions = {'.jpg', '.jpeg', '.png', '.bmp', '.webp', '.tiff', '.gif'}
# 是否保存绝对路径True还是仅文件名False
save_full_path = True # 设为 False 只保存文件名
# =============================================
# 获取所有图片文件
image_files = []
for root, dirs, files in os.walk(image_folder):
for file in files:
ext = os.path.splitext(file.lower())[1]
if ext in image_extensions:
file_path = os.path.join(root, file)
if save_full_path:
image_files.append(os.path.abspath(file_path))
else:
image_files.append(file)
# 写入txt文件
with open(output_txt, 'w', encoding='utf-8') as f:
for img_path in image_files:
f.write(img_path + '\n')
print(f"✅ 已保存 {len(image_files)} 张图片的路径到:\n {output_txt}")