From 75027cb346e3b2e77b848ef236c6518b13e96c6a Mon Sep 17 00:00:00 2001 From: Zhiltsov Max Date: Fri, 10 Jul 2020 10:39:32 +0300 Subject: [PATCH 1/2] Add interpolation smoke tests --- cvat/apps/dataset_manager/annotation.py | 4 +- .../dataset_manager/tests/test_annotation.py | 92 ++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/cvat/apps/dataset_manager/annotation.py b/cvat/apps/dataset_manager/annotation.py index 54b0f21a6477..6c7df4b1d1e3 100644 --- a/cvat/apps/dataset_manager/annotation.py +++ b/cvat/apps/dataset_manager/annotation.py @@ -442,11 +442,11 @@ def normalize_shape(shape): @staticmethod def get_interpolated_shapes(track, start_frame, end_frame): - def copy_shape(source, frame, points = None): + def copy_shape(source, frame, points=None): copied = deepcopy(source) copied["keyframe"] = True copied["frame"] = frame - if points: + if points is not None: copied["points"] = points return copied diff --git a/cvat/apps/dataset_manager/tests/test_annotation.py b/cvat/apps/dataset_manager/tests/test_annotation.py index 2db3969906a5..d27d07293d3b 100644 --- a/cvat/apps/dataset_manager/tests/test_annotation.py +++ b/cvat/apps/dataset_manager/tests/test_annotation.py @@ -8,7 +8,7 @@ class TrackManagerTest(TestCase): - def test_single_point_interpolation(self): + def test_point_interpolation(self): track = { "frame": 0, "label_id": 0, @@ -36,4 +36,94 @@ def test_single_point_interpolation(self): interpolated = TrackManager.get_interpolated_shapes(track, 0, 2) + self.assertEqual(len(interpolated), 3) + + def test_polygon_interpolation(self): + track = { + "frame": 0, + "label_id": 0, + "group": None, + "attributes": [], + "shapes": [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0, 5.0, 2.0], + "type": "polygon", + "occluded": False, + "outside": False, + "attributes": [] + }, + { + "frame": 2, + "attributes": [], + "points": [3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 4.0, 5.0], + "type": "polygon", + "occluded": False, + "outside": True + }, + ] + } + + interpolated = TrackManager.get_interpolated_shapes(track, 0, 2) + + self.assertEqual(len(interpolated), 3) + + def test_bbox_interpolation(self): + track = { + "frame": 0, + "label_id": 0, + "group": None, + "attributes": [], + "shapes": [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0], + "type": "rectangle", + "occluded": False, + "outside": False, + "attributes": [] + }, + { + "frame": 2, + "attributes": [], + "points": [3.0, 4.0, 5.0, 6.0], + "type": "rectangle", + "occluded": False, + "outside": True + }, + ] + } + + interpolated = TrackManager.get_interpolated_shapes(track, 0, 2) + + self.assertEqual(len(interpolated), 3) + + def test_line_interpolation(self): + track = { + "frame": 0, + "label_id": 0, + "group": None, + "attributes": [], + "shapes": [ + { + "frame": 0, + "points": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], + "type": "polyline", + "occluded": False, + "outside": False, + "attributes": [] + }, + { + "frame": 2, + "attributes": [], + "points": [3.0, 4.0, 5.0, 6.0], + "type": "polyline", + "occluded": False, + "outside": True + }, + ] + } + + interpolated = TrackManager.get_interpolated_shapes(track, 0, 2) + self.assertEqual(len(interpolated), 3) \ No newline at end of file From 5ddb8afa4b534758c27d334e91c21e63b2691386 Mon Sep 17 00:00:00 2001 From: Zhiltsov Max Date: Fri, 10 Jul 2020 10:42:50 +0300 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a9fda1ab27..5313d9bec99f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Annotations aren't updated after reopening a task () - Labels aren't updated after reopening a task () - Canvas isn't fitted after collapsing side panel in attribute annotation mode () +- Error when interpolating polygons () ### Security - SQL injection in Django `CVE-2020-9402` ()