Skip to content

Get instance segmentation#2

Open
samhumeau wants to merge 3 commits intomasterfrom
get_instance_segmentation
Open

Get instance segmentation#2
samhumeau wants to merge 3 commits intomasterfrom
get_instance_segmentation

Conversation

@samhumeau
Copy link
Owner

Wrap the result in this

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

@cmaibom
Copy link

cmaibom commented Jan 30, 2020

Hello @samhumeau

Thanks for sharing your code.
I have a question. In which file do I have to add the above class ColorModifierWrapper?

I would be very grateful for an answer.

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.

2 participants