def process_images(self, simulator_image): """ Invoked when an image is received from the simulator. Args: simulator_image: a carla.Image. """ game_time = int(simulator_image.timestamp * 1000) timestamp = erdos.Timestamp(coordinates=[game_time]) watermark_msg = erdos.WatermarkMessage(timestamp) with erdos.profile(self.config.name + '.process_images', self, event_data={'timestamp': str(timestamp)}): # Ensure that the code executes serially with self._lock: msg = None if self._camera_setup.camera_type == 'sensor.camera.rgb': msg = FrameMessage( timestamp, CameraFrame.from_simulator_frame( simulator_image, self._camera_setup)) elif self._camera_setup.camera_type == 'sensor.camera.depth': # Include the transform relative to the vehicle. # simulator_image.transform returns the world transform, # but we do not use it directly. msg = DepthFrameMessage( timestamp, DepthFrame.from_simulator_frame( simulator_image, self._camera_setup, save_original_frame=self._flags. visualize_depth_camera)) elif (self._camera_setup.camera_type == 'sensor.camera.semantic_segmentation'): msg = SegmentedFrameMessage( timestamp, SegmentedFrame.from_simulator_image( simulator_image, self._camera_setup)) if self._release_data: self._camera_stream.send(msg) self._camera_stream.send(watermark_msg) else: # Pickle the data, and release it upon release msg receipt. pickled_msg = pickle.dumps( msg, protocol=pickle.HIGHEST_PROTOCOL) with self._pickle_lock: self._pickled_messages[msg.timestamp] = pickled_msg self._notify_reading_stream.send(watermark_msg)
def on_camera_frame(self, data): self._counter += 1 if self._counter % self._modulo_to_send != 0: return cv2_image = self._bridge.imgmsg_to_cv2(data, "bgr8") resized_image = cv2.resize( cv2.flip(cv2_image, -1), (self._flags.camera_image_width, self._flags.camera_image_height)) numpy_array = np.asarray(resized_image) timestamp = erdos.Timestamp(coordinates=[self._msg_cnt]) camera_frame = CameraFrame(numpy_array, 'BGR', self._camera_setup) self._camera_stream.send(FrameMessage(timestamp, camera_frame)) watermark_msg = erdos.WatermarkMessage(timestamp) self._camera_stream.send(watermark_msg) self._logger.debug('@{}: sent message'.format(timestamp)) self._msg_cnt += 1
def process_images(self, carla_image): """ Invoked when an image is received from the simulator. Args: carla_image: a carla.Image. """ # Ensure that the code executes serially with self._lock: game_time = int(carla_image.timestamp * 1000) timestamp = erdos.Timestamp(coordinates=[game_time]) watermark_msg = erdos.WatermarkMessage(timestamp) msg = None if self._camera_setup.camera_type == 'sensor.camera.rgb': msg = FrameMessage( timestamp, CameraFrame.from_carla_frame(carla_image, self._camera_setup)) elif self._camera_setup.camera_type == 'sensor.camera.depth': # Include the transform relative to the vehicle. # Carla carla_image.transform returns the world transform, but # we do not use it directly. msg = DepthFrameMessage( timestamp, DepthFrame.from_carla_frame(carla_image, self._camera_setup)) elif self._camera_setup.camera_type == \ 'sensor.camera.semantic_segmentation': msg = SegmentedFrameMessage( timestamp, SegmentedFrame.from_carla_image(carla_image, self._camera_setup)) # Send the message containing the frame. self._camera_stream.send(msg) # Note: The operator is set not to automatically propagate # watermark messages received on input streams. Thus, we can # issue watermarks only after the Carla callback is invoked. self._camera_stream.send(watermark_msg)
def on_camera_msg(carla_image): game_time = int(carla_image.timestamp * 1000) print("Received camera msg {}".format(game_time)) global last_frame last_frame = FrameMessage(carla_image, game_time, encoding='carla')