tum-traffic-dataset / tum-traffic-dataset-dev-kit

TUM Traffic Dataset Development Kit
https://innovation-mobility.com/tumtraf-dataset
MIT License
43 stars 7 forks source link

visualization in R0 #5

Open Sondosmohamed1 opened 10 months ago

Sondosmohamed1 commented 10 months ago

Thank you very much for the great work. I wonder if there is source code that represents the visualization in S0 and S1 for the R0. I was trying to visualize the projected key point, but I got the wrong projection. I have attached my code.

import cv2 import json import numpy as np open("/home/sun/Downloads/a9_dataset_r00_s02/_labels/1616762521_089000000_s40_camera_basler_south_50mm.json", "r") as file: data = json.load(file)

image=cv2.imread("/home/sun/Downloads/a9_dataset_r00_s02/_images/1616762521_089000000_s40_camera_basler_north_50mm.jpg")

for label in data["labels"]:

box3d_projected = label["box3d_projected"]
print("this is projected boxes ", box3d_projected)

points_order = [
    "bottom_left_front", "bottom_right_front", "top_right_front", "top_left_front",
    "bottom_left_back", "bottom_right_back", "top_right_back", "top_left_back"
]

corners_3d_img = np.array([box3d_projected[point] for point in points_order], dtype=np.float32)

corners_3d_img = corners_3d_img.reshape((-1, 1, 2))

scale_factor = 1000
corners_3d_img = (corners_3d_img * scale_factor).astype(np.int32)

color = (0, 255, 0) 
thickness = 2
cv2.line(image, tuple(corners_3d_img[0, 0]), tuple(corners_3d_img[1, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[1, 0]), tuple(corners_3d_img[2, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[2, 0]), tuple(corners_3d_img[3, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[3, 0]), tuple(corners_3d_img[0, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[4, 0]), tuple(corners_3d_img[5, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[5, 0]), tuple(corners_3d_img[6, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[6, 0]), tuple(corners_3d_img[7, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[7, 0]), tuple(corners_3d_img[4, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[0, 0]), tuple(corners_3d_img[4, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[1, 0]), tuple(corners_3d_img[5, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[2, 0]), tuple(corners_3d_img[6, 0]), color=color, thickness=thickness)
cv2.line(image, tuple(corners_3d_img[3, 0]), tuple(corners_3d_img[7, 0]), color=color, thickness=thickness)

cv2.imshow("Image with 3D lines", image) cv2.waitKey(0) cv2.destroyAllWindows()