From a1c2c9525f311e5f12872152cedcb6bd5fd0f686 Mon Sep 17 00:00:00 2001 From: Caglar Pir Date: Wed, 2 Dec 2026 15:44:23 +0100 Subject: [PATCH] Raise the duplicate defaults to 3 m and 10 degrees An image within --duplicate_distance of the last image kept, and within --duplicate_angle of its direction, is left out as a duplicate. The defaults go from 0.1 m and 5 degrees to 3 m and 10 degrees, as in the mobile apps; 3 m is also the default distance between video frames. Images that a camera keeps taking while stopped, at a red light say, are now left out when they are within 3 m and 10 degrees of the last image kept. Frames sampled at the default 3 m are not affected. Denser frames (--video_sample_distance below 3 m, or --video_sample_interval) are thinned to 3 m unless --duplicate_distance is lowered too; the command reference says so. The splitting tests spaced their images 1.6 m apart: they are 16 m apart now, as they are not about duplicates. --- README.md | 6 +-- docs/command_reference.md | 11 ++++- mapillary_tools/constants.py | 7 ++- tests/integration/test_video_process.py | 11 ++++- tests/unit/test_sequence_processing.py | 60 ++++++++++++++++++++----- 5 files changed, 76 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 33ee8594..dd6c4b25 100644 --- a/README.md +++ b/README.md @@ -217,10 +217,10 @@ mapillary_tools process MY_CAPTURE_DIR MY_VIDEO_DIR/*.mp4 Duplicate check with custom distance and angle: ```sh -# Mark images within 3 meters of the previous one as duplicates. -# Duplicates won't be uploaded +# Mark images within 5 meters of the previous one as duplicates +# (default: 3 meters and 10 degrees). Duplicates won't be uploaded mapillary_tools process MY_CAPTURE_DIR \ - --duplicate_distance 3 \ + --duplicate_distance 5 \ --duplicate_angle 360 # Set 360 to disable angle check ``` diff --git a/docs/command_reference.md b/docs/command_reference.md index aadba1ec..29559c82 100644 --- a/docs/command_reference.md +++ b/docs/command_reference.md @@ -99,7 +99,7 @@ Then each file is checked. Files that fail a check get an error entry and are no | Check | Applies to | Error | | --------------------------------------- | --------------- | ------------------------------------------------------------------------ | -| Same position and direction as the image before it (`--duplicate_distance` 0.1 m, `--duplicate_angle` 5°) | images | `MapillaryDuplicationError`, which does not fail the command | +| Within `--duplicate_distance` (3 m) of the last image kept, and within `--duplicate_angle` (10°) of its direction | images | `MapillaryDuplicationError`, which does not fail the command | | Position (0, 0) | images, videos | `MapillaryNullIslandError` | | Average speed above 400 km/h | sequences, videos | `MapillaryCaptureSpeedTooFastError` | | GPS positions that jump back and forth | sequences | `MapillaryZigZagError` (turn off with `--skip_zigzag_check`) | @@ -158,7 +158,7 @@ give an `--overwrite_*` option. | `--use_file_time_as_capture_time` | | Give an image with a GPS position but no capture time the earlier of its file modification and creation times. See the gotchas below. | | `--interpolate_directions` | | Point each image at the next one, instead of using the direction from EXIF. | | `--cutoff_time`, `--cutoff_distance` | 60 s, 100 m | Where to split sequences. | -| `--duplicate_distance`, `--duplicate_angle` | 0.1 m, 5° | When an image counts as a duplicate of the one before it. `--duplicate_angle 360` ignores direction. | +| `--duplicate_distance`, `--duplicate_angle` | 3 m, 10° | When an image counts as a duplicate of the last image kept. `--duplicate_angle 360` ignores direction. | | `--skip_zigzag_check` | | Do not fail sequences whose GPS zig-zags. | | `--device_make`, `--device_model` | | Override the camera make and model. | | `--overwrite_all_EXIF_tags` | | Write the processed time, position, direction and orientation into the EXIF of the images. `--overwrite_EXIF_time_tag`, `--overwrite_EXIF_gps_tag`, `--overwrite_EXIF_direction_tag` and `--overwrite_EXIF_orientation_tag` write one each. | @@ -200,6 +200,10 @@ Gotchas: `--interpolation_offset_time` shifts them before they are placed on a track, so it moves the images too. Both change the capture time that is uploaded: to fix a camera clock against a GPX, use `--interpolation_offset_time` alone. +- An image within 3 m of the last image kept, and pointing within 10° of its direction, is left out as a duplicate + (`--duplicate_distance`, `--duplicate_angle`). Images without a direction are compared by distance alone. So + images taken less than 3 m apart, as when walking or stopped at a red light, are thinned out: of images 2 m + apart, every other one is left out. - The `--overwrite_*` options modify your original images. - An image with a GPS position of its own but no capture time that any source can read fails, with a message that says how to fix it. With `--use_file_time_as_capture_time`, it gets the earlier of its file modification and @@ -506,6 +510,9 @@ Gotchas: - Unlike `process`, it does not look for a track beside each video by the default pattern: without `--geotag_source_path`, give the pattern, as in `--video_geotag_source '{"source": "gpx", "pattern": "%g.gpx"}'`. +- The frames go through the duplicate check of `process`: frames within 3 m of the last frame kept, in about the + same direction, are left out. With `--video_sample_distance` below 3 m, or `--video_sample_interval` while moving + slowly, give a smaller `--duplicate_distance` too to keep them all. ## video_process_and_upload diff --git a/mapillary_tools/constants.py b/mapillary_tools/constants.py index 72bac96b..21d5779e 100644 --- a/mapillary_tools/constants.py +++ b/mapillary_tools/constants.py @@ -143,8 +143,11 @@ def _parse_scaled_integers( CUTOFF_DISTANCE = float(os.getenv(_ENV_PREFIX + "CUTOFF_DISTANCE", 100)) # In seconds CUTOFF_TIME = float(os.getenv(_ENV_PREFIX + "CUTOFF_TIME", 60)) -DUPLICATE_DISTANCE = float(os.getenv(_ENV_PREFIX + "DUPLICATE_DISTANCE", 0.1)) -DUPLICATE_ANGLE = float(os.getenv(_ENV_PREFIX + "DUPLICATE_ANGLE", 5)) +# In meters, as the mobile apps, and the default distance between video frames +# (VIDEO_SAMPLE_DISTANCE) +DUPLICATE_DISTANCE = float(os.getenv(_ENV_PREFIX + "DUPLICATE_DISTANCE", 3)) +# In degrees, as the mobile apps +DUPLICATE_ANGLE = float(os.getenv(_ENV_PREFIX + "DUPLICATE_ANGLE", 10)) MAX_CAPTURE_SPEED_KMH = float( os.getenv(_ENV_PREFIX + "MAX_CAPTURE_SPEED_KMH", 400) ) # 400 KM/h diff --git a/tests/integration/test_video_process.py b/tests/integration/test_video_process.py index 0e944b26..306aebaf 100644 --- a/tests/integration/test_video_process.py +++ b/tests/integration/test_video_process.py @@ -199,7 +199,14 @@ def test_video_process_by_interval_with_the_default_geotag_sources( pytest_skip_if_not_ffmpeg_installed() video_path = setup_data.join("gopro_data").join("max-360mode.mp4") - interval = ["--video_sample_interval=2", "--video_sample_distance=-1"] + # Every sample, however close to the one before: one of the six is within + # the default duplicate distance (3 m) of the one before it + no_duplicates = ["--duplicate_distance=0"] + interval = [ + "--video_sample_interval=2", + "--video_sample_distance=-1", + *no_duplicates, + ] with tempfile.TemporaryDirectory() as dir: descs = run_video_process_for_descs([*interval, str(video_path), dir]) @@ -208,7 +215,7 @@ def test_video_process_by_interval_with_the_default_geotag_sources( assert all("error" not in desc for desc in descs), descs # sample_video and process, as video_process runs them - process_descs = run_process_for_descs([str(sample_dir)]) + process_descs = run_process_for_descs([*no_duplicates, str(sample_dir)]) assert_same_image_descs(process_descs, descs) with tempfile.TemporaryDirectory() as dir: diff --git a/tests/unit/test_sequence_processing.py b/tests/unit/test_sequence_processing.py index 009c2250..c583c104 100644 --- a/tests/unit/test_sequence_processing.py +++ b/tests/unit/test_sequence_processing.py @@ -399,6 +399,46 @@ def test_duplication(tmpdir: py.path.local): ) +@pytest.mark.parametrize( + "meters, angles, duplicate", + [ + (2.0, (0, 0), True), + (2.9, (0, 9), True), + (3.1, (0, 0), False), + (2.0, (0, 11), False), + # Without a direction, by distance alone + (2.9, (None, None), True), + (3.1, (None, None), False), + ], +) +def test_duplicate_defaults( + tmpdir: py.path.local, + meters: float, + angles: tuple[float | None, float | None], + duplicate: bool, +): + """ + By default, as in the mobile apps, an image within 3 m of the image before + it, and within 10° of its direction, is a duplicate + """ + lat = 1.0 + meters / 110_574 + assert geo.gps_distance((1.0, 1.0), (lat, 1.0)) == pytest.approx(meters, abs=0.01) + sequence = [ + _make_image_metadata(Path(tmpdir) / "a.jpg", 1.0, 1.0, 1, angle=angles[0]), + _make_image_metadata(Path(tmpdir) / "b.jpg", 1.0, lat, 2, angle=angles[1]), + ] + + metadatas = psp.process_sequence_properties(sequence) + + errors = [m.error for m in metadatas if isinstance(m, types.ErrorMetadata)] + if duplicate: + [error] = errors + assert isinstance(error, exceptions.MapillaryDuplicationError) + assert error.desc["filename"] == str(sequence[1].filename) + else: + assert errors == [] + + def test_interpolation(tmpdir: py.path.local): curdir = tmpdir.mkdir("hello222").mkdir("world333") sequence: T.List[types.Metadata] = [ @@ -864,10 +904,10 @@ def test_split_sequence_by_filesize(tmpdir): ), # s2 _make_image_metadata( - Path(tmpdir) / Path("./b.jpg"), 2.00001, 2.00001, 2, filesize=1 + Path(tmpdir) / Path("./b.jpg"), 2.0001, 2.0001, 2, filesize=1 ), _make_image_metadata( - Path(tmpdir) / Path("./c.jpg"), 2.00002, 2.00002, 2, filesize=1 + Path(tmpdir) / Path("./c.jpg"), 2.0002, 2.0002, 2, filesize=1 ), ] @@ -882,8 +922,8 @@ def test_split_sequence_by_image_count(tmpdir): for i in range(1, max_allowed_images + 1): image = _make_image_metadata( Path(tmpdir) / Path(f"./a{i}.jpg"), - 1 + i * 0.00001, - 1 + i * 0.00001, + 1 + i * 0.0001, + 1 + i * 0.0001, i, filesize=1, ) @@ -900,8 +940,8 @@ def test_split_sequence_by_image_count_split(tmpdir): for i in range(1, max_allowed_images + 2): image = _make_image_metadata( Path(tmpdir) / Path(f"./a{i}.jpg"), - 1 + i * 0.00001, - 1 + i * 0.00001, + 1 + i * 0.0001, + 1 + i * 0.0001, i, filesize=1, ) @@ -917,10 +957,10 @@ def test_split_sequence_by_cutoff_time(tmpdir): _make_image_metadata(Path(tmpdir) / Path("./a.jpg"), 1, 1, 1, filesize=1), # s2 _make_image_metadata( - Path(tmpdir) / Path("./b.jpg"), 1.00001, 1.00001, 600, filesize=1 + Path(tmpdir) / Path("./b.jpg"), 1.0001, 1.0001, 600, filesize=1 ), _make_image_metadata( - Path(tmpdir) / Path("./c.jpg"), 1.00002, 1.00002, 601, filesize=1 + Path(tmpdir) / Path("./c.jpg"), 1.0002, 1.0002, 601, filesize=1 ), ] @@ -933,9 +973,9 @@ def test_split_sequence_no_split(tmpdir): # s1 _make_image_metadata(Path(tmpdir) / Path("./a.jpg"), 1, 1, 1), # s2 - _make_image_metadata(Path(tmpdir) / Path("./b.jpg"), 1.00001, 1.00001, 2), + _make_image_metadata(Path(tmpdir) / Path("./b.jpg"), 1.0001, 1.0001, 2), # s3 - _make_image_metadata(Path(tmpdir) / Path("./c.jpg"), 1.00002, 1.00002, 3), + _make_image_metadata(Path(tmpdir) / Path("./c.jpg"), 1.0002, 1.0002, 3), ] metadatas = psp.process_sequence_properties(sequence)