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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
11 changes: 9 additions & 2 deletions docs/command_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) |
Expand Down Expand Up @@ -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. |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions mapillary_tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions tests/integration/test_video_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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:
Expand Down
60 changes: 50 additions & 10 deletions tests/unit/test_sequence_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down Expand Up @@ -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
),
]

Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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
),
]

Expand All @@ -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)
Expand Down
Loading