python实现labelme_json_to_dataset数据集标签批量提取

python实现labelme_json_to_dataset数据集标签批量提取

讲解

代码

import os
import shutil


def take_labels_rename(or_path, tar_path):
    determination = tar_path
    if not os.path.exists(determination):
        os.makedirs(determination)

    path = or_path
    folders = os.listdir(path)
    for folder in folders:
        print(str(folders))
        dir = path + '/' + str(folder)
        files = os.listdir(dir)
        for file in files:
            print(str(files))
            if str(file) == "label.png":
                print("{} from {}".format(str(file), str(folder)))
                source = dir + '/' + str(file)
                folder_name = str(folder).split('_')[0]
                deter = determination + '/' + str(folder_name)+'.png'
                shutil.copyfile(source, deter)


if __name__ == "__main__":
    print("hellow world")
    take_labels_rename(r"", r"")#原始路径及存储路径

运行结果
运行前
python实现labelme_json_to_dataset数据集标签批量提取_第1张图片

运行过程
python实现labelme_json_to_dataset数据集标签批量提取_第2张图片
运行结果
python实现labelme_json_to_dataset数据集标签批量提取_第3张图片
python实现labelme_json_to_dataset数据集标签批量提取_第4张图片

你可能感兴趣的:(文件处理小程序,python,函数式编程)