Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions mapillary_tools/process_sequence_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 21 additions & 12 deletions tests/unit/test_sequence_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading