예제 #1
0
    def from_json(cls, data):
        points = []
        for point_obj in data[POINTS]:
            points.append(
                PointTemplate(label=point_obj[LABEL],
                              color=hex2rgb(point_obj[COLOR])))

        edges = []
        for edge_obj in data[EDGES]:
            edges.append(
                EdgeTemplate(label=edge_obj[LABEL],
                             color=hex2rgb(edge_obj[COLOR]),
                             start=edge_obj[POINTS][0],
                             end=edge_obj[POINTS][1]))

        return cls(points=points, edges=edges)
예제 #2
0
    def from_json(cls, data):
        '''
        The function from_json convert tagmeta from json format to TagMeta class object.
        :param data: input tagmeta in json format
        :return: TagMeta class object
        '''
        if isinstance(data, str):
            return cls(name=data, value_type=TagValueType.NONE)
        elif isinstance(data, dict):
            name = data[TagMetaJsonFields.NAME]
            value_type = data[TagMetaJsonFields.VALUE_TYPE]
            values = data.get(TagMetaJsonFields.VALUES)
            color = data.get(TagMetaJsonFields.COLOR)
            if color is not None:
                color = hex2rgb(color)
            sly_id = data.get(TagMetaJsonFields.ID, None)

            hotkey = data.get(TagMetaJsonFields.HOTKEY, "")
            applicable_to = data.get(TagMetaJsonFields.APPLICABLE_TYPE,
                                     TagApplicableTo.ALL)
            applicable_classes = data.get(TagMetaJsonFields.APPLICABLE_CLASSES,
                                          [])

            return cls(name=name,
                       value_type=value_type,
                       possible_values=values,
                       color=color,
                       sly_id=sly_id,
                       hotkey=hotkey,
                       applicable_to=applicable_to,
                       applicable_classes=applicable_classes)
        else:
            raise ValueError('Tags must be dict or str types.')
예제 #3
0
    def from_json(cls, data: dict) -> 'ObjClass':
        """
        Creates object from json serializable dictionary. See Supervisely Json format explanation here:
        https://docs.supervise.ly/ann_format/

        Returns:
            ObjClass
        """
        name = data[ObjClassJsonFields.NAME]
        geometry_type = JSON_SHAPE_TO_GEOMETRY_TYPE[data[ObjClassJsonFields.GEOMETRY_TYPE]]
        color = hex2rgb(data[ObjClassJsonFields.COLOR])
        return cls(name=name, geometry_type=geometry_type, color=color)
예제 #4
0
 def from_json(cls, data):
     if isinstance(data, str):
         return cls(name=data, value_type=TagValueType.NONE)
     elif isinstance(data, dict):
         name = data[TagMetaJsonFields.NAME]
         value_type = data[TagMetaJsonFields.VALUE_TYPE]
         values = data.get(TagMetaJsonFields.VALUES)
         color = data.get(TagMetaJsonFields.COLOR)
         if color is not None:
             color = hex2rgb(color)
         return cls(name=name, value_type=value_type, possible_values=values, color=color)
     else:
         raise ValueError('Tags must be dict or str types.')
예제 #5
0
    def from_json(cls, data: dict) -> 'ObjClass':
        """
        Creates object from json serializable dictionary. See Supervisely Json format explanation here:
        https://docs.supervise.ly/ann_format/

        Returns:
            ObjClass
        """
        name = data[ObjClassJsonFields.NAME]
        geometry_type = GET_GEOMETRY_FROM_STR(data[ObjClassJsonFields.GEOMETRY_TYPE])
        color = hex2rgb(data[ObjClassJsonFields.COLOR])
        geometry_config = geometry_type.config_from_json(data.get(ObjClassJsonFields.GEOMETRY_CONFIG))
        sly_id = data.get(ObjClassJsonFields.ID, None)
        hotkey = data.get(ObjClassJsonFields.HOTKEY, "")
        return cls(name=name, geometry_type=geometry_type, color=color, geometry_config=geometry_config, sly_id=sly_id,
                   hotkey=hotkey)
예제 #6
0
 def from_json(cls, data):
     '''
     The function from_json convert tagmeta from json format to TagMeta class object.
     :param data: input tagmeta in json format
     :return: TagMeta class object
     '''
     if isinstance(data, str):
         return cls(name=data, value_type=TagValueType.NONE)
     elif isinstance(data, dict):
         name = data[TagMetaJsonFields.NAME]
         value_type = data[TagMetaJsonFields.VALUE_TYPE]
         values = data.get(TagMetaJsonFields.VALUES)
         color = data.get(TagMetaJsonFields.COLOR)
         if color is not None:
             color = hex2rgb(color)
         return cls(name=name,
                    value_type=value_type,
                    possible_values=values,
                    color=color)
     else:
         raise ValueError('Tags must be dict or str types.')
예제 #7
0
    def validate_classes_colors(self, logger=None):
        # check colors uniq
        color_names = defaultdict(list)
        for obj_class in self:
            hex = rgb2hex(obj_class.color)
            color_names[hex].append(obj_class.name)

        class_colors_notify = None
        for hex_color, class_names in color_names.items():
            if len(class_names) > 1:
                warn_str = "Classes {!r} have the same RGB color = {!r}".format(
                    class_names, hex2rgb(hex_color))
                if logger is not None:
                    logger.warn(warn_str)
                if class_colors_notify is None:
                    class_colors_notify = ""
                class_colors_notify += warn_str + '\n\n'
        #if class_colors_notify != "":
        #    pass
        #    api.report.create_notification("Classes colors", class_colors_notify, sly.NotificationType.WARNING))
        return class_colors_notify
예제 #8
0
    def validate_classes_colors(self, logger=None):
        # check colors uniq
        color_names = defaultdict(list)
        for obj_class in self:
            hex = rgb2hex(obj_class.color)
            color_names[hex].append(obj_class.name)

        class_colors_notify = None
        for hex_color, class_names in color_names.items():
            if len(class_names) > 1:
                warn_str = "Classes {!r} have the same RGB color = {!r}".format(class_names, hex2rgb(hex_color))
                if logger is not None:
                    logger.warn(warn_str)
                if class_colors_notify is None:
                    class_colors_notify = ""
                class_colors_notify += warn_str + '\n\n'
        return class_colors_notify