日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

labelme的 json格式转化成自己的json格式

發布時間:2024/9/21 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 labelme的 json格式转化成自己的json格式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

labelme的json格式:

{"version": "4.5.6","flags": {},"shapes": [{"label": "1","points": [[1609.6923076923076,884.6153846153846],[1988.1538461538462,1172.3076923076924]],"group_id": null,"shape_type": "rectangle","flags": {}},{"label": "0","points": [[1352.7692307692307,3.0769230769230766],[1925.076923076923,578.4615384615385]],"group_id": null,"shape_type": "rectangle","flags": {}}],"imagePath": "..\\imgs\\0001.jpg","imageData": null,"imageHeight": 1492,"imageWidth": 2040 }

自己的json格式:

{"name": "0001.jpg","frames": [{"timestamp": "10000","objects": [{"category": "1","id": 0,"attributes": {"occluded": false,"truncated": false,"trafficLightCorlor": "none"},"box2d": {"x1": 1609.6923076923076,"y1": 884.6153846153846,"x2": 1988.1538461538462,"y2": 1172.3076923076924}},{"category": "0","id": 1,"attributes": {"occluded": false,"truncated": false,"trafficLightCorlor": "none"},"box2d": {"x1": 1352.7692307692307,"y1": 3.0769230769230766,"x2": 1925.076923076923,"y2": 578.4615384615385}}]}],"imagePath": "..\\imgs\\0001.jpg","imageData": null,"imageHeight": 1492,"imageWidth": 2040 }

轉換代碼:

import argparse import json import cv2 import numpy as np import os''' parser = argparse.ArgumentParser() parser.add_argument("square", help="display a square of a given number", type=int) args = parser.parse_args() print(args.square** 2) ''' def json_for_train(from_json, to_json):final_json = dict()final_json['name'] = Nonefinal_json['frames'] = None#解析from_jsonload_f = open(from_json)anno = json.load(load_f)version = anno["version"]flags = anno["flags"]imagePath = anno["imagePath"]imageData = anno["imageData"]imageHeight = anno["imageHeight"]imageWidth = anno["imageWidth"]shapes = []object1=[]fname=imagePath.split("\\")[-1] #獲得圖片的名字#print(fname)classes_locations = anno["shapes"]i=-1for cls in classes_locations:i=i+1print(cls)attr = {"occluded":False,"truncated": False,"trafficLightCorlor": "none"}print(cls.get("points"))box = {"x1": cls.get("points")[0][0],"y1": cls.get("points")[0][1],"x2": cls.get("points")[1][0],"y2": cls.get("points")[1][1]}#print(box)print("label:"+cls.get("label"))mid = {"category": cls.get("label"),"id": i,"attributes": attr,"box2d": box}object1.append(mid)print("******")print(object1)print("====")shape = {"timestamp": "10000","objects": object1,}shapes.append(shape)print("----")#print(shapes)result_json = {"name": fname,"frames": shapes,"imagePath": imagePath,"imageData": imageData,"imageHeight": imageHeight,"imageWidth": imageWidth}print(result_json)labelme_json = json.dumps(result_json, indent=4, ensure_ascii=False)with open(to_json, "w+") as fp:fp.write(labelme_json)if __name__ == '__main__':from_jsons = './annotation/'to_jsons = './annotation_new/'dir_jsons = os.listdir(from_jsons)print(dir_jsons)i = 1for dir_json in dir_jsons:print("第" + str(i) + "/" + str(len(dir_jsons)) + "張 ===>" + dir_json)i += 1from_name = os.path.join(from_jsons, dir_json)to_name = os.path.join(to_jsons, dir_json)try:json_for_train(from_name, to_name)except Exception as e:print(e)

總結

以上是生活随笔為你收集整理的labelme的 json格式转化成自己的json格式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。