fix bbox for pascal voc loading and saving

This commit is contained in:
Mayank Agarwal committed 2023-07-24 19:01:21 +05:30
1 parent 8afd54a1cc
commit 06d0646fb8
1 file changed
+19 -7
+19 -7
View File
@@ -39,6 +39,16 @@ def object_to_pascal_voc(
return root
# Correction functions for VOC XML format as bounding boxes in VOC XML start at (1,1) not (0,0). Refer:
# https://github.com/roboflow/supervision/issues/144
def __increment_bbox_for_pascal_voc(xyxy):
return xyxy + 1
def __decrement_bbox_for_pascal_voc(xyxy):
return xyxy - 1
def detections_to_pascal_voc(
detections: Detections,
classes: List[str],
@@ -106,11 +116,11 @@ def detections_to_pascal_voc(
for polygon in polygons:
xyxy = polygon_to_xyxy(polygon=polygon)
next_object = object_to_pascal_voc(
xyxy=xyxy, name=name, polygon=polygon
xyxy=xyxy + 1, name=name, polygon=polygon
)
annotation.append(next_object)
else:
next_object = object_to_pascal_voc(xyxy=xyxy, name=name)
next_object = object_to_pascal_voc(xyxy=xyxy + 1, name=name)
annotation.append(next_object)
# Generate XML string
@@ -146,12 +156,14 @@ def load_pascal_voc_annotations(
# Correction for VOC XML format as bounding boxes in VOC XML start at (1,1) not (0,0). Refer:
# https://github.com/roboflow/supervision/issues/144
x1 = int(bbox.find("xmin").text) - 1
y1 = int(bbox.find("ymin").text) - 1
x2 = int(bbox.find("xmax").text) - 1
y2 = int(bbox.find("ymax").text) - 1
x1 = int(bbox.find("xmin").text)
y1 = int(bbox.find("ymin").text)
x2 = int(bbox.find("xmax").text)
y2 = int(bbox.find("ymax").text)
xyxy.append([x1, y1, x2, y2])
xyxy.append(
__decrement_bbox_for_pascal_voc(np.array([x1, y1, x2, y2])).tolist()
)
xyxy = np.array(xyxy)
detections = Detections(xyxy=xyxy)