Ejemplo n.º 1
0
def process_image(data):
    image = process_compressed_image(data,
                                     sensor_stats={
                                         'height': 256,
                                         'width': 256,
                                         'depth': 3
                                     })
    output_images = [PILImage.fromarray((image * 255).astype(np.uint8))]

    o_t = TF.to_tensor(image) * 2 - 1
    o_t = o_t.unsqueeze_(0)
    task = 'segment_semantic'
    pred = visualpriors.feature_readout(o_t, task, device='cpu')
    labels = semantic_masks(pred)

    output_images.append(PILImage.fromarray(labels))

    widths, heights = zip(*(i.size for i in output_images))

    total_width = sum(widths)
    max_height = max(heights)
    new_im = PILImage.new('RGB', (total_width, max_height))

    x_offset = 0
    for im in output_images:
        new_im.paste(im, (x_offset, 0))
        x_offset += im.size[0]
    cv2.imshow('image', np.asarray(new_im))
    cv2.waitKey(1)
 def _process_compressed_image(self, msg: CompressedImage,
                               args: tuple) -> None:
     sensor_topic, sensor_stats = args
     image = process_compressed_image(msg, sensor_stats)
     image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
     if sum(image.shape) < 3000:
         image = cv2.resize(image, (600, 400), interpolation=cv2.INTER_AREA)
     self._draw(image)
Ejemplo n.º 3
0
 def _process_observation(self):
     if self._view_msg is None:
         return None
     msg = copy.deepcopy(self._view_msg)
     self._view_msg = None
     image = process_image(msg,
                           self._observation_sensor_stats) if isinstance(
                               msg, Image) else process_compressed_image(
                                   msg, self._observation_sensor_stats)
     return cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
 def _process_mask(self):
     if self._mask_msg is None:
         return None
     msg = copy.deepcopy(self._mask_msg)
     self._mask_msg = None
     image = process_image(msg, self._mask_sensor_stats) if isinstance(
         msg, Image) else process_compressed_image(msg,
                                                   self._mask_sensor_stats)
     image -= image.min()
     image /= image.max()
     image *= 255
     return cv2.applyColorMap(image.astype(np.uint8),
                              cv2.COLORMAP_AUTUMN) / 255.