SPALaboratory / SiT-Dataset

SiT Dataset: Socially Interactive Pedestrian Trajectory Dataset for Social Navigation Robots [NeurIPS 2023]
https://spalaboratory.github.io/SiT/
Apache License 2.0
49 stars 3 forks source link

bouding box does not match to object #11

Open nghiabka opened 3 days ago

nghiabka commented 3 days ago

Thank you for your excellent work.

I am trying to draw ground truth with point cloud data. However, the bounding box does not match the object. I am so confused. I would be appreciate any comments or suggestions. Thank you. Screenshot 2024-11-12 102454

Here is my code to visualize box

import open3d as o3d
import open3d
import numpy as np
import pandas as pd
import math

from scipy.spatial.transform import Rotation

def load_point_cloud(pcd_path):
    """
    Load the point cloud from a .pcd file.
    """
    pcd = o3d.io.read_point_cloud(pcd_path)
    return pcd

def parse_labels(label_path):
    """
    Parse label data from the given label file.

    Each line in the label file should have the following format:
    Class name, Track ID, Height (h), Length (l), Width (w), X, Y, Z, rotation (rot)

    Returns:
        List of dictionaries with bounding box parameters.
    """
    labels = []
    with open(label_path, 'r') as file:
        for line in file.readlines():
            print("line ", line)
            data = line.strip().split(' ')
            # print("data ", data)
            if len(data) == 9:
                label = {
                    'class_name': data[0].strip(),
                    'track_id': data[1].strip(),
                    'h': float(data[2].strip()),
                    'l': float(data[3].strip()),
                    'w': float(data[4].strip()),
                    'x': float(data[5].strip()),
                    'y': float(data[6].strip()),
                    'z': float(data[7].strip()),
                    'rot': float(data[8].strip())  # Rotation in radians
                }
                labels.append(label)
    return labels

pcd_path = "/data/Sit/Cafe_street/Cafe_street_1/velo/concat/data/100.pcd"
label_path = "/data/Sit/Cafe_street/Cafe_street_1/label_3d/100.txt"

point_data = load_point_cloud(pcd_path)
bounding_boxes = parse_labels(label_path)
print(len(bounding_boxes))
vis_elements = [point_data]  # List of all visual elements to add to Open3D visualizer

vis = open3d.visualization.Visualizer()
vis.create_window()

vis.get_render_option().point_size = 4.0
vis.get_render_option().background_color = np.ones(3) * 0.25

axis_pcd = open3d.geometry.TriangleMesh.create_coordinate_frame(
            size=1.0, origin=[0, 0, 0])
vis.add_geometry(axis_pcd)

axis_pcd = open3d.geometry.TriangleMesh.create_coordinate_frame(
size=1.0, origin=[0, 0, 0])
vis.add_geometry(axis_pcd)

pts = open3d.geometry.PointCloud()

point_data = np.asarray(point_data.points)

print(point_data.shape)

for gt in bounding_boxes:
    if gt['class_name']=="Pedestrian":
        print(gt['rot'])
        rot_mat = Rotation.from_rotvec([0, 0, gt['rot']]).as_matrix()
        bb_gt = open3d.geometry.OrientedBoundingBox([gt['x'], gt['y'], gt['z']], rot_mat, [gt['w'], gt['l'], gt['h']])
        bb_gt.color = (0.0, 1.0, 2.0)
        vis.add_geometry(bb_gt)

pts.points = open3d.utility.Vector3dVector(point_data[:, :3])

view_control = vis.get_view_control()
view_control.set_front([0, 0, -1])
view_control.set_lookat([1, 2, 3])  # Adjust the look-at position if needed
view_control.set_up([0, -1, 0])
view_control.set_zoom(0.8)

vis.add_geometry(pts)

vis.run()
nghiabka commented 3 days ago

I found a solution. We need to combine the label and trajectory information to get the final bounding box.