Skip to content

Commit

Permalink
Calculates area of coco annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevmatias committed Mar 12, 2021
1 parent e7155f1 commit b2546b4
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 141 deletions.
4 changes: 2 additions & 2 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ def show_detection_example():

# Bboxes creation
gt_bbox_1 = BBox(10, 10, 100, 100, 0)
pred_bbox_1 = BBox(10, 10, 100, 100, 0, .8)
pred_bbox_1 = BBox(10, 10, 100, 100, 0, .8212158464)

gt_bbox_2 = BBox(110, 110, 320, 280, 1)
pred_bbox_2 = BBox(70, 50, 240, 220, 1, .3)
pred_bbox_2 = BBox(70, 50, 240, 220, 1, .34844545)

gt_bbox_3 = BBox(300, 300, 100, 100, 2)

Expand Down
7 changes: 7 additions & 0 deletions lapixdl/convert/labelbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ def __generate_coco_annotations(img_labels: List[dict], img_id: int, annotation_
'category_id': classes.index(class_name),
'id': annotation_first_id,
'bbox': bbox,
'area': __calculate_area(segmentation)
})

annotation_first_id += 1

return annotations


def __calculate_area(segmentation: List[float]) -> float:
x = segmentation[0:-1:2]
y = segmentation[1::2]
return 0.5*np.abs(np.dot(x, np.roll(y, 1))-np.dot(y, np.roll(x, 1))) #Shoelace


def __generate_coco_file(lblbox_annotations: dict, img_names_to_include: Optional[List[str]] = None) -> dict:
annotation_id = 1
image_id = 1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
name='lapixdl',
packages=find_packages(exclude=['tests']),
version='0.7.8',
version='0.7.9',
description='Utils for Computer Vision Deep Learning research',

long_description=long_description,
Expand Down
Loading

0 comments on commit b2546b4

Please sign in to comment.