cpauger.generate_coco_ann

Functions

get_params(func, kwargs)

generate_random_bbox(→ List[int])

Create a list of random bbox coordinates in coco format.

generate_random_segmentation(→ List[float])

Generate a random segmentation mask made of polygon points

create_coco_annotation(→ Dict)

Create annotation for object. Represents the annotation field of coco annotation

generate_coco_annotation_file(→ None)

Generate and export random coco annotation file

save_random_imgs(→ None)

_summary_

save_random_img_wrapper(→ None)

Wrapper around save_random_imgs

generate_random_images(→ List[str])

Generates random images

generate_random_images_and_annotation(→ Tuple[List, str])

Generates random images and annotations in coco format

Module Contents

cpauger.generate_coco_ann.get_params(func, kwargs)[source]
cpauger.generate_coco_ann.generate_random_bbox(image_width: int, image_height: int, anthor=5) List[int][source]

Create a list of random bbox coordinates in coco format.

Parameters:
  • image_width (int) – Width of image

  • image_height (int) – Height of image

Returns:

List of bbox coordinates in coco format.

Return type:

List[int]

cpauger.generate_coco_ann.generate_random_segmentation(bbox) List[float][source]

Generate a random segmentation mask made of polygon points

Parameters:

bbox (List) – Bounding box of object in coco format

Returns:

Polygon coordinates representing segmentation mask

Return type:

List[float]

cpauger.generate_coco_ann.create_coco_annotation(image_id: int, category_id: int, bbox: List[int], segmentation: List[float], ann_id: int) Dict[source]

Create annotation for object. Represents the annotation field of coco annotation

Parameters:
  • image_id (int) – Unique identifier for image to be used in coco annotation.

  • category_id (int) – Category identifier for object to be used in annotation

  • bbox (List[int]) – Boundry of object to be used in coco annotation format

  • segmentation (List[float]) – Polygon of object representing segmentation mask to be used in annotation

  • ann_id (int) – Unique identifier for annotation

Returns:

Single annotation for object.

Return type:

Dict

cpauger.generate_coco_ann.generate_coco_annotation_file(image_width: int, image_height: int, output_path: str, img_list: List) None[source]

Generate and export random coco annotation file

Parameters:
  • image_width (int) – Width of image

  • image_height (int) – Height of image

  • output_path (str) – Path to store the annotation

  • img_list (List) – List of image names

Returns: None

cpauger.generate_coco_ann.save_random_imgs(img_size: Tuple[int], save_as: str) None[source]

_summary_

Parameters:
  • img_size (Tuple[int]) – Image height and width

  • save_as (str) – Path to save the image

cpauger.generate_coco_ann.save_random_img_wrapper(args: Dict) None[source]

Wrapper around save_random_imgs

Parameters:
  • args (Dict) – arguments for save_random_imgs function where keys are the

  • save_random_imgs (parameter name and values are the values to assign.)

  • parameters. (requires img_size and save_as)

Returns: None

cpauger.generate_coco_ann.generate_random_images(image_height: int, image_width: int, number_of_images: int, output_dir: str = 'random_images', img_ext: str = 'jpg', image_name: str = 'random_images', parallelize: bool = True) List[str][source]

Generates random images

Parameters:
  • image_height (int) – Height of the image

  • image_width (int) – Width of the image

  • number_of_images (int) – Number of images to generate

  • output_dir (_type_, optional) – Directory to export images to. Defaults to random_images.

  • img_ext (str, optional) – Image extention to use to save. Defaults to jpg.

  • image_name (str, optional) – Prefix name to use in saving image. Defaults to random_images.

  • parallelize (bool, optional) – Multiprocess should be use for image generating. Defaults to True.

Returns:

List of paths to images generated

Return type:

List[str]

cpauger.generate_coco_ann.generate_random_images_and_annotation(image_height: int, image_width: int, number_of_images: int, output_dir: str = 'random_images', img_ext: str = 'jpg', image_name: str = 'random_images', parallelize: bool = True, save_ann_as: str = 'generated_annotation.json', **kwargs) Tuple[List, str][source]

Generates random images and annotations in coco format

Parameters:
  • image_height (int) – Height of the image

  • image_width (int) – Width of the image

  • number_of_images (int) – Number of images to generate

  • output_dir (_type_, optional) – Directory to export images to. Defaults to random_images.

  • img_ext (str, optional) – Image extention to use to save. Defaults to jpg.

  • image_name (str, optional) – Prefix name to use in saving image. Defaults to random_images.

  • parallelize (bool, optional) – Multiprocess should be use for image generating. Defaults to True.

  • save_ann_as (str, optional) – coco annotation file name to use for saving

Returns:

List of images generated paths and save_ann_as

Return type:

Tuple[List, str]