Coco utilities¶
Evaluation functions for FlatBug datasets.
- flat_bug.coco_utils.annotations_2_contours(annotations: Dict[str, dict]) Dict[str, List[array]] ¶
Converts COCO annotations to contours.
- Parameters:
annotations (Dict[str, dict]) – COCO annotations.
- Returns:
Contours.
- Return type:
out (Dict[str, List[np.array]])
- flat_bug.coco_utils.annotations_to_numpy(annotations: List[Dict[str, int | List[int]]]) Tuple[ndarray, ndarray] ¶
Converts COCO annotations to NumPy arrays.
- Parameters:
annotations (List[Dict[str, Union[int, List[int]]]]) – COCO annotations.
- Returns:
Bounding boxes and contours.
- Return type:
out (Tuple[np.ndarray, np.ndarray])
- flat_bug.coco_utils.contour_area(c: ndarray) ndarray ¶
Calculates the area of a contour.
- Parameters:
c (np.ndarray) – Contour of shape (n, 2).
- Returns:
Scalar area of the contour of shape (1,).
- Return type:
out (np.array[np.int32])
- flat_bug.coco_utils.contour_bbox(c: ndarray) ndarray ¶
Calculates the bounding box of a contour.
- Parameters:
c (np.ndarray) – Contour.
- Returns:
Bounding box.
- Return type:
oyut (np.ndarray)
- flat_bug.coco_utils.fb_to_coco(d: Dict, coco: Dict) Dict ¶
Converts a FlatBug dataset to a COCO dataset.
- Parameters:
d (dict) – FlatBug dataset.
coco (dict) – An instantiated COCO dataset or an empty dictionary.
- Returns:
COCO dataset.
- Return type:
out (dict)
- flat_bug.coco_utils.filter_coco(coco: dict, confidence: float | None = None, area: int | None = None, verbose: bool = False) dict ¶
Filters COCO annotations by confidence.
- Parameters:
coco (dict) – COCO dataset.
confidence (Optional[float], optional) – Confidence threshold. Defaults to None; no threshold.
area (Optional[int], optional) – Area threshold. Defaults to None; no threshold.
verbose (bool, optional) – Verbose mode. Defaults to False.
- Returns:
Filtered COCO dataset.
- Return type:
out (dict)
- flat_bug.coco_utils.format_contour(c: List) ndarray ¶
Formats a contour to the OpenCV format.
- Parameters:
c (list) – Contour.
- Returns:
Formatted contour.
- Return type:
out (np.ndarray)
- flat_bug.coco_utils.split_annotations(coco: dict, strip_directories: bool = True) Dict[str, dict] ¶
Splits COCO annotations by image ID.
- Parameters:
coco (dict) – COCO dataset.
strip_directories (bool, optional) – Flag to indicate whether only the basename of the images should be included in the result. Defaults to True.
- Returns:
Dict of COCO datasets, split by image ID and keyed by image name.
- Return type:
out (Dict[str, dict])