onecocotoyolo文件一对一10.26

import json
import os

def normalize_coordinates(x, y, img_width, img_height):
    normalized_x = x / img_width
    normalized_y = y / img_height
    return normalized_x, normalized_y

def convert_to_yolo(json_file, output_file):
    labels = ["unlabeled", "ego vehicle", "rectification border", "out of roi", "static", "dynamic", "ground", "road", "sidewalk", "parking", "rail track", "building", "wall", "fence", "guard rail", "bridge", "tunnel", "pole", "polegroup", "traffic light", "traffic sign", "vegetation", "terrain", "sky", "person", "rider", "car", "truck", "bus", "caravan", "trailer", "train", "motorcycle", "bicycle", "license plate","cargroup","bicyclegroup",'persongroup']

    with open(json_file, 'r') as f:
        data = json.load(f)

    base_name = os.path.splitext(os.path.basename(json_file))[0]
    output_file = f"{base_name}.txt"

    with open(output_file, 'w') as f:
        for obj in data['objects']:
            label = obj['label']
            if label in labels:
                label_index = labels.index(label)

                f.write(f"{label_index} ")

                for point in obj['polygon']:
                    x, y = normalize_coordinates(point[0], point[1], data['imgWidth'], data['imgHeight'])
                    f.write(f"{x} {y} ")

                f.write("\n")


# Example usage
json_folder = r"E:\jsonlabels\jsonlabels\test"

json_files = [f for f in os.listdir(json_folder) if f.endswith('.json')]

for json_file in json_files:
    json_path = os.path.join(json_folder, json_file)
    convert_to_yolo(json_path, json_folder)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
housing.csv是一个公开的数据集,您可以在网上下载到。以下是一个housing.csv文件的示例,仅供参考: ``` CRIM,ZN,INDUS,CHAS,NOX,RM,AGE,DIS,RAD,TAX,PTRATIO,B,LSTAT,MEDV 0.00632,18.0,2.31,0,0.538,6.575,65.2,4.09,1,296,15.3,396.9,4.98,24.0 0.02731,0.0,7.07,0,0.469,6.421,78.9,4.9671,2,242,17.8,396.9,9.14,21.6 0.02729,0.0,7.07,0,0.469,7.185,61.1,4.9671,2,242,17.8,392.83,4.03,34.7 0.03237,0.0,2.18,0,0.458,6.998,45.8,6.0622,3,222,18.7,394.63,2.94,33.4 0.06905,0.0,2.18,0,0.458,7.147,54.2,6.0622,3,222,18.7,396.9,5.33,36.2 0.02985,0.0,2.18,0,0.458,6.43,58.7,6.0622,3,222,18.7,394.12,5.21,28.7 0.08829,12.5,7.87,0,0.524,6.012,66.6,5.5605,5,311,15.2,395.6,12.43,22.9 0.14455,12.5,7.87,0,0.524,6.172,96.1,5.9505,5,311,15.2,396.9,19.15,27.1 0.21124,12.5,7.87,0,0.524,5.631,100.0,6.0821,5,311,15.2,386.63,29.93,16.5 0.17004,12.5,7.87,0,0.524,6.004,85.9,6.5921,5,311,15.2,386.71,17.1,18.9 0.22489,12.5,7.87,0,0.524,6.377,94.3,6.3467,5,311,15.2,392.52,20.45,15.0 0.11747,12.5,7.87,0,0.524,6.009,82.9,6.2267,5,311,15.2,396.9,13.27,18.9 0.09378,12.5,7.87,0,0.524,5.889,39.0,5.4509,5,311,15.2,390.5,15.71,21.7 0.62976,0.0,8.14,0,0.538,5.949,61.8,4.7075,4,307,21.0,396.9,8.26,20.4 0.63796,0.0,8.14,0,0.538,6.096,84.5,4.4619,4,307,21.0,380.02,10.26,18.2 0.62739,0.0,8.14,0,0.538,5.834,56.5,4.4986,4,307,21.0,395.62,8.47,19.9 1.05393,0.0,8.14,0,0.538,5.935,29.3,4.4986,4,307,21.0,386.85,6.58,23.1 0.7842,0.0,8.14,0,0.538,5.99,81.7,4.2579,4,307,21.0,386.75,14.67,17.5 0.80271,0.0,8.14,0,0.538,5.456,36.6,3.7965,4,307,21.0,288.99,11.69,20.2 0.7258,0.0,8.14,0,0.538,5.727,69.5,3.7965,4,307,21.0,390.95,11.28,18.2 0.52338,0.0,6.2,0,0.507,6.095,65.1,3.9454,8,307,17.4,395.38,3.11,41.7 0.87179,0.0,6.2,0,0.507,6.122,52.8,4.0029,8,307,17.4,396.9,5.52,22.8 0.88125,0.0,21.89,0,0.624,5.637,94.7,1.9799,4,437,21.2,396.9,18.34,14.3 ``` 其中,每一行代表一个房屋的属性,包括: - CRIM:城镇人均犯罪率 - ZN:占地面积超过 25,000 平方英尺的住宅用地比例 - INDUS:城镇中非零售业商业用地比例 - CHAS:边界位于 Charles River 的情况,如果是则为 1,否则为 0 - NOX:环保指数 - RM:每栋住宅的平均房间数 - AGE:1940 年以前建成的自用房屋比例 - DIS:到波士顿五个就业中心的加权距离 - RAD:距离辐射性公路的便利指数 - TAX:每 10,000 美元的全额财产税率 - PTRATIO:城镇中学生与教师的比例 - B:黑人比例 - LSTAT:人口中地位低下者的比例 - MEDV:自用房屋房价中位数

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值