Skip to content

Commit eff2543

Browse files
authored
use computed area instead 1.0
1 parent 2e59ffd commit eff2543

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

csv2coco.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _annotation(self, shape,label):
8686
annotation['segmentation'] = self._get_seg(points)
8787
annotation['bbox'] = self._get_box(points)
8888
annotation['iscrowd'] = 0
89-
annotation['area'] = 1.0
89+
annotation['area'] = self._get_area(points)
9090
return annotation
9191

9292
# COCO的格式: [x1,y1,w,h] 对应COCO的bbox格式
@@ -96,6 +96,13 @@ def _get_box(self, points):
9696
max_x = points[2]
9797
max_y = points[3]
9898
return [min_x, min_y, max_x - min_x, max_y - min_y]
99+
# 计算面积
100+
def _get_area(self, points):
101+
min_x = points[0]
102+
min_y = points[1]
103+
max_x = points[2]
104+
max_y = points[3]
105+
return (max_x - min_x+1) * (max_y - min_y+1)
99106
# segmentation
100107
def _get_seg(self, points):
101108
min_x = points[0]

0 commit comments

Comments
 (0)