From 66c6e7e9195507627e697eaa86ef5020784cc754 Mon Sep 17 00:00:00 2001 From: zhiltsov-max Date: Thu, 2 Apr 2020 14:08:22 +0300 Subject: [PATCH] Fix point interpolation (#1344) * Extend formats tests with different track types * Add unordered list comparison * Skip empty list comparison * fix * fix * Reproduce problem * Fix point interpolation for single point * undo rest api refactor --- cvat/apps/engine/data_manager.py | 5 ++- cvat/apps/engine/tests/test_data_manager.py | 39 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 cvat/apps/engine/tests/test_data_manager.py diff --git a/cvat/apps/engine/data_manager.py b/cvat/apps/engine/data_manager.py index d7adc8b8b4a5..b39c6783f616 100644 --- a/cvat/apps/engine/data_manager.py +++ b/cvat/apps/engine/data_manager.py @@ -293,7 +293,10 @@ def _modify_unmached_object(obj, end_frame): @staticmethod def normalize_shape(shape): - points = np.asarray(shape["points"]).reshape(-1, 2) + points = list(shape["points"]) + if len(points) == 2: + points.extend(points) # duplicate points for single point case + points = np.asarray(points).reshape(-1, 2) broken_line = geometry.LineString(points) points = [] for off in range(0, 100, 1): diff --git a/cvat/apps/engine/tests/test_data_manager.py b/cvat/apps/engine/tests/test_data_manager.py new file mode 100644 index 000000000000..968b57525f6b --- /dev/null +++ b/cvat/apps/engine/tests/test_data_manager.py @@ -0,0 +1,39 @@ +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT + +from cvat.apps.engine.data_manager import TrackManager + +from unittest import TestCase + + +class TrackManagerTest(TestCase): + def test_single_point_interpolation(self): + track = { + "frame": 0, + "label_id": 0, + "group": None, + "attributes": [], + "shapes": [ + { + "frame": 0, + "points": [1.0, 2.0], + "type": "points", + "occluded": False, + "outside": False, + "attributes": [] + }, + { + "frame": 2, + "attributes": [], + "points": [3.0, 4.0, 5.0, 6.0], + "type": "points", + "occluded": False, + "outside": True + }, + ] + } + + interpolated = TrackManager.get_interpolated_shapes(track, 0, 2) + + self.assertEqual(len(interpolated), 3) \ No newline at end of file