使用labelme标注的json标签mask可视化

一、在labelme解释器下。

二、分两步走(假设我的原始图片和标注结果,在D:\Huawei_image)

使用labelme标注的json标签mask可视化_第1张图片

import os
 
json_folder = r"D:\Huawei_image"
#  获取文件夹内的文件名
FileNameList = os.listdir(json_folder)
#  激活labelme环境
os.system("activate labelme")
for i in range(len(FileNameList)):
    #  判断当前文件是否为json文件
    if(os.path.splitext(FileNameList[i])[1] == ".json"):
        json_file = json_folder + "\\" + FileNameList[i]
        #  将该json文件转为png
        os.system("labelme_json_to_dataset " + json_file)
import os
import shutil

JPG_folder = r"D:\Huawei_image"
Paste_JPG_folder = r"D:\Huawei_image\img2"
Paste_label_folder = r"D:\Huawei_image\label2"
Paste_label_viz_folder = r"D:\Huawei_image\label_viz"
#我原始图片的扩展名
extentName=".bmp"

folder = [JPG_folder, Paste_JPG_folder, Paste_label_folder, Paste_label_viz_folder]
for folder_x in folder:
    if not os.path.exists(folder_x):
        os.makedirs(folder_x)

#  获取文件夹内的文件名
FileNameList = os.listdir(JPG_folder)
NewFileName = 1
for i in range(len(FileNameList)):
    #  判断当前文件是否为json文件
    if (os.path.splitext(FileNameList[i])[1] == extentName):
        #  复制jpg文件
        JPG_file = JPG_folder + "\\" + FileNameList[i]
        new_JPG_file = Paste_JPG_folder + "\\" + str(NewFileName) + ".jpg"
        shutil.copyfile(JPG_file, new_JPG_file)

        #  复制label文件
        jpg_file_name = FileNameList[i].split(".", 1)[0]
        label_file = JPG_folder + "\\" + jpg_file_name + "_json\\label.png"
        new_label_file = Paste_label_folder + "\\" + str(NewFileName) + ".png"
        shutil.copyfile(label_file, new_label_file)

        #  复制label_viz文件
        jpg_file_name = FileNameList[i].split(".", 1)[0]
        label_viz_file = JPG_folder + "\\" + jpg_file_name + "_json\\label_viz.png"
        new_label_viz_file = Paste_label_viz_folder + "\\" + str(NewFileName) + ".png"
        shutil.copyfile(label_viz_file, new_label_viz_file)

        #  文件序列名+1
        NewFileName = NewFileName + 1

使用labelme标注的json标签mask可视化_m0_61899108的博客-CSDN博客

你可能感兴趣的:(人工智能,json)