VIA注釈ツールによって生成されたJSON形式のファイルをpng形式のデータラベルに変換します



Convert Json Format File Generated Via Annotation Tool Png Format Data Label



VGG Image Annotator(VIA)は、高速でシンプルなターゲット検出および注釈ツールであり、公式Webサイトです。 import os import numpy as np import cv2 as cv import json import skimage dataset_dir='/home/fcc/crack_via_label' subset='spalling' json_path='spalling.json' output_path = '/home/fcc/crack_via_label/spalling_label/' dataset_dir = os.path.join(dataset_dir, subset) # We mostly care about the x and y coordinates of each region annotations = json.load(open(os.path.join(dataset_dir, json_path)))#Load json file #json file dictionary nested dictionary, dictionary nested list. In order to get the key x, y point data, you have to split the dictionary and list one by one. annotations = list(annotations.values()) annotations_point=annotations[1] annotations_point=list(annotations_point.values()) annotations_point = [a for a in annotations_point if a['regions']] for i in range(len(annotations_point)): #Traverse the information of each picture filename=annotations_point[i]['filename'] mask = np.zeros([608, 608, 3],dtype=np.uint8)#Set the size of the output image dimension for j in range(len(annotations_point[i]['regions'])):#A map may have multiple labeled regions #json file dictionary nested dictionary, dictionary nested list. In order to get the key x, y point data, you have to split the dictionary and list one by one. point = annotations_point[i]['regions'][j].values()[0] point_x=point['all_points_x']#Extract x point data point_y=point['all_points_y']#Extract y point data rr, cc = skimage.draw.polygon(point_y, point_x)#Draw the outline, get the coordinates of all points in the outline mask[rr, cc, 0] = 255# fill color, 255 0 0: blue 0 255 0: green 0 0 255: red #cv.imshow('mask_'+filename,mask)#Display and view while debugging #cv.waitKey(0) cv.imwrite(output_path+filename,mask)#Save png format tags

出力結果の例は次のとおりです。