@@ -395,22 +395,38 @@ def _rotate_img(self, results):
395
395
gt_boxes_ret = []
396
396
for poly in results [key ]:
397
397
rot_array = []
398
-
398
+ poly_length = len (poly )
399
+
400
+ if poly_length == 4 :
401
+ poly = [poly [0 ], poly [1 ], poly [2 ], poly [1 ], poly [2 ], poly [3 ], poly [0 ], poly [3 ]]
402
+
399
403
# Convert to np.array of shape (:, 2)
400
404
for i in range (0 , len (poly ), 2 ):
401
405
rot_array .append (np .array ([poly [i ], poly [i + 1 ]]))
402
406
403
407
# Rotate corresponding annotations
404
408
rot_array = np .array ([rot_array ])
405
409
rot_array = cv2 .transform (rot_array , mat_rotation ).squeeze ().reshape (len (poly ))
410
+
411
+ if poly_length == 4 :
412
+ x_coords = rot_array [0 ::2 ]
413
+ y_coords = rot_array [1 ::2 ]
414
+ rot_array = np .array ([
415
+ np .min (x_coords ),
416
+ np .min (y_coords ),
417
+ np .max (x_coords ),
418
+ np .max (y_coords )
419
+ ])
420
+
406
421
gt_boxes_ret .append (rot_array )
407
- results [key ] = gt_boxes_ret
422
+ if len (results [key ]) > 0 :
423
+ results [key ] = gt_boxes_ret
408
424
409
425
# Rotate gt_bboxes according to gt_poly_bboxes
410
- if 'gt_bboxes' in results :
411
- assert 'gt_poly_bboxes' in results
426
+ if 'gt_bboxes' in results and 'gt_poly_bboxes' in results :
412
427
gt_bboxes = []
413
428
gt_bboxes_ignore = []
429
+
414
430
for poly in results ['gt_poly_bboxes' ]:
415
431
poly = np .array (poly , dtype = np .double )
416
432
x_coords = poly [0 ::2 ]
@@ -502,11 +518,7 @@ def __call__(self, results):
502
518
else :
503
519
angle = np .random .choice (self .angles )
504
520
self .angle = angle
505
- try :
506
- self ._rotate_img (results )
507
- except Exception as e :
508
- print (e )
509
- return None
521
+ self ._rotate_img (results )
510
522
return results
511
523
512
524
def __repr__ (self ):
0 commit comments