Commit 322f0633 authored by oscar's avatar oscar

提交新的空点云信息和老json文件到新json文件的转换

parent 2b8e05d9
import os
import json
import glob
import numpy
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
numpy.uint16, numpy.uint32, numpy.uint64)):
return int(obj)
elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32,numpy.float64)):
return float(obj)
elif isinstance(obj, (numpy.ndarray,)):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
if __name__ == '__main__':
dir_name = "7_1"
old_json_path = "D:/shared/N7_1/jsons"
save_json_path = "D:/shared/N7_1/"
old_json_list = glob.glob(os.path.join(old_json_path,"*.json"))
save_json = {}
save_json["annotations"] = []
for jsn_f in old_json_list:
with open(jsn_f, 'r',encoding='utf-8',errors='ignore') as fp:
jsn = json.load(fp)
new_jsn = {}
new_jsn["fileuri"] = dir_name + "/pcd/" + jsn["baseInfo"]["fileName"]
new_jsn["labels_box3D"] = []
for old_info in jsn["markResult"]["objects"]:
new_info = {}
new_info["box3D"] = {}
new_info["box3D"]["translation"] = { "x": old_info["center"]["x"],"y":old_info["center"]["y"],"z":old_info["center"]["z"]}
new_info["box3D"]["rotation"] = { "x": old_info["rotation"]["x"],"y":old_info["rotation"]["y"],"z":old_info["rotation"]["z"],"w":old_info["rotation"]["w"]}
new_info["box3D"]["size"] = { "x": old_info["dimensions"]["length"],"y":old_info["dimensions"]["width"],"z":old_info["dimensions"]["height"]}
new_info["category"] = old_info["content"]["label"]
new_jsn["labels_box3D"].append(new_info)
save_json["annotations"].append(new_jsn)
save_json_name = save_json_path + "N" + dir_name + ".json"
with open(save_json_name,'w') as file_o:
json.dump(save_json,file_o,cls=NumpyEncoder,indent=4)
str = "10_1/pcd/1629734723.170913000.pcd"
print(str.split('/'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment