当前位置: 首页 > news >正文

将CVAT点云格式标注格式由datumaro转换为kitti格式

依赖json与os

输入:default.json

输出每个点云对应一个标签

参考:3D点云目标检测数据集标注工具 保姆级教程——CVAT (附json转kitti代码)_3d点云标注工具-CSDN博客

import json
import osdef json_to_kitti(json_path, output_dir):with open(json_path, 'r') as f:data = json.load(f)labels = data['categories']['label']['labels']os.makedirs(output_dir, exist_ok=True)# 遍历每一帧for item in data['items']:item_id = item['id']  # 使用 JSON 中的 'id' 值annotations = item['annotations']# 输出 KITTI 格式文件的路径,使用 'id' 命名output_path = f"{output_dir}/{item_id}.txt"with open(output_path, 'w') as f_out:# 遍历每个标注for annotation in annotations:label_id = annotation['label_id']label_name = labels[label_id]['name']# 提取 3D 立方体信息position = annotation['position']rotation = annotation['rotation']scale = annotation['scale']# KITTI 格式字段truncated = 0  # 默认为 0,因为未提供截断信息occluded = 1 if annotation['attributes']['occluded'] else 0alpha = rotation[2]  # 使用 Z 轴的旋转角作为方向角bbox_left = 0.0  # 2D 边界框位置,点云标注中通常为 0bbox_top = 0.0bbox_right = 0.0bbox_bottom = 0.0height = scale[2]  # 物体高度width = scale[0]   # 物体宽度length = scale[1]  # 物体长度x = position[0]    # 物体在相机坐标系中的 x 坐标y = position[1]    # 物体在相机坐标系中的 y 坐标z = position[2]    # 物体在相机坐标系中的 z 坐标rotation_y = rotation[2]  # KITTI 中物体绕 Y 轴的旋转角度# 将数据写入到 KITTI 格式文件f_out.write(f"{label_name} {truncated} {occluded} {alpha} "f"{bbox_left} {bbox_top} {bbox_right} {bbox_bottom} "f"{height} {width} {length} {x} {y} {z} {rotation_y}\n")json_to_kitti('/home/wisdom/pyprojects/dataset/uat1/annotations/default.json', '/home/wisdom/pyprojects/dataset/uat1/annotations/kitti_labels')

http://www.xdnf.cn/news/1056817.html

相关文章:

  • 软件测试用例(一)
  • Java锁机制:ReentrantLock深度解析与锁粒度优化实践(时序图详解)
  • 交互式编程:编程范式的静默革命
  • 在windows10上安装nvm以及配置环境
  • 【推荐】城市灾害应急管理系统【面试模拟题目——字节跳动面试原题】
  • java复习 13
  • (二十八)深度解析领域特定语言(DSL)第六章——语法分析:巴科斯-诺尔范式
  • 适合 Acrobat DC 文件类型解析
  • 6.15 操作系统面试题 锁 内存管理
  • Appium + .NET 测试全流程
  • 【模拟 贪心】B4207 [常州市赛 2021] 战士|普及+
  • XP POWER EJ ET EY FJ FR 系列软件和驱动程序和手侧
  • verl multi-node train 教程
  • 红花多组学挖掘OGT1-文献精读146
  • Git开发流程
  • 两个渐开线花键需要共用一把滚刀
  • 【unitrix】 1.8 常量约束(const_traits.rs)
  • SOLIDWORKS的“12”个简单高效的草图绘制规则,全部应用成为草图大师!
  • SpringBoot常用注解
  • C++ Builder xe 关于ListView的自然排序功能排序效果与Windows资源管理器相同
  • 蛋白分析工具和数据库
  • 鼓励建设性对抗,反对攻击性评论
  • 计量经济学EViews软件题与证明题预测
  • Java 多线程轮流打印 ABC 的 4 种实现方式详解
  • 关于脉冲功率技术的认识
  • 【Python训练营打卡】day53 @浙大疏锦行
  • Java30:SpringBoot3
  • 数据库优化实战分享
  • Python 基础语法(3)【适合0基础】
  • 你听过网关支付吗?它是什么?