Skip to content

Commit

Permalink
added custom bounding box option
Browse files Browse the repository at this point in the history
  • Loading branch information
waspinator committed May 8, 2018
1 parent abe3653 commit fba8f40
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ ENV/
\.DS_Store

MANIFEST

\.vscode/
20 changes: 13 additions & 7 deletions pycococreatortools/pycococreatortools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]',
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'
Expand Down

0 comments on commit fba8f40

Please sign in to comment.