MCPcopy Create free account
hub / github.com/EGO4D/episodic-memory / BoundingBox

Class BoundingBox

VQ3D/annotation_API/API/bounding_box.py:6–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4from typing import Any, Dict, List, Optional, Tuple
5
6class BoundingBox():
7 def __init__(self, data: Any = None, scale=1.0):
8 self.scale = scale
9 if data:
10 self.load(data)
11
12 def load(self, data: Any ) -> None:
13 if type(data) is dict:
14 position = data['position']
15 rotation = data['rotation']
16 dimension = data['dimension']
17 elif type(data) is str:
18 f = json.load(open(data, 'r'))
19
20 position = f['frames'][0]['items'][0]['position']
21 rotation = f['frames'][0]['items'][0]['rotation']
22 dimension = f['frames'][0]['items'][0]['dimension']
23 else:
24 raise NotImplementedError
25
26 self.center = np.array([position['x'],
27 position['y'],
28 position['z']]) * self.scale
29
30 self.sizes = np.array([dimension['x'],
31 dimension['y'],
32 dimension['z']]) * self.scale
33
34 self.rotation = np.array([rotation['x'],
35 rotation['y'],
36 rotation['z'],
37 ])
38
39 def volume(self) -> float:
40 return np.prod(self.sizes)
41
42 def get_transformation_matrix(self) -> np.ndarray:
43 rotation = self.rotation
44 position = self.center
45
46 Rx = np.array([[1, 0, 0, 0],
47 [0, np.cos(rotation[0]), -np.sin(rotation[0]), 0],
48 [0, np.sin(rotation[0]), np.cos(rotation[0]), 0],
49 [0, 0, 0, 1],
50 ])
51
52 Ry = np.array([[ np.cos(rotation[1]), 0, np.sin(rotation[1]), 0],
53 [0, 1, 0, 0],
54 [-np.sin(rotation[1]), 0, np.cos(rotation[1]), 0],
55 [0, 0, 0, 1],
56 ])
57
58 Rz = np.array([[np.cos(rotation[2]), -np.sin(rotation[2]), 0, 0],
59 [np.sin(rotation[2]), np.cos(rotation[2]), 0, 0],
60 [0, 0, 1, 0],
61 [0, 0, 0, 1],
62 ])
63

Callers 2

load_3d_annotationMethod · 0.90
eval.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected