forked from chaomath/open3d-kitti-visualization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_info.py
116 lines (108 loc) · 3.78 KB
/
object_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import numpy as np
class ObjectInfo:
@classmethod
def get_csv_header(cls) -> str:
return (
"type,frame,distance_m,"
"min_azimuth_deg,max_azimuth_deg,"
"min_altitude_deg,max_altitude_deg,"
"min_distance_m,max_distance_m,"
"height,width,length,"
"center_x,center_y,center_z,"
"yaw_rad,points_count"
)
@classmethod
def create(cls, box: list, pcd, obj_type: str, frame: int) -> "ObjectInfo":
L = box[2]
W = box[1]
H = box[0]
X = box[3]
Y = box[4]
Z = box[5]
Theta = box[6]
points_numpy = np.asarray(pcd.points) # (n, 3)
if points_numpy.shape[0] > 0:
# xyz to spherical coordinates
r = np.linalg.norm(points_numpy, axis=1)
theta = np.arctan2(points_numpy[:, 1], points_numpy[:, 0])
phi = np.arccos(points_numpy[:, 2] / r)
min_azimuth_deg = np.rad2deg(np.min(theta))
max_azimuth_deg = np.rad2deg(np.max(theta))
min_altitude_deg = np.rad2deg(np.min(phi))
max_altitude_deg = np.rad2deg(np.max(phi))
min_distance_m = np.min(r)
max_distance_m = np.max(r)
point_num = points_numpy.shape[0]
else:
min_azimuth_deg = 0
max_azimuth_deg = 0
min_altitude_deg = 0
max_altitude_deg = 0
min_distance_m = 0
max_distance_m = 0
point_num = 0
return cls(
type=obj_type,
frame=frame,
distance_m=float(np.linalg.norm([X, Y, Z])),
min_azimuth_deg=min_azimuth_deg,
max_azimuth_deg=max_azimuth_deg,
min_altitude_deg=min_altitude_deg,
max_altitude_deg=max_altitude_deg,
min_distance_m=min_distance_m,
max_distance_m=max_distance_m,
height=H,
width=W,
length=L,
center_x=X,
center_y=Y,
center_z=Z,
yaw_rad=Theta,
points_count=point_num,
)
def __init__(
self,
type: str,
frame: int,
distance_m: float,
min_azimuth_deg: float,
max_azimuth_deg: float,
min_altitude_deg: float,
max_altitude_deg: float,
min_distance_m: float,
max_distance_m: float,
height: float,
width: float,
length: float,
center_x: float,
center_y: float,
center_z: float,
yaw_rad: float,
points_count: int,):
self.type = type
self.frame = frame
self.distance_m = distance_m
self.min_azimuth_deg = min_azimuth_deg
self.max_azimuth_deg = max_azimuth_deg
self.min_altitude_deg = min_altitude_deg
self.max_altitude_deg = max_altitude_deg
self.min_distance_m = min_distance_m
self.max_distance_m = max_distance_m
self.height = height
self.width = width
self.length = length
self.center_x = center_x
self.center_y = center_y
self.center_z = center_z
self.yaw_rad = yaw_rad
self.points_count = points_count
def to_csv_line(self) -> str:
return (
f"{self.type},{self.frame},{self.distance_m:.3f},"
f"{self.min_azimuth_deg:.3f},{self.max_azimuth_deg:.3f},"
f"{self.min_altitude_deg:.3f},{self.max_altitude_deg:.3f},"
f"{self.min_distance_m:.3f},{self.max_distance_m:.3f},"
f"{self.height:.3f},{self.width:.3f},{self.length:.3f},"
f"{self.center_x:.3f},{self.center_y:.3f},{self.center_z:.3f},"
f"{self.yaw_rad:.3f},{self.points_count}"
)