Skip to content

Camera Object Bounding Box Issues #154

@shamkhalshukurov

Description

@shamkhalshukurov

Hello. I have taken two boxes from the .pkl file as an example.. The coordinates of the box are shifting, is this normal? This problem exists in all boxes in this frame and other frames. Can you help me?

import numpy as np
import cv2
import pandaset
from pandaset import geometry

DATASET_PATH = "dataset" # öz yolunuzu yazın
DATASET_IDX = "001"
SEQ_IDX = 0
CAMERA_NAME = "back_camera" # back.jpg üçün

dataset = pandaset.DataSet(DATASET_PATH)
seq = dataset[DATASET_IDX]
seq.load()

camera = seq.camera[CAMERA_NAME]
camera_data = camera[SEQ_IDX] # PIL.Image
camera_pose = camera.poses[SEQ_IDX] # pandaset pose dict
camera_intr = camera.intrinsics # pandaset intrinsics

def get_corners_world(bbox_center, bbox_size, yaw):
pos_x, pos_y, pos_z = bbox_center
dim_x, dim_y, dim_z = bbox_size
corners = geometry.center_box_to_corners(
[pos_x, pos_y, pos_z, dim_x, dim_y, dim_z, yaw]
)
return np.array(corners) # (8, 3)

def world_to_cam_center(center_world, camera_pose_dict):
import transforms3d as t3d
heading = camera_pose_dict["heading"]
position = camera_pose_dict["position"]
quat = np.array([heading["w"], heading["x"], heading["y"], heading["z"]])
t_wc = np.array([position["x"], position["y"], position["z"]])
R_wc = t3d.quaternions.quat2mat(quat)
trans = np.linalg.inv(
t3d.affines.compose(t_wc, R_wc, [1.0, 1.0, 1.0])
)
pt = trans[:3, :3] @ np.array(center_world) + trans[:3, 3]
return pt

-----------------------------

BBox çizməsi — pandaset edge sırası

-----------------------------

def draw_bbox_on_img(img, pts_2d_all, color=(0, 0, 255), thickness=2):

edge_sets = [
    [0, 1, 2, 3, 0],
    [4, 5, 6, 7, 4],
    [0, 4],
    [1, 5],
    [2, 6],
    [3, 7],
]

for edgeset in edge_sets:
    for k in range(len(edgeset) - 1):
        i, j = edgeset[k], edgeset[k + 1]
        pi = tuple(pts_2d_all[i].astype(int))
        pj = tuple(pts_2d_all[j].astype(int))
        cv2.line(img, pi, pj, color, thickness)

return img

-----------------------------

MAIN

-----------------------------

def main():
# PIL → OpenCV
img = cv2.cvtColor(np.array(camera_data), cv2.COLOR_RGB2BGR)
img_h, img_w = img.shape[:2]
print("Image size:", img_w, img_h)

# ========================================
# BOUNDING BOX-LAR
# ========================================
bboxes = [
    ((-5.559, -10.021, 0.58),  (1.762, 4.656, 1.698), -0.8788),
    ((-10.9,  -10.0,   0.8),   (1.9,   4.0,   1.7),   -0.71),
    (( 8.966,  14.093, 0.633), (1.934, 4.162, 1.555), -0.781),
]

colors = [
    (0,   0,   255),
    (0,   255,   0),
    (255,   0,   0),
    (255, 255,   0),
    (255,   0, 255),
]

for idx, (bbox_center, bbox_size, yaw) in enumerate(bboxes):

    # 1) Center kameranın önündədir?
    center_cam = world_to_cam_center(bbox_center, camera_pose)
    if center_cam[2] < 0.0:
        print(f"BBox {idx+1}: arxadadır (Z={center_cam[2]:.2f}), skip")
        continue

    # 2) Pandaset geometry ilə corners al
    corners_world = get_corners_world(bbox_center, bbox_size, yaw)


    pts_2d, _, _ = geometry.projection(
        lidar_points   = corners_world,
        camera_data    = camera_data,
        camera_pose    = camera_pose,
        camera_intrinsics = camera_intr,
        filter_outliers= False          # corner-ləri kəsməsin
    )

    if pts_2d.shape[0] == 0:
        print(f"BBox {idx+1}: proyeksiya boşdur, skip")
        continue

    print(f"BBox {idx+1}: center Z={center_cam[2]:.2f}, pts_2d=\n", pts_2d)

    color = colors[idx % len(colors)]
    img   = draw_bbox_on_img(img, pts_2d, color=color, thickness=2)

cv2.imwrite("output_bbox.jpg", img)
cv2.imshow("BBox", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

if name == "main":
main()

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions