Skip to content

Commit fba8f40

Browse files
committed
added custom bounding box option
1 parent abe3653 commit fba8f40

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,5 @@ ENV/
103103
\.DS_Store
104104

105105
MANIFEST
106+
107+
\.vscode/

pycococreatortools/pycococreatortools.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
convert = lambda text: int(text) if text.isdigit() else text.lower()
1313
natrual_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
1414

15-
def resize_array(array, new_size):
16-
image = Image.fromarray(array)
15+
def resize_binary_mask(array, new_size):
16+
image = Image.fromarray(array.astype(np.uint8)*255)
1717
image = image.resize(new_size)
18-
return np.asarray(image)
18+
return np.asarray(image).astype(np.bool_)
1919

2020
def close_contour(contour):
2121
if not np.array_equal(contour[0], contour[-1]):
@@ -76,15 +76,21 @@ def create_image_info(image_id, file_name, image_size,
7676

7777
return image_info
7878

79-
def create_annotation_info(annotation_id, image_id, category_info, binary_mask, image_size, tolerance=0):
80-
binary_mask = resize_array(binary_mask, image_size)
79+
def create_annotation_info(annotation_id, image_id, category_info, binary_mask,
80+
image_size=None, tolerance=2, bounding_box=None):
81+
82+
if image_size is not None:
83+
binary_mask = resize_binary_mask(binary_mask, image_size)
84+
8185
binary_mask_encoded = mask.encode(np.asfortranarray(binary_mask.astype(np.uint8)))
82-
bounding_box = mask.toBbox(binary_mask_encoded)
83-
area = mask.area(binary_mask_encoded)
8486

87+
area = mask.area(binary_mask_encoded)
8588
if area < 1:
8689
return None
8790

91+
if bounding_box is None:
92+
bounding_box = mask.toBbox(binary_mask_encoded)
93+
8894
if category_info["is_crowd"]:
8995
is_crowd = 1
9096
segmentation = binary_mask_to_rle(binary_mask)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
setup(name='pycococreatortools',
77
packages=['pycococreatortools'],
88
package_dir = {'pycococreatortools': 'pycococreatortools'},
9-
version='0.1.5',
9+
version='0.2.0',
1010
description = 'Tools to create COCO datasets',
1111
url = 'https://github.com/waspinator/pycococreator',
1212
author = 'waspinator',
1313
author_email = '[email protected]',
14-
download_url = 'https://github.com/waspinator/pycococreator/archive/0.1.5.tar.gz',
14+
download_url = 'https://github.com/waspinator/pycococreator/archive/0.2.0.tar.gz',
1515
keywords = ['coco', 'dataset', 'machine-learning'],
1616
install_requires=[
1717
'numpy', 'pillow', 'scikit-image'

0 commit comments

Comments
 (0)