From 47ea75139c688ba26b494fd6a1c4cd54d2569f75 Mon Sep 17 00:00:00 2001 From: Kirill Sizov Date: Thu, 24 Jun 2021 12:05:04 +0300 Subject: [PATCH] Fix interpolation for outside shapes (#3348) * fix interpolation * add tests * remove unnecessary conditions Co-authored-by: Nikita Manovich --- cvat/apps/dataset_manager/annotation.py | 12 +- .../dataset_manager/tests/test_annotation.py | 136 ++++++++++++++++++ 2 files changed, 138 insertions(+), 10 deletions(-) diff --git a/cvat/apps/dataset_manager/annotation.py b/cvat/apps/dataset_manager/annotation.py index e34d47cd9..0fbd6bf09 100644 --- a/cvat/apps/dataset_manager/annotation.py +++ b/cvat/apps/dataset_manager/annotation.py @@ -453,11 +453,7 @@ class TrackManager(ObjectManager): for frame in range(shape0["frame"] + 1, shape1["frame"]): offset = (frame - shape0["frame"]) / distance - points = None - if shape1["outside"]: - points = np.asarray(shape0["points"]) - else: - points = shape0["points"] + diff * offset + points = shape0["points"] + diff * offset shapes.append(copy_shape(shape0, frame, points.tolist())) @@ -679,11 +675,7 @@ class TrackManager(ObjectManager): distance = shape1["frame"] - shape0["frame"] for frame in range(shape0["frame"] + 1, shape1["frame"]): offset = (frame - shape0["frame"]) / distance - points = None - if shape1["outside"]: - points = np.asarray(shape0["points"]) - else: - points = interpolate_position(shape0, shape1, offset) + points = interpolate_position(shape0, shape1, offset) shapes.append(copy_shape(shape0, frame, points)) diff --git a/cvat/apps/dataset_manager/tests/test_annotation.py b/cvat/apps/dataset_manager/tests/test_annotation.py index f7263dc3c..b9bbd6f0b 100644 --- a/cvat/apps/dataset_manager/tests/test_annotation.py +++ b/cvat/apps/dataset_manager/tests/test_annotation.py @@ -167,3 +167,139 @@ class TrackManagerTest(TestCase): self._check_interpolation(track) + def test_outside_bbox_interpolation(self): + track = { + "frame": 0, + "label_id": 0, + "group": None, + "attributes": [], + "source": "manual", + "shapes": [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0], + "type": "rectangle", + "occluded": False, + "outside": False, + "attributes": [] + }, + { + "frame": 2, + "points": [3.0, 4.0, 5.0, 6.0], + "type": "rectangle", + "occluded": False, + "outside": True, + "attributes": [], + }, + { + "frame": 4, + "points": [5.0, 6.0, 7.0, 8.0], + "type": "rectangle", + "occluded": False, + "outside": True, + "attributes": [] + } + ] + } + + expected_shapes = [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0], + "type": "rectangle", + "occluded": False, + "outside": False, + "attributes": [], + "keyframe": True + }, + { + "frame": 1, + "points": [2.0, 3.0, 4.0, 5.0], + "type": "rectangle", + "occluded": False, + "outside": False, + "attributes": [], + "keyframe": False + }, + { + "frame": 2, + "points": [3.0, 4.0, 5.0, 6.0], + "type": "rectangle", + "occluded": False, + "outside": True, + "attributes": [], + "keyframe": True + }, + { + "frame": 4, + "points": [5.0, 6.0, 7.0, 8.0], + "type": "rectangle", + "occluded": False, + "outside": True, + "attributes": [], + "keyframe": True + } + ] + + interpolated_shapes = TrackManager.get_interpolated_shapes(track, 0, 5) + self.assertEqual(expected_shapes, interpolated_shapes) + + def test_outside_polygon_interpolation(self): + track = { + "frame": 0, + "label_id": 0, + "group": None, + "attributes": [], + "source": "manual", + "shapes": [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], + "type": "polygon", + "occluded": False, + "outside": False, + "attributes": [] + }, + { + "frame": 2, + "points": [3.0, 4.0, 5.0, 6.0, 7.0, 8.0], + "type": "polygon", + "occluded": False, + "outside": True, + "attributes": [] + } + ] + } + + expected_shapes = [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], + "type": "polygon", + "occluded": False, + "outside": False, + "attributes": [], + "keyframe": True + }, + { + "frame": 1, + "points": [2.0, 3.0, 4.0, 5.0, 6.0, 7.0], + "type": "polygon", + "occluded": False, + "outside": False, + "attributes": [], + "keyframe": False + }, + { + "frame": 2, + "points": [3.0, 4.0, 5.0, 6.0, 7.0, 8.0], + "type": "polygon", + "occluded": False, + "outside": True, + "attributes": [], + "keyframe": True + } + ] + + interpolated_shapes = TrackManager.get_interpolated_shapes(track, 0, 3) + self.assertEqual(expected_shapes, interpolated_shapes) -- GitLab