@@ -1398,13 +1398,27 @@ def to_keypoints_on_image(self):
1398
1398
Returns
1399
1399
-------
1400
1400
imgaug.augmentables.kps.KeypointsOnImage
1401
- A keypoints instance containing ``N*2 `` coordinates for ``N``
1401
+ A keypoints instance containing ``N*4 `` coordinates for ``N``
1402
1402
bounding boxes. Order matches the order in ``bounding_boxes``.
1403
1403
1404
1404
"""
1405
1405
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
+
1406
1420
return KeypointsOnImage .from_xy_array (
1407
- self . to_xyxy_array () .reshape ((- 1 , 2 )),
1421
+ arr .reshape ((- 1 , 2 )),
1408
1422
shape = self .shape
1409
1423
)
1410
1424
@@ -1427,12 +1441,14 @@ def invert_to_keypoints_on_image_(self, kpsoi):
1427
1441
Note that the instance is also updated in-place.
1428
1442
1429
1443
"""
1430
- assert len (kpsoi .keypoints ) == len (self .bounding_boxes ) * 2 , (
1444
+ assert len (kpsoi .keypoints ) == len (self .bounding_boxes ) * 4 , (
1431
1445
"Expected %d coordinates, got %d." % (
1432
1446
len (self .bounding_boxes ) * 2 , len (kpsoi .keypoints )))
1433
1447
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 ]
1436
1452
bb .x1 = min (xx )
1437
1453
bb .y1 = min (yy )
1438
1454
bb .x2 = max (xx )
0 commit comments