精灵标注助手json转csv

本文介绍了一个使用Python脚本将JSON格式的目标检测数据转换为YOLOv3所需的训练格式的过程。该脚本读取指定目录下的JSON文件,解析路径、尺寸和边界框信息,并按比例缩放至YOLO所需的格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import os
import cv2
import numpy as np
import json
from cfg import *

with open(LABEL_FILE, "w+") as f:
    for json_file in os.listdir("F:\A_I\myyolo3\data\label"):
        with open(os.path.join("F:\A_I\myyolo3\data\label", json_file), "r") as jf:
            j = json.load(jf)
            print(j)
            pic = j['path'].split("\\")[-1]
            boxes = j['outputs']['object']
            wh = j['size']
            w, h = wh['width'], wh['height']

            w_scale, h_scale = w / IMG_WIDTH, h / IMG_HEIGHT

            f.write(pic)
            for box in boxes:
                bndbox = box['bndbox']
                _x1, _y1, _x2, _y2 = bndbox['xmin'], bndbox['ymin'], bndbox['xmax'], bndbox['ymax']
                _w, _h = _x2 - _x1, _y2 - _y1
                _w0_5, _h0_5 = _w / 2, _h / 2
                _cx, _cy = _x1 + _w0_5, _y1 + _h0_5
                x1, y1, w, h = int(_cx / w_scale), int(_cy / h_scale), int(_w / w_scale), int(_h / h_scale)
                f.write(f" {int(box['name'])} {x1} {y1} {w} {h}")
            f.write("\n")
            f.flush()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值