Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyframe Selection: Add support for SfMData files as inputs and outputs #1406

Merged
merged 12 commits into from
Apr 26, 2023

Conversation

cbentejac
Copy link
Contributor

@cbentejac cbentejac commented Apr 7, 2023

Description

This PR builds on top of #1343 and:

  1. Adds the support of SfMData files as an input;
  2. Outputs two SfMData files: one that contains the selected keyframes, and one that contains all the frames that failed to be selected as keyframes.

SfMData files can now be provided as inputs for both the regular and smart keyframe selection, and the selection methods remain oblivious to the type of input they are given. Rigs are not supported with SfMData files as inputs.

Once the keyframes have been written, two SfMData files are written, respectively with the keyframes' information and the rejected frames' information. Depending on the type of input, the output SfMData files are written with the following specifications:

  • If the input is an image sequence (or a rig of image sequences), both the keyframes' and frames' SfMData files will be written, with a full rig support;
  • If the input is a video (or a rig of videos), only the keyframes SfMData file will be written, with a full rig support. Since the frames' SfMData file requires the paths of all the rejected frames to be filled and the only available path (beside the keyframes') is the input video's, it is simply ignored;
  • If the input is an SfMData file, both the keyframes' and frames' SfMData files will be written, with no rig support.

While rigs are not supported with SfMData files as inputs, it is possible to provide an SfMData file that contains several different image sequences. If that occurs, the views will be ordered according to their frame IDs and their intrinsics' serial number, put back-to-back (e.g. for two sequences with 3 frames each in the same SfMData file, the views will be sorted as "seq1#id0, seq1#id1, seq1#id2, seq2#id0, seq2#id1, seq2#id2"), and then processed by the selection methods as a single sequence.

Additionally, the dataio module has been reformatted to use 4-space indentations everywhere.

The corresponding Meshroom pull request can be found here: alicevision/Meshroom#1967

Features list

  • Reformat the dataio module;
  • Remove the old support for JSON files from the ImageFeed in the dataio module;
  • Add a specific feeder for SfMData files in the dataio module;
  • Support SfMData files as inputs for the keyframe selection;
  • Write one to two SfMData files (depending on the input's type) in addition to the selected keyframes.

Implementation remarks

  • A new feed, SfMDataFeed, dedicated to SfMData files has been added to dataio's FeedProvider to read and provide images from any SfMData files. It replaces the support for .json files that was provided by the ImageFeed feed.
  • The partial and outdated support for SfMData files (with a .json extension) that was available in the ImageFeed feed has been completely removed. ImageFeed still supports all types of images as well as .txt files containing a list of paths to images.
  • The sensor database, which was provided but never used until now, is loaded and parsed to retrieve sensor-related information during the intrinsics' creation.
  • The rig support for the input SfMData files is not covered by this pull request, and should be added later in a dedicated one.

This commit only modifies the syntax of the dataio module and does not
change its content in any way. The hpp and cpp files have been clang-
formatted to respect the 4-spaces indentation that can be found in other
modules (in the "keyframe" module, primarily), and some functions'
prototypes have been re-aligned accordingly.
The ImageFeed accepted as an input:
- a text file containing a list of images' paths
- input images
- a directory
- a JSON file (SfMData)

The support for the JSON file is removed from the ImageFeed. It will
later be added to a specific feeder.
The SfMDataFeed supports SfMData files, which can be .sfm, .json or .abc.
The provided input file is parsed, and the views are ordered according
to their frame ID.
The keyframe selection now supports an SfMData file as the input, and
outputs two SfMData files:
- one that contains all the selected keyframes
- one that contains all the frames that were not selected as keyframes
The "selectedFrames" vector is filled with 0s and 1s depending on whether
the frame with the ID corresponding to the position within the vector has
been selected as a keyframe or not.

It was filled with the smart method, but not with the regular one. As it
will be needed later on and is not costly, it should also be filled for
the regular selection method.
…file

This commit adds a new method that writes two output SfMData files (one
containing the keyframes, the other containing all the frames that were not
selected) when the input file is an SfMData file.

Once all the selected keyframes have been written on disk, the input
SfMData file is loaded (outside of the feed) and its views and intrinsics
are extracted to be written in their corresponding output SfMData file.
No information written is these files is built from scratch.

Rigs are currently not supported and therefore ignored when writing the
output files.

If the input is a video or a sequence of images, no SfMData file is written
for now.
Prior to this commit, views were ordered based solely on their frame ID.
If the inpput SfMData only contains one sequence, this works perfectly
fine. However, in case of a rig or several sequences dropped one after
the other, there might be some identical frame IDs which would affect the
entire sorting order: the sequences would be mixed together instead of
being sorted back-to-back.

For example, if there are two sequences with identical frame IDs, the
sorting order will be "seq1#id0, seq2#id0, seq1#id1, seq2#id1, seq1#id2,
seq2#id2" instead of "seq1#id0, seq1#id1, seq1#id2, seq2#id0, seq2#id1,
seq2#id2".

This commit sorts views with different intrinsics' serial numbers
separately based on their frame IDs, and then concatenates all the sorted
views together.
…xists

The database, if available, will later be used to try to determine the
intrinsics of input videos or image sequences.
…umber

The ordering of the views when writing the output SfMData files should
be identical to the one used in the SfMDataFeed. Otherwise, the views
written in the output files will not reflect the keyframes that were saved
on disk.
SfMData files are written as outputs for all types of inputs, with the
following specifications:
- for an input SfMData file, both the keyframes and frames SfMData files
will be written; rigs are not supported
- for an input sequence (or several) of images, both the keyframes and
frames SfMData files will be written; rigs are supported and will be
written in the output SfMData files
- for an input video, only the keyframes SfMData file will be written,
no frames SfMData file will be output; rigs are supported and will be
written in the keyframes SfMData files
Following the addition of the SfMData files as outputs in the command line,
the version needs to be updated.
@mugulmd mugulmd merged commit be2bb06 into develop Apr 26, 2023
@mugulmd mugulmd deleted the dev/sfmDataKeyframeSelection branch April 26, 2023 11:04
@cbentejac cbentejac added this to the 3.1.0 milestone Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants