Repository navigation
Conversation
The capture time prefers the GPS time, which usually has no subseconds, so images taken within the same second tie and were ordered by filename. OpenCamera names the second one "IMG_... (1).jpg", which sorts first, so each such pair was reversed in the sequence. Keep the EXIF capture time (with subseconds) on ImageMetadata and use it as the second sort key, before the filename. Fixes mapillary#677
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #677.
Problem
ExifRead.extract_capture_time()prefers the GPS date/time, which usually has no subseconds. When two images are taken within the same second, they get the same capture time, andImageMetadata.sort_key()breaks the tie by filename. OpenCamera names the second shot of a secondIMG_..._170431 (1).jpg, which sorts beforeIMG_..._170431.jpg(space <.). Every such pair is put in reverse order._interpolate_subsecs_for_sortingthen spreads the times in that wrong order, so the uploaded sequence steps back and forth, as in the issue.Change
As suggested in #677, images are now sorted by (capture time, EXIF time with subseconds, filename):
ImageMetadatagets anexif_timefield: the EXIFDateTimeOriginal/SubSecTimeOriginal(or theDateTimeDigitizedfallback) as Unix time. It is only used insort_key(). It is not aMAP*field, so it isn't written to the description file or EXIF, and the description schema is unchanged.ImageEXIFExtractorfills it in. Exiftool-based extraction goes through the same extractor.extract_exif_datetime()was already implemented by all three readers, and it is now declared onExifReadABC.math.infin that slot, so the key stays comparable and the order falls back to the filename as before.How I found it
I went through the open sequence/ordering issues and reproduced #677 on current
main(0.15.1) with seven synthetic JPEGs written with piexif in the OpenCamera pattern. Each image has whole-second GPS times,SubSecTimeOriginalset, and latitude increasing in capture order. These are themapillary_tools processresults frommapillary_image_description.json:IMG_20231115_170430.jpg…_04_30_000…_04_30_000IMG_20231115_170431.jpg…_04_31_500…_04_31_000IMG_20231115_170431 (1).jpg…_04_31_000…_04_31_500IMG_20231115_170432.jpg…_04_32_000…_04_32_000Before the change, the latitudes in output order went 52.50000, 52.50006, 52.50003, 52.50009, …. After it, they increase monotonically. The 170433 pair behaved the same way.
Where this can show up in practice (my estimate)
Phone camera apps that shoot faster than one frame per second with GPS on, such as OpenCamera with a short interval or burst mode. Other cameras whose GPS timestamps are whole seconds but whose filenames don't sort in capture order are affected too. Every same-second pair is reversed in the uploaded sequence.
Test plan
test_sequences_sorted_by_exif_time_within_same_timeintests/unit/test_sequence_processing.py. It fails without thesort_key()change and passes with it.pytest tests/unit: 1645 passed, 33 skipped (macOS, Python 3.11).ruff check mapillary_tools,ruff format --check mapillary_tools testsandmypy mapillary_tools tests/cliare clean.