coco格式转yolo格式,标注软件是旷世labelbee

注意,这只是把单一123.jpg.json文件转化为123.txt
并没有把整体的json文件转换

import json

# 读取JSON文件
json_file_path = r'G:\bsh\dataset\flame_test_dataset\train\annotations\259.jpg.json'
with open(json_file_path, 'r') as json_file:
    data = json.load(json_file)

# 提取相关信息
image_width = data["width"]
image_height = data["height"]
objects = data["step_1"]["result"]

# 创建YOLO格式文本
yolo_txt = ""
for obj in objects:
    x = obj["x"]
    y = obj["y"]
    width = obj["width"]
    height = obj["height"]
    class_id = obj["attribute"]

    # 将坐标转换为YOLO格式(中心坐标/宽度/高度)
    x_center = (x+0.5*width) / image_width
    y_center = (y+0.5*height) / image_height
    width = width / image_width
    height = height / image_height

    yolo_txt += f"{class_id} {x_center:.6f} {y_center:.6f} {width:.6f} {height:.6f}\n"

# 将YOLO格式文本保存到文件
output_txt_path = r'G:\bsh\dataset\flame_test_dataset\train\annotations\259.txt'
with open(output_txt_path, 'w') as output_file:
    output_file.write(yolo_txt)

print(f"已将JSON数据转换为YOLO格式并保存到 {output_txt_path}。")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值