添加状态分类和液面分割
This commit is contained in:
@ -77,7 +77,7 @@ def split_dataset(
|
||||
if __name__ == "__main__":
|
||||
# 数据集路径
|
||||
images_dir = r"/home/hx/桌面/image/image" # 需要读取的所有图像文件夹路径
|
||||
labels_dir = r"/home/hx/桌面/image/2" # 需要读取的所有图像与之对应的txt标签文件夹路径
|
||||
labels_dir = r"/home/hx/桌面/image/image/2" # 需要读取的所有图像与之对应的txt标签文件夹路径
|
||||
|
||||
# 输出路径
|
||||
output_root = r"/home/hx/桌面/image" # 保存最终数据集的根目录
|
||||
|
||||
@ -202,9 +202,9 @@ def totxt(xml_path, out_path, class_mapping):
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 设置路径
|
||||
roxml_path = r"/home/hx/桌面/image/1" # 存放原始 XML 文件夹名字的路径
|
||||
dotaxml_path = r"/home/hx/桌面/image/2" # 存放 DOTA格式的 XML文件夹名字(小建议:先手动创建该文件夹,然后路径放在这里)
|
||||
out_path = r"/home/hx/桌面/image/2" # 存放 DOTA格式的 TXT 文件夹名字(小建议:先手动创建该文件夹,然后路径放在这里)
|
||||
roxml_path = r"/home/hx/桌面/image/image/1" # 存放原始 XML 文件夹名字的路径
|
||||
dotaxml_path = r"/home/hx/桌面/image/image/1" # 存放 DOTA格式的 XML文件夹名字(小建议:先手动创建该文件夹,然后路径放在这里)
|
||||
out_path = r"/home/hx/桌面/image/image/2" # 存放 DOTA格式的 TXT 文件夹名字(小建议:先手动创建该文件夹,然后路径放在这里)
|
||||
|
||||
# 第一步:将 XML 文件统一转换成旋转框的 XML 文件
|
||||
filelist = os.listdir(roxml_path)
|
||||
|
||||
73
yolo11_obb/move_xml_files.py
Normal file
73
yolo11_obb/move_xml_files.py
Normal file
@ -0,0 +1,73 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
def move_xml_files(source_folder, target_folder, recursive=True):
|
||||
"""
|
||||
将 source_folder 中的 .xml 文件移动到 target_folder
|
||||
|
||||
:param source_folder: 源文件夹路径
|
||||
:param target_folder: 目标文件夹路径
|
||||
:param recursive: 是否递归查找子文件夹
|
||||
"""
|
||||
# 检查源文件夹是否存在
|
||||
if not os.path.exists(source_folder):
|
||||
print(f"❌ 源文件夹不存在: {source_folder}")
|
||||
return
|
||||
|
||||
# 如果目标文件夹不存在,创建它
|
||||
os.makedirs(target_folder, exist_ok=True)
|
||||
|
||||
# 统计移动的文件数
|
||||
moved_count = 0
|
||||
|
||||
# 选择遍历方式
|
||||
if recursive:
|
||||
# 递归遍历所有子文件夹
|
||||
for root, dirs, files in os.walk(source_folder):
|
||||
for file in files:
|
||||
if file.lower().endswith('.xml'):
|
||||
src_path = os.path.join(root, file)
|
||||
dst_path = os.path.join(target_folder, file)
|
||||
|
||||
# 防止重名冲突(可选)
|
||||
counter = 1
|
||||
original_dst = dst_path
|
||||
while os.path.exists(dst_path):
|
||||
name, ext = os.path.splitext(file)
|
||||
dst_path = os.path.join(target_folder, f"{name}_{counter}{ext}")
|
||||
counter += 1
|
||||
|
||||
shutil.move(src_path, dst_path)
|
||||
print(f"✅ 移动: {src_path} -> {dst_path}")
|
||||
moved_count += 1
|
||||
else:
|
||||
# 只遍历当前目录
|
||||
for file in os.listdir(source_folder):
|
||||
src_path = os.path.join(source_folder, file)
|
||||
if os.path.isfile(src_path) and file.lower().endswith('.xml'):
|
||||
dst_path = os.path.join(target_folder, file)
|
||||
|
||||
# 防止重名(可选)
|
||||
counter = 1
|
||||
original_dst = dst_path
|
||||
while os.path.exists(dst_path):
|
||||
name, ext = os.path.splitext(file)
|
||||
dst_path = os.path.join(target_folder, f"{name}_{counter}{ext}")
|
||||
counter += 1
|
||||
|
||||
shutil.move(src_path, dst_path)
|
||||
print(f"✅ 移动: {src_path} -> {dst_path}")
|
||||
moved_count += 1
|
||||
|
||||
print(f"\n🎉 完成!共移动 {moved_count} 个 XML 文件。")
|
||||
|
||||
|
||||
# ==========================
|
||||
# 使用示例
|
||||
# ==========================
|
||||
if __name__ == "__main__":
|
||||
source = "/home/hx/桌面/image/image" # 修改为你的源文件夹
|
||||
target = "/home/hx/桌面/image/image/1" # 修改为你的目标文件夹
|
||||
|
||||
move_xml_files(source, target, recursive=True)
|
||||
Reference in New Issue
Block a user