Skip to content

Commit 8be2e4c

Browse files
committed
bug fix
1 parent 8235fc4 commit 8be2e4c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

davarocr/davarocr/davar_common/datasets/pipelines/transforms.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,38 @@ def _rotate_img(self, results):
395395
gt_boxes_ret = []
396396
for poly in results[key]:
397397
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+
399403
# Convert to np.array of shape (:, 2)
400404
for i in range(0, len(poly), 2):
401405
rot_array.append(np.array([poly[i], poly[i + 1]]))
402406

403407
# Rotate corresponding annotations
404408
rot_array = np.array([rot_array])
405409
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+
406421
gt_boxes_ret.append(rot_array)
407-
results[key] = gt_boxes_ret
422+
if len(results[key]) > 0:
423+
results[key] = gt_boxes_ret
408424

409425
# 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:
412427
gt_bboxes = []
413428
gt_bboxes_ignore = []
429+
414430
for poly in results['gt_poly_bboxes']:
415431
poly = np.array(poly, dtype=np.double)
416432
x_coords = poly[0::2]
@@ -502,11 +518,7 @@ def __call__(self, results):
502518
else:
503519
angle = np.random.choice(self.angles)
504520
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)
510522
return results
511523

512524
def __repr__(self):

0 commit comments

Comments
 (0)