添加--添加到处labelstudio注释脚本,根据解压后的label文件复制图片和注释到指定文件夹脚本

This commit is contained in:
haotian 2025-06-25 18:02:55 +08:00
parent 8df4dc1e6a
commit 52a3019fa6
3 changed files with 40 additions and 2 deletions

View File

@ -32,6 +32,6 @@ def filter_and_rename_labels(label_directory, output_label_directory):
file.writelines(filtered_lines)
# 示例用法
label_directory = '/home/admin-root/haotian/python哈汽锻8安全帽识别/DatasetHelmetHeadShoe/labels_raw' # 替换为你的标签文件夹路径
output_label_directory = '/home/admin-root/haotian/python哈汽锻8安全帽识别/DatasetHelmetHeadShoe/labels' # 替换为你希望保存过滤后标签的路径
label_directory = '/home/admin-root/haotian/python哈汽锻8安全帽识别/export/duan8_11/labels_raw' # 替换为你的标签文件夹路径
output_label_directory = '/home/admin-root/haotian/python哈汽锻8安全帽识别/export/duan8_11/labels' # 替换为你希望保存过滤后标签的路径
filter_and_rename_labels(label_directory, output_label_directory)

View File

@ -0,0 +1,17 @@
from label_studio_sdk import Client
import os
import shutil
# 连接 Label Studio
ls = Client(url='http://10.0.0.202:9432', api_key='ccbfb1432d8720230c8a0b9af53091bd3ef6e61c')
project = ls.get_project(id=5)
# 导出任务并处理图片
export_result = project.export_tasks(export_type='YOLO', export_location='export/yolo_obb_5.zip')
# os.makedirs("export/images", exist_ok=True)
# for task in export_result:
# if task['annotations']: # 仅处理已标注任务
# src_path = task['data']['image'] # 原始图片路径
# dst_path = f"export/images/{task['id']}.jpg"
# shutil.copy2(src_path, dst_path) # 复制图片到导出目录

View File

@ -0,0 +1,21 @@
from re import I
import shutil
import os
image_path = '/home/admin-root/haotian/锻8/tensorrtx/yolov8/images_20250624105811'
label_path = '/home/admin-root/haotian/python哈汽锻8安全帽识别/export/duan8_11/labels'
destination_image_path = '/home/admin-root/haotian/python哈汽锻8安全帽识别/DatasetHelmetHeadShoe/train/images'
destination_label_path = '/home/admin-root/haotian/python哈汽锻8安全帽识别/DatasetHelmetHeadShoe/train/labels'
image_name = [ t.split('.')[0] for t in os.listdir(label_path)]
for i in range(len(image_name)):
# 复制图片文件
shutil.copy2(os.path.join(image_path, image_name[i]+'.jpg'), os.path.join(destination_image_path, f'22_{i}.jpg'))
# 复制标签文件
shutil.copy2(os.path.join(label_path, image_name[i]+'.txt'), os.path.join(destination_label_path, f'22_{i}.txt'))
print(f"{i} finished")