Skip to content

tweaking the Semantic Segmentation#3

Open
samhumeau wants to merge 1 commit intoget_bone_positionfrom
get_instance_segmentation
Open

tweaking the Semantic Segmentation#3
samhumeau wants to merge 1 commit intoget_bone_positionfrom
get_instance_segmentation

Conversation

@samhumeau
Copy link
Copy Markdown
Owner

Dirty hack the the semantic segmentation camera.

You can use this wrapper to interpret the result:

class ColorModifierWrapper(object):
    """ We can not instanciate a Carla image from the python side, so this is
        an helper to convert what's out of the semantic segmentation now
    """

    def __init__(self, carla_image):
        self.carla_image = carla_image
        self.original_colors = [ColorModifierWrapper.clone_color(carla_image[i])
                                for i in range(len(carla_image))]
        self.color_map = {r:carla.Color(r = (r*13+16) % 256,
                                        g = (142+r*21) % 256,
                                        b = (89+r*47) % 256)
                          for r in range(256)}
        self.blank = carla.Color(r=255,b=255,g=255)
        self.black = carla.Color(r=0,b=0,g=0)

    @staticmethod
    def clone_color(color):
        return carla.Color(r=color.r, g=color.g, b=color.b, a=color.a)

    def view_as_semantic_seg(self):
        for i, color in enumerate(self.original_colors):
            new_color = ColorModifierWrapper.clone_color(color)
            if color.r >=16 and color.r < 128:
                new_color.r = 4 # pedestrian
            if color.r >=128 and color.r < 240:
                new_color.r = 10 # vehicle
            self.carla_image[long(i)] = new_color
        self.carla_image.convert(carla.ColorConverter.CityScapesPalette)
        return self.carla_image


    def view_as_instance_seg(self):
        for i, color in enumerate(self.original_colors):
            if color.r < 16 and color.r != 4:
                self.carla_image[long(i)] = self.blank # Not a pedestrian nor a car
            elif color.r == 4:
                self.carla_image[long(i)] = self.black # rider
            else:
                self.carla_image[long(i)] = self.color_map[color.r]
        return self.carla_image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant