parameters: (self, scene_token: str, freq: float = 10, imsize: Tuple[float, float] = (640, 360),
                       out_path: str = None)
docstring: Renders a full scene with all camera channels.
          :param scene_token: Unique identifier of scene to render.
          :param freq: Display frequency (Hz).
          :param imsize: Size of image to render. The larger the slower this will run.
          :param out_path: Optional path to write a video file of the rendered frames.
docstring_summary: Renders a full scene with all camera channels.
          :param scene_token: Unique identifier of scene to render.
          :param freq: Display frequency (Hz).
          :param imsize: Size of image to render. The larger the slower this will run.
          :param out_path: Optional path to write a video file of the rendered frames.
docstring_tokens: Renders a full scene with all camera channels . : param scene_token : Unique identifier of scene to render . : param freq : Display frequency ( Hz ) . : param imsize : Size of image to render . The larger the slower this will run . : param out_path : Optional path to write a video file of the rendered frames .
function: def render_scene(self, scene_token: str, freq: float = 10, imsize: Tuple[float, float] = (640, 360),
                       out_path: str = None) -> None:
          """
          Renders a full scene with all camera channels.
          :param scene_token: Unique identifier of scene to render.
          :param freq: Display frequency (Hz).
          :param imsize: Size of image to render. The larger the slower this will run.
          :param out_path: Optional path to write a video file of the rendered frames.
          """
  
          assert imsize[0] / imsize[1] == 16 / 9, "Aspect ratio should be 16/9."
  
          # Get records from DB.
          scene_rec = self.nusc.get('scene', scene_token)
          first_sample_rec = self.nusc.get('sample', scene_rec['first_sample_token'])
          last_sample_rec = self.nusc.get('sample', scene_rec['last_sample_token'])
  
          # Set some display parameters
          layout = {
              'CAM_FRONT_LEFT': (0, 0),
              'CAM_FRONT': (imsize[0], 0),
              'CAM_FRONT_RIGHT': (2 * imsize[0], 0),
              'CAM_BACK_LEFT': (0, imsize[1]),
              'CAM_BACK': (imsize[0], imsize[1]),
              'CAM_BACK_RIGHT': (2 * imsize[0], imsize[1]),
          }
  
          horizontal_flip = ['CAM_BACK_LEFT', 'CAM_BACK', 'CAM_BACK_RIGHT']  # Flip these for aesthetic reasons.
  
          time_step = 1 / freq * 1e6  # Time-stamps are measured in micro-seconds.
  
          window_name = '{}'.format(scene_rec['name'])
          cv2.namedWindow(window_name)
          cv2.moveWindow(window_name, 0, 0)
  
          canvas = np.ones((2 * imsize[1], 3 * imsize[0], 3), np.uint8)
          if out_path is not None:
              fourcc = cv2.VideoWriter_fourcc(*'MJPG')
              out = cv2.VideoWriter(out_path, fourcc, freq, canvas.shape[1::-1])
  
          # Load first sample_data record for each channel
          current_recs = {}  # Holds the current record to be displayed by channel.
          prev_recs = {}  # Hold the previous displayed record by channel.
          for channel in layout:
              current_recs[channel] = self.nusc.get('sample_data', first_sample_rec['data'][channel])
              prev_recs[channel] = None
  
          current_time = first_sample_rec['timestamp']
  
          while current_time < last_sample_rec['timestamp']:
  
              current_time += time_step
  
              # For each channel, find first sample that has time > current_time.
              for channel, sd_rec in current_recs.items():
                  while sd_rec['timestamp'] < current_time and sd_rec['next'] != '':
                      sd_rec = self.nusc.get('sample_data', sd_rec['next'])
                      current_recs[channel] = sd_rec
  
              # Now add to canvas
              for channel, sd_rec in current_recs.items():
  
                  # Only update canvas if we have not already rendered this one.
                  if not sd_rec == prev_recs[channel]:
  
                      # Get annotations and params from DB.
                      impath, boxes, camera_intrinsic = self.nusc.get_sample_data(sd_rec['token'],
                                                                                  box_vis_level=BoxVisibility.IN_FRONT)
  
                      # Load and render
                      if not osp.exists(impath):
                          raise Exception('Error: Missing image %s' % impath)
                      im = cv2.imread(impath)
                      for box in boxes:
                          c = self.get_color(box.name)
                          box.render_cv2(im, view=camera_intrinsic, normalize=True, colors=[c, c, c])
  
                      im = cv2.resize(im, imsize)
                      if channel in horizontal_flip:
                          im = im[:, ::-1, :]
  
                      canvas[layout[channel][1]: layout[channel][1] + imsize[1],
                      layout[channel][0]:layout[channel][0] + imsize[0], :] = im
  
                      prev_recs[channel] = sd_rec  # Store here so we don't render the same image twice.
  
              # Show updated canvas.
              cv2.imshow(window_name, canvas)
              if out_path is not None:
                  out.write(canvas)
  
              key = cv2.waitKey(1)  # Wait a very short time (1 ms).
  
              if key == 32:  # if space is pressed, pause.
                  key = cv2.waitKey()
  
              if key == 27:  # if ESC is pressed, exit.
                  cv2.destroyAllWindows()
                  break
  
          cv2.destroyAllWindows()
          if out_path is not None:
              out.release()
function_tokens: def render_scene ( self , scene_token : str , freq : float = 10 , imsize : Tuple [ float , float ] = ( 640 , 360 ) , out_path : str = None ) -> None : assert imsize [ 0 ] / imsize [ 1 ] == 16 / 9 , "Aspect ratio should be 16/9." # Get records from DB. scene_rec = self . nusc . get ( 'scene' , scene_token ) first_sample_rec = self . nusc . get ( 'sample' , scene_rec [ 'first_sample_token' ] ) last_sample_rec = self . nusc . get ( 'sample' , scene_rec [ 'last_sample_token' ] ) # Set some display parameters layout = { 'CAM_FRONT_LEFT' : ( 0 , 0 ) , 'CAM_FRONT' : ( imsize [ 0 ] , 0 ) , 'CAM_FRONT_RIGHT' : ( 2 * imsize [ 0 ] , 0 ) , 'CAM_BACK_LEFT' : ( 0 , imsize [ 1 ] ) , 'CAM_BACK' : ( imsize [ 0 ] , imsize [ 1 ] ) , 'CAM_BACK_RIGHT' : ( 2 * imsize [ 0 ] , imsize [ 1 ] ) , } horizontal_flip = [ 'CAM_BACK_LEFT' , 'CAM_BACK' , 'CAM_BACK_RIGHT' ] # Flip these for aesthetic reasons. time_step = 1 / freq * 1e6 # Time-stamps are measured in micro-seconds. window_name = '{}' . format ( scene_rec [ 'name' ] ) cv2 . namedWindow ( window_name ) cv2 . moveWindow ( window_name , 0 , 0 ) canvas = np . ones ( ( 2 * imsize [ 1 ] , 3 * imsize [ 0 ] , 3 ) , np . uint8 ) if out_path is not None : fourcc = cv2 . VideoWriter_fourcc ( * 'MJPG' ) out = cv2 . VideoWriter ( out_path , fourcc , freq , canvas . shape [ 1 : : - 1 ] ) # Load first sample_data record for each channel current_recs = { } # Holds the current record to be displayed by channel. prev_recs = { } # Hold the previous displayed record by channel. for channel in layout : current_recs [ channel ] = self . nusc . get ( 'sample_data' , first_sample_rec [ 'data' ] [ channel ] ) prev_recs [ channel ] = None current_time = first_sample_rec [ 'timestamp' ] while current_time < last_sample_rec [ 'timestamp' ] : current_time += time_step # For each channel, find first sample that has time > current_time. for channel , sd_rec in current_recs . items ( ) : while sd_rec [ 'timestamp' ] < current_time and sd_rec [ 'next' ] != '' : sd_rec = self . nusc . get ( 'sample_data' , sd_rec [ 'next' ] ) current_recs [ channel ] = sd_rec # Now add to canvas for channel , sd_rec in current_recs . items ( ) : # Only update canvas if we have not already rendered this one. if not sd_rec == prev_recs [ channel ] : # Get annotations and params from DB. impath , boxes , camera_intrinsic = self . nusc . get_sample_data ( sd_rec [ 'token' ] , box_vis_level = BoxVisibility . IN_FRONT ) # Load and render if not osp . exists ( impath ) : raise Exception ( 'Error: Missing image %s' % impath ) im = cv2 . imread ( impath ) for box in boxes : c = self . get_color ( box . name ) box . render_cv2 ( im , view = camera_intrinsic , normalize = True , colors = [ c , c , c ] ) im = cv2 . resize ( im , imsize ) if channel in horizontal_flip : im = im [ : , : : - 1 , : ] canvas [ layout [ channel ] [ 1 ] : layout [ channel ] [ 1 ] + imsize [ 1 ] , layout [ channel ] [ 0 ] : layout [ channel ] [ 0 ] + imsize [ 0 ] , : ] = im prev_recs [ channel ] = sd_rec # Store here so we don't render the same image twice. # Show updated canvas. cv2 . imshow ( window_name , canvas ) if out_path is not None : out . write ( canvas ) key = cv2 . waitKey ( 1 ) # Wait a very short time (1 ms). if key == 32 : # if space is pressed, pause. key = cv2 . waitKey ( ) if key == 27 : # if ESC is pressed, exit. cv2 . destroyAllWindows ( ) break cv2 . destroyAllWindows ( ) if out_path is not None : out . release ( )