Skip to main content

3D 바운딩 박스 변환

PCD(Point Cloud Data)용 3D 바운딩 박스 어노테이션의 V1/V2 양방향 변환 가이드입니다.

데이터 구조

V1 구조

# annotations
{
"id": "bbox3d_1",
"tool": "3d_bounding_box",
"isLocked": False,
"isVisible": True,
"isValid": True,
"classification": {
"class": "car",
"confidence": 0.95
},
"label": ["car"]
}

# annotationsData
{
"id": "bbox3d_1",
"psr": {
"position": {"x": 10.5, "y": 20.3, "z": 1.2},
"scale": {"x": 4.5, "y": 2.0, "z": 1.5},
"rotation": {"x": 0, "y": 0, "z": 0.785} # 라디안
}
}

V2 구조

{
"id": "bbox3d_1",
"classification": "car",
"attrs": [
{"name": "confidence", "value": 0.95}
],
"data": {
"position": {"x": 10.5, "y": 20.3, "z": 1.2},
"scale": {"x": 4.5, "y": 2.0, "z": 1.5},
"rotation": {"x": 0, "y": 0, "z": 0.785}
}
}

변환 규칙

V1 → V2

V1 필드V2 필드
psr.positiondata.position
psr.scaledata.scale
psr.rotationdata.rotation
classification.classclassification
classification.{other}attrs[{name, value}]

V2 → V1

V2 필드V1 필드
data.positionpsr.position
data.scalepsr.scale
data.rotationpsr.rotation
classificationclassification.class
attrs[{name, value}]classification.{name: value}

사용 예제

기본 변환

from synapse_sdk.utils.converters.dm import convert_v1_to_v2, convert_v2_to_v1

# V1 3D 바운딩 박스 데이터
v1_data = {
"annotations": {
"pcd_1": [
{
"id": "3DBbox123",
"tool": "3d_bounding_box",
"classification": {"class": "car", "confidence": 0.95}
}
]
},
"annotationsData": {
"pcd_1": [
{
"id": "3DBbox123",
"psr": {
"position": {"x": 10.5, "y": 20.3, "z": 1.2},
"scale": {"x": 4.5, "y": 2.0, "z": 1.5},
"rotation": {"x": 0, "y": 0, "z": 0.785}
}
}
]
}
}

# V2로 변환
result = convert_v1_to_v2(v1_data)
annotation_data = result["annotation_data"]

# V2 결과 확인
bbox3d = annotation_data["pcds"][0]["3d_bounding_box"][0]
print(bbox3d["data"]["position"]) # {"x": 10.5, "y": 20.3, "z": 1.2}
print(bbox3d["data"]["scale"]) # {"x": 4.5, "y": 2.0, "z": 1.5}
print(bbox3d["classification"]) # "car"

라운드트립 검증

def verify_3d_bbox_roundtrip(v1_original):
"""3D 바운딩 박스 라운드트립 검증"""
# V1 → V2 → V1
v2_result = convert_v1_to_v2(v1_original)
v1_restored = convert_v2_to_v1(v2_result)

# PSR 비교
orig_psr = v1_original["annotationsData"]["pcd_1"][0]["psr"]
rest_psr = v1_restored["annotationsData"]["pcd_1"][0]["psr"]

for key in ["position", "scale", "rotation"]:
for axis in ["x", "y", "z"]:
assert orig_psr[key][axis] == rest_psr[key][axis]

print("3D 바운딩 박스 라운드트립 검증 성공")

verify_3d_bbox_roundtrip(v1_data)

PSR 좌표계

3D 바운딩 박스는 PSR(Position, Scale, Rotation) 형식을 사용합니다:

필드설명단위
position.xX 위치미터
position.yY 위치미터
position.zZ 위치미터
scale.xX 크기 (길이)미터
scale.yY 크기 (너비)미터
scale.zZ 크기 (높이)미터
rotation.xX축 회전라디안
rotation.yY축 회전라디안
rotation.zZ축 회전 (요)라디안