Beispiel #1
0
 def set_image(self, image_msg, image_topic, image_stamp):
     self._image_msg = image_msg
     if image_msg:
         self._image = image_helper.imgmsg_to_pil(image_msg)
     else:
         self._image = None
     self._image_topic = image_topic
     self._image_stamp = image_stamp
     self.put_image_into_scene()
 def set_image(self, image_msg, image_topic, image_stamp):
     self._image_msg = image_msg
     if image_msg:
         self._image = image_helper.imgmsg_to_pil(image_msg)
     else:
         self._image = None
     self._image_topic = image_topic
     self._image_stamp = image_stamp
     self.put_image_into_scene()
    def _load_thumbnail(self, topic, stamp, thumbnail_details):
        """
        Loads the thumbnail from the bag
        """
        (thumbnail_height, ) = thumbnail_details

        # Find position of stamp using index
        t = rospy.Time.from_sec(stamp)
        bag, entry = self.timeline.scene().get_entry(t, topic)
        if not entry:
            return None, None
        pos = entry.position

        # Not in the cache; load from the bag file

        with self.timeline.scene()._bag_lock:
            msg_topic, msg, msg_stamp = bag._read_message(pos)

        # Convert from ROS image to PIL image
        try:
            pil_image = image_helper.imgmsg_to_pil(msg)
        except Exception as ex:
            print('Error loading image on topic %s: %s' % (topic, str(ex)),
                  file=sys.stderr)
            pil_image = None

        if not pil_image:
            print('Disabling renderer on %s' % topic, file=sys.stderr)
            self.timeline.set_renderer_active(topic, False)
            return None, None

        # Calculate width to maintain aspect ratio
        try:
            pil_image_size = pil_image.size
            thumbnail_width = int(
                round(thumbnail_height *
                      (float(pil_image_size[0]) / pil_image_size[1])))
            # Scale to thumbnail size
            thumbnail = pil_image.resize((thumbnail_width, thumbnail_height),
                                         self.quality)

            return msg_stamp, thumbnail

        except Exception as ex:
            print('Error loading image on topic %s: %s' % (topic, str(ex)),
                  file=sys.stderr)
            raise
            return None, None
    def _load_thumbnail(self, topic, stamp, thumbnail_details):
        """
        Loads the thumbnail from the bag
        """
        (thumbnail_height,) = thumbnail_details

        # Find position of stamp using index
        t = rospy.Time.from_sec(stamp)
        bag, entry = self.timeline.scene().get_entry(t, topic)
        if not entry:
            return None, None
        pos = entry.position

        # Not in the cache; load from the bag file

        with self.timeline.scene()._bag_lock:
            msg_topic, msg, msg_stamp = bag._read_message(pos)

        # Convert from ROS image to PIL image
        try:
            pil_image = image_helper.imgmsg_to_pil(msg)
        except Exception as ex:
            print('Error loading image on topic %s: %s' % (topic, str(ex)), file=sys.stderr)
            pil_image = None

        if not pil_image:
            print('Disabling renderer on %s' % topic, file=sys.stderr)
            self.timeline.set_renderer_active(topic, False)
            return None, None

        # Calculate width to maintain aspect ratio
        try:
            pil_image_size = pil_image.size
            thumbnail_width = int(round(thumbnail_height * (float(pil_image_size[0]) / pil_image_size[1])))
            # Scale to thumbnail size
            thumbnail = pil_image.resize((thumbnail_width, thumbnail_height), self.quality)

            return msg_stamp, thumbnail

        except Exception as ex:
            print('Error loading image on topic %s: %s' % (topic, str(ex)), file=sys.stderr)
            raise
            return None, None