| import os
|
| import shutil
|
| import glob
|
|
|
|
|
|
|
| source_root = r"G:\datasets\lolblurtest\test\low_blur_noise"
|
|
|
|
|
| target_dir = r"G:\IR_Experiment\DarkIR\test_input"
|
|
|
|
|
| def prepare_dataset():
|
| if not os.path.exists(source_root):
|
| print(f"❌ 错误:源目录不存在 -> {source_root}")
|
| return
|
|
|
|
|
| if os.path.exists(target_dir):
|
| shutil.rmtree(target_dir)
|
| os.makedirs(target_dir)
|
|
|
| print(f"🚀 开始从 {source_root} 抽取数据...")
|
|
|
|
|
| scene_folders = [f for f in os.listdir(source_root) if os.path.isdir(os.path.join(source_root, f))]
|
| count = 0
|
|
|
| for scene in scene_folders:
|
| scene_path = os.path.join(source_root, scene)
|
|
|
|
|
| images = [f for f in os.listdir(scene_path) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
|
|
| if images:
|
|
|
| img_name = images[0]
|
| src_file = os.path.join(scene_path, img_name)
|
|
|
|
|
| new_name = f"{scene}_{img_name}"
|
| dst_file = os.path.join(target_dir, new_name)
|
|
|
| shutil.copy2(src_file, dst_file)
|
| print(f" [提取] 场景 {scene}: {img_name} -> {new_name}")
|
| count += 1
|
|
|
| print(f"\n✅ 数据准备完毕!共抽取 {count} 张图片。")
|
| print(f"📂 输入文件夹: {target_dir}")
|
|
|
| if __name__ == "__main__":
|
| prepare_dataset() |