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

编程入门 行业动态 更新时间:2024-10-25 18:28:26

coco<a href=https://www.elefans.com/category/jswz/34/1771175.html style=格式转yolo格式,标注软件是旷世labelbee"/>

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_widthy_center = (y+0.5*height) / image_heightwidth = width / image_widthheight = height / image_heightyolo_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}。")

更多推荐

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

本文发布于:2023-12-06 03:56:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1666364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:格式   软件   coco   labelbee   yolo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!