diff --git a/doctr/utils/geometry.py b/doctr/utils/geometry.py index a49cd0d406..40427b42ee 100644 --- a/doctr/utils/geometry.py +++ b/doctr/utils/geometry.py @@ -37,9 +37,9 @@ def bbox_to_polygon(bbox: BoundingBox) -> Polygon4P: bbox: a bounding box Returns: - a polygon + a polygon with the top left, top right, bottom right and bottom left corners """ - return bbox[0], (bbox[1][0], bbox[0][1]), (bbox[0][0], bbox[1][1]), bbox[1] + return bbox[0], (bbox[1][0], bbox[0][1]), bbox[1], (bbox[0][0], bbox[1][1]) def polygon_to_bbox(polygon: Polygon4P) -> BoundingBox: diff --git a/tests/common/test_utils_geometry.py b/tests/common/test_utils_geometry.py index 844bbf6d03..963f57f5e9 100644 --- a/tests/common/test_utils_geometry.py +++ b/tests/common/test_utils_geometry.py @@ -1,6 +1,7 @@ from copy import deepcopy from math import hypot +import cv2 import numpy as np import pytest @@ -9,11 +10,13 @@ def test_bbox_to_polygon(): - assert geometry.bbox_to_polygon(((0, 0), (1, 1))) == ((0, 0), (1, 0), (0, 1), (1, 1)) + assert geometry.bbox_to_polygon(((0, 0), (1, 1))) == ((0, 0), (1, 0), (1, 1), (0, 1)) + # the corners go around the box, so the polygon is not self-intersecting + assert cv2.contourArea(np.array(geometry.bbox_to_polygon(((0, 0), (10, 10))), dtype=np.float32)) == 100 def test_polygon_to_bbox(): - assert geometry.polygon_to_bbox(((0, 0), (1, 0), (0, 1), (1, 1))) == ((0, 0), (1, 1)) + assert geometry.polygon_to_bbox(((0, 0), (1, 0), (1, 1), (0, 1))) == ((0, 0), (1, 1)) def test_order_points():