import json
import os
import glob
import os.path as osp
def labelme2yolov2Seg(jsonfilePath="", resultDirPath="", classList=["buds"]):
if (not os.path.exists(resultDirPath)):
os.mkdir(resultDirPath)
jsonfileList = glob.glob(osp.join(jsonfilePath, "*.json"))
print(jsonfileList)
for jsonfile in jsonfileList:
with open(jsonfile, "r") as f:
file_in = json.load(f)
shapes = file_in["shapes"]
with open(resultDirPath + "\\" + jsonfile.split("\\")[-1].replace(".json", ".txt"), "w") as file_handle:
for shape in shapes:
file_handle.writelines(str(classList.index(shape["label"])) + " ")
for point in shape["points"]:
x = point[0] / file_in["imageWidth"]
json 转为txt
于 2024-01-13 09:29:02 首次发布