diff --git a/.gitignore b/.gitignore index 5a2503c..b8944f8 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,5 @@ ENV/ \.DS_Store MANIFEST + +\.vscode/ diff --git a/pycococreatortools/pycococreatortools.py b/pycococreatortools/pycococreatortools.py index 05550e2..aa6515c 100755 --- a/pycococreatortools/pycococreatortools.py +++ b/pycococreatortools/pycococreatortools.py @@ -12,10 +12,10 @@ convert = lambda text: int(text) if text.isdigit() else text.lower() natrual_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] -def resize_array(array, new_size): - image = Image.fromarray(array) +def resize_binary_mask(array, new_size): + image = Image.fromarray(array.astype(np.uint8)*255) image = image.resize(new_size) - return np.asarray(image) + return np.asarray(image).astype(np.bool_) def close_contour(contour): if not np.array_equal(contour[0], contour[-1]): @@ -76,15 +76,21 @@ def create_image_info(image_id, file_name, image_size, return image_info -def create_annotation_info(annotation_id, image_id, category_info, binary_mask, image_size, tolerance=0): - binary_mask = resize_array(binary_mask, image_size) +def create_annotation_info(annotation_id, image_id, category_info, binary_mask, + image_size=None, tolerance=2, bounding_box=None): + + if image_size is not None: + binary_mask = resize_binary_mask(binary_mask, image_size) + binary_mask_encoded = mask.encode(np.asfortranarray(binary_mask.astype(np.uint8))) - bounding_box = mask.toBbox(binary_mask_encoded) - area = mask.area(binary_mask_encoded) + area = mask.area(binary_mask_encoded) if area < 1: return None + if bounding_box is None: + bounding_box = mask.toBbox(binary_mask_encoded) + if category_info["is_crowd"]: is_crowd = 1 segmentation = binary_mask_to_rle(binary_mask) diff --git a/setup.py b/setup.py index 3120aca..578a67c 100755 --- a/setup.py +++ b/setup.py @@ -6,12 +6,12 @@ setup(name='pycococreatortools', packages=['pycococreatortools'], package_dir = {'pycococreatortools': 'pycococreatortools'}, - version='0.1.5', + version='0.2.0', description = 'Tools to create COCO datasets', url = 'https://github.com/waspinator/pycococreator', author = 'waspinator', author_email = 'patrickwasp@gmail.com', - download_url = 'https://github.com/waspinator/pycococreator/archive/0.1.5.tar.gz', + download_url = 'https://github.com/waspinator/pycococreator/archive/0.2.0.tar.gz', keywords = ['coco', 'dataset', 'machine-learning'], install_requires=[ 'numpy', 'pillow', 'scikit-image'