当前位置: 首页 > 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.dtcms.com/a/251993.html

相关文章:

  • 【IQA技术专题】-PSNR和SSIM
  • SylixOS armv7 任务切换
  • (二十八)深度解析领域特定语言(DSL)第六章——语法分析:巴科斯-诺尔范式
  • 【NOI 专题训练】概率期望
  • 【Canvas与卡通】天龙通宝
  • 分割数据集 - 足球运动员分割数据集下载
  • FTP 并不适合用在两个计算机之间共享读写文件 为什么
  • 实验绘图参考-0615版(自用)
  • 动手实践:LangChain流图可视化全解析
  • 超子说物联网-MQTT_笔记1---通过EMQX搭建MQTT服务器
  • FastAPI-MCP构建自定义MCP工具实操指南
  • 《一元线性回归:从基础到应用及模型处理》
  • 【Dify系列】【Dify 核心功能】【应用类型】【五】【工作流】
  • 包含30个APP客户端UI界面的psd适用于旅游酒店项目
  • VMware Workstation 添加PCI设备显卡直连
  • 深度学习入门知识
  • 信息学奥赛一本通 1541:【例 1】数列区间最大值
  • 把Cmakelist.txt转化为Qt Pro文件的方法
  • Vue3 跨多个组件方法调用:简洁实用的解决方案
  • Elasticsearch:什么是混合搜索?
  • 【大厂机试题解法笔记】字符串加密
  • 智慧流水线在ESOP数字工厂中的作用
  • leetcode146-LRU缓存
  • linux 下 Doris 单点部署
  • 【极客时间】大模型RAG进阶实战营毕业总结
  • 【AI大模型】Elasticsearch9 + 通义大模型实现语义检索操作详解
  • Java设计模式完整学习指南(23+4种模式)
  • semi-BATNet
  • 如何让 AI 接入自己的 API?我开发了一个将 OpenAPI 文档转为 MCP 服务的工具
  • 股指期货的多空策略是什么?