Skip to content

Commit 353c9c1

Browse files
committed
Switch BB aug from 2 to 4 corners by default
1 parent 10f12ff commit 353c9c1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

imgaug/augmentables/bbs.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,27 @@ def to_keypoints_on_image(self):
13981398
Returns
13991399
-------
14001400
imgaug.augmentables.kps.KeypointsOnImage
1401-
A keypoints instance containing ``N*2`` coordinates for ``N``
1401+
A keypoints instance containing ``N*4`` coordinates for ``N``
14021402
bounding boxes. Order matches the order in ``bounding_boxes``.
14031403
14041404
"""
14051405
from .kps import KeypointsOnImage
1406+
1407+
# This currently uses 4 points instead of 2 points as the method
1408+
# is primarily used during augmentation and 4 points are overall
1409+
# the better choice there.
1410+
arr = np.zeros((len(self.bounding_boxes), 2*4), dtype=np.float32)
1411+
1412+
for i, box in enumerate(self.bounding_boxes):
1413+
arr[i] = [
1414+
box.x1, box.y1,
1415+
box.x2, box.y1,
1416+
box.x2, box.y2,
1417+
box.x1, box.y2
1418+
]
1419+
14061420
return KeypointsOnImage.from_xy_array(
1407-
self.to_xyxy_array().reshape((-1, 2)),
1421+
arr.reshape((-1, 2)),
14081422
shape=self.shape
14091423
)
14101424

@@ -1427,12 +1441,14 @@ def invert_to_keypoints_on_image_(self, kpsoi):
14271441
Note that the instance is also updated in-place.
14281442
14291443
"""
1430-
assert len(kpsoi.keypoints) == len(self.bounding_boxes) * 2, (
1444+
assert len(kpsoi.keypoints) == len(self.bounding_boxes) * 4, (
14311445
"Expected %d coordinates, got %d." % (
14321446
len(self.bounding_boxes) * 2, len(kpsoi.keypoints)))
14331447
for i, bb in enumerate(self.bounding_boxes):
1434-
xx = [kpsoi.keypoints[2*i+0].x, kpsoi.keypoints[2*i+1].x]
1435-
yy = [kpsoi.keypoints[2*i+0].y, kpsoi.keypoints[2*i+1].y]
1448+
xx = [kpsoi.keypoints[4*i+0].x, kpsoi.keypoints[4*i+1].x,
1449+
kpsoi.keypoints[4*i+2].x, kpsoi.keypoints[4*i+3].x]
1450+
yy = [kpsoi.keypoints[4*i+0].y, kpsoi.keypoints[4*i+1].y,
1451+
kpsoi.keypoints[4*i+2].y, kpsoi.keypoints[4*i+3].y]
14361452
bb.x1 = min(xx)
14371453
bb.y1 = min(yy)
14381454
bb.x2 = max(xx)

0 commit comments

Comments
 (0)