diff --git a/mapillary_tools/process_sequence_properties.py b/mapillary_tools/process_sequence_properties.py index 27ca1a4cc..ff039a41e 100644 --- a/mapillary_tools/process_sequence_properties.py +++ b/mapillary_tools/process_sequence_properties.py @@ -46,8 +46,8 @@ def cut_sequence_by_time_distance( def duplication_check( sequence: PointSequence, - duplicate_distance: float, - duplicate_angle: float, + max_duplicate_distance: float, + max_duplicate_angle: float, ) -> T.Tuple[PointSequence, T.List[types.ErrorMetadata]]: dedups: PointSequence = [] dups: T.List[types.ErrorMetadata] = [] @@ -70,13 +70,14 @@ def duplication_check( else: angle_diff = None - if distance <= duplicate_distance and ( - angle_diff is not None and angle_diff <= duplicate_angle + if distance <= max_duplicate_distance and ( + angle_diff is None or angle_diff <= max_duplicate_angle ): + msg = f"Duplicate of its previous image in terms of distance <= {max_duplicate_distance} and angle <= {max_duplicate_angle}" dups.append( types.describe_error_metadata( MapillaryDuplicationError( - f"Duplicate of its previous image in terms of distance <= {duplicate_distance} and angle <= {duplicate_angle}", + msg, types.as_desc(cur), distance=distance, angle_diff=angle_diff, @@ -305,8 +306,8 @@ def process_sequence_properties( # duplication check dedups, dups = duplication_check( sequence, - duplicate_distance=duplicate_distance, - duplicate_angle=duplicate_angle, + max_duplicate_distance=duplicate_distance, + max_duplicate_angle=duplicate_angle, ) assert len(sequence) == len(dedups) + len(dups) error_metadatas.extend(dups) diff --git a/tests/unit/test_sequence_processing.py b/tests/unit/test_sequence_processing.py index 79e35db70..401857b98 100644 --- a/tests/unit/test_sequence_processing.py +++ b/tests/unit/test_sequence_processing.py @@ -52,21 +52,30 @@ def test_find_sequences_by_folder(tmpdir: py.path.local): error=Exception("an error"), ), # s1 - _make_image_metadata(Path(curdir) / Path("hello/foo.jpg"), 1.00001, 1.00001, 2), + _make_image_metadata( + Path(curdir) / Path("hello/foo.jpg"), 1.00001, 1.00001, 2, 11 + ), _make_image_metadata( Path(curdir) / Path("./hello/bar.jpg"), 1.00002, 1.00002, 8, + 22, + ), + _make_image_metadata( + Path(curdir) / Path("hello/a.jpg"), 1.00002, 1.00002, 9, 33 ), - _make_image_metadata(Path(curdir) / Path("hello/a.jpg"), 1.00002, 1.00002, 9), # s2 - _make_image_metadata(Path(curdir) / Path("hello.jpg"), 1.00002, 1.00002, 2), - _make_image_metadata(Path(curdir) / Path("./foo.jpg"), 1.00001, 1.00001, 3), - _make_image_metadata(Path(curdir) / Path("a.jpg"), 1.00001, 1.00001, 1), + _make_image_metadata(Path(curdir) / Path("hello.jpg"), 1.00002, 1.00002, 2, 11), + _make_image_metadata(Path(curdir) / Path("./foo.jpg"), 1.00001, 1.00001, 3, 22), + _make_image_metadata(Path(curdir) / Path("a.jpg"), 1.00001, 1.00001, 1, 33), # s3 - _make_image_metadata(Path(curdir) / Path("./../foo.jpg"), 1.00001, 1.00001, 19), - _make_image_metadata(Path(curdir) / Path("../bar.jpg"), 1.00002, 1.00002, 28), + _make_image_metadata( + Path(curdir) / Path("./../foo.jpg"), 1.00001, 1.00001, 19, 11 + ), + _make_image_metadata( + Path(curdir) / Path("../bar.jpg"), 1.00002, 1.00002, 28, 22 + ), ] metadatas = psp.process_sequence_properties( sequence, @@ -277,11 +286,11 @@ def test_subsec_interpolation(tmpdir: py.path.local): curdir = tmpdir.mkdir("hello222").mkdir("world333") sequence: T.List[types.Metadata] = [ # s1 - _make_image_metadata(Path(curdir) / Path("./a.jpg"), 1, 1, 0.0), - _make_image_metadata(Path(curdir) / Path("./b.jpg"), 0, 1, 1.0), - _make_image_metadata(Path(curdir) / Path("./c.jpg"), 0, 0, 1.0), - _make_image_metadata(Path(curdir) / Path("./d.jpg"), 0, 0, 1.0), - _make_image_metadata(Path(curdir) / Path("./e.jpg"), 1, 0, 2.0), + _make_image_metadata(Path(curdir) / Path("./a.jpg"), 1, 1, 0.0, 1), + _make_image_metadata(Path(curdir) / Path("./b.jpg"), 0, 1, 1.0, 11), + _make_image_metadata(Path(curdir) / Path("./c.jpg"), 0, 0, 1.0, 22), + _make_image_metadata(Path(curdir) / Path("./d.jpg"), 0, 0, 1.0, 33), + _make_image_metadata(Path(curdir) / Path("./e.jpg"), 1, 0, 2.0, 44), ] metadatas = psp.process_sequence_properties( sequence,