def color_list(self, color: List[GL_Color]): if type(color) is list: check_list_length(color, correct_length=len(self)) check_type_from_list(color, valid_type_list=[GL_Color]) for point, val in zip(self, color): point.color = val elif type(color) is GL_Color: for point in self: point.color = color else: raise Exception
def get_instance_segmentation(self, img: np.ndarray, target_bgr: List[int] = None, interval: int = 1, exclude_invalid_polygons: bool = True): target_bgr = target_bgr if target_bgr is not None else self.get_color_from_id( ) check_list_length(target_bgr, correct_length=3) lower_bgr = [ val - interval if val - interval >= 0 else 0 for val in target_bgr ] upper_bgr = [ val + interval if val + interval <= 255 else 255 for val in target_bgr ] color_mask = cv2.inRange(src=img, lowerb=tuple(lower_bgr), upperb=tuple(upper_bgr)) color_contours, _ = cv2.findContours(color_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) seg = Segmentation.from_contour( contour_list=color_contours, exclude_invalid_polygons=exclude_invalid_polygons) return seg
def from_tuple(self, vals: Tuple[int]) -> GL_Color: check_list_length(vals, correct_length=3) r, b, g = vals return GL_Color(r=r, b=b, g=g)
def from_dict(cls, collection_dict: dict, check_paths: bool = True) -> DatasetConfigCollection: check_required_keys(collection_dict, required_keys=[ 'collection_dir', 'dataset_names', 'dataset_specific' ]) collection_dir = collection_dict['collection_dir'] check_type(collection_dir, valid_type_list=[str]) dataset_names = collection_dict['dataset_names'] check_type(dataset_names, valid_type_list=[list]) check_type_from_list(dataset_names, valid_type_list=[str]) dataset_specific = collection_dict['dataset_specific'] check_type(dataset_specific, valid_type_list=[dict]) collection_tag = None if 'tag' not in collection_dict else collection_dict[ 'tag'] check_type(collection_tag, valid_type_list=[type(None), str]) check_required_keys( dataset_specific, required_keys=['img_dir', 'ann_path', 'ann_format']) img_dir = dataset_specific['img_dir'] check_type(img_dir, valid_type_list=[str, list]) if type(img_dir) is list: check_type_from_list(img_dir, valid_type_list=[str]) check_list_length(img_dir, correct_length=len(dataset_names)) ann_path = dataset_specific['ann_path'] check_type(ann_path, valid_type_list=[str, list]) if type(ann_path) is list: check_type_from_list(ann_path, valid_type_list=[str]) check_list_length(ann_path, correct_length=len(dataset_names)) ann_format = dataset_specific['ann_format'] check_type(ann_format, valid_type_list=[str, list]) if type(ann_format) is list: check_type_from_list(ann_format, valid_type_list=[str]) check_list_length(ann_format, correct_length=len(dataset_names)) dataset_tag = None if 'tag' not in dataset_specific else dataset_specific[ 'tag'] check_type(dataset_tag, valid_type_list=[type(None), str, list]) if type(dataset_tag) is list: check_type_from_list(dataset_tag, valid_type_list=[type(None), str]) check_list_length(dataset_tag, correct_length=len(dataset_names)) dataset_config_list = [] for i in range(len(dataset_names)): if type(img_dir) is str: img_dir0 = img_dir elif type(img_dir) is list: if i >= len(img_dir): raise IndexError img_dir0 = img_dir[i] else: raise Exception if type(ann_path) is str: ann_path0 = ann_path elif type(ann_path) is list: if i >= len(ann_path): raise IndexError ann_path0 = ann_path[i] else: raise Exception if type(ann_format) is str: ann_format0 = ann_format elif type(ann_format) is list: if i >= len(ann_format): raise IndexError ann_format0 = ann_format[i] else: raise Exception if type(dataset_tag) is str or dataset_tag is None: dataset_tag0 = dataset_tag elif type(dataset_tag) is list: if i >= len(dataset_tag): raise IndexError dataset_tag0 = dataset_tag[i] else: raise Exception img_dir1 = rel_to_abs_path( f'{collection_dir}/{dataset_names[i]}/{img_dir0}') ann_path1 = rel_to_abs_path( f'{collection_dir}/{dataset_names[i]}/{ann_path0}') if check_paths: check_dir_exists(img_dir1) check_file_exists(ann_path1) config = DatasetConfig(img_dir=img_dir1, ann_path=ann_path1, ann_format=ann_format0, tag=dataset_tag0) dataset_config_list.append(config) return DatasetConfigCollection(dataset_config_list=dataset_config_list, tag=collection_tag)
def from_list(self, coords: list) -> Point3D: check_list_length(coords, correct_length=3) return Point3D(x=coords[0], y=coords[1], z=coords[2])
def from_list(self, coords: list) -> Point2D: check_list_length(coords, correct_length=2) return Point2D(x=coords[0], y=coords[1])
def __init__(self, point_list: List[Point3D]): check_list_length(point_list, correct_length=8) check_type_from_list(point_list, valid_type_list=[Point3D]) super().__init__(point_list=point_list)
def from_list(self, coords: List[float]) -> Quaternion: check_list_length(coords, correct_length=4) return Quaternion(x=coords[0], y=coords[1], z=coords[2], w=coords[3])