Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doctr/utils/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions tests/common/test_utils_geometry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from copy import deepcopy
from math import hypot

import cv2
import numpy as np
import pytest

Expand All @@ -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():
Expand Down
Loading