An interactive renderer for camera visualization.
| 4 | |
| 5 | |
| 6 | class VedoRenderer(object): |
| 7 | """An interactive renderer for camera visualization.""" |
| 8 | def __init__(self, scale=0.03): |
| 9 | """Visualize cameras in an interactive scene supported by vedo. |
| 10 | |
| 11 | Args: |
| 12 | scale (float, optional): |
| 13 | Scale factor. Defaults to 0.03. |
| 14 | """ |
| 15 | self.scale = scale |
| 16 | self.axis_list = self.__init_axis() |
| 17 | self.camera_list = [] |
| 18 | self.frames_dir_path = '' |
| 19 | self.y_reverse = False |
| 20 | |
| 21 | def __init_axis(self, axis_len=80): |
| 22 | """Prepare arrows for axis. |
| 23 | |
| 24 | Args: |
| 25 | axis_len (int, optional): |
| 26 | Length of each axis. |
| 27 | Defaults to 80. |
| 28 | |
| 29 | Returns: |
| 30 | List[Arrows]: |
| 31 | A list of three arrows. |
| 32 | """ |
| 33 | arrow_end_np = np.eye(3) * axis_len * self.scale |
| 34 | colors = ['r', 'g', 'b'] # r-x, g-y, b-z |
| 35 | ret_list = [] |
| 36 | for axis_index in range(3): |
| 37 | ret_list.append( |
| 38 | vedo.Arrows([[0, 0, 0]], |
| 39 | [arrow_end_np[axis_index]]).c(colors[axis_index])) |
| 40 | return ret_list |
| 41 | |
| 42 | def set_y_reverse(self): |
| 43 | """Set y reverse before add_camera if it is needed. |
| 44 | |
| 45 | Vedo defines y+ as up direction. When visualizing kinect cameras, y- is |
| 46 | up, call set_y_reverse in this situation to make text in correct |
| 47 | direction. |
| 48 | """ |
| 49 | self.y_reverse = True |
| 50 | self.y_reverse_rotation = \ |
| 51 | scipy_Rotation.from_euler('z', 180, degrees=True) |
| 52 | |
| 53 | def add_camera(self, camera_parameter, arrow_len=30): |
| 54 | """Add an camera to the scene. |
| 55 | |
| 56 | Args: |
| 57 | camera_parameter (CameraParameter): |
| 58 | An instance of class CameraParameter which stores |
| 59 | rotation, translation and name of a camera. |
| 60 | arrow_len (int, optional): |
| 61 | Length of the arrow. Defaults to 30. |
| 62 | |
| 63 | Returns: |
no outgoing calls
no test coverage detected