Skip to content

Commit 5470a6f

Browse files
Expand the theia doc (#386)
* Expand the Theia doc * More Theia tweaks
1 parent 406b5f1 commit 5470a6f

File tree

1 file changed

+115
-21
lines changed

1 file changed

+115
-21
lines changed

localization/sparse_mapping/theia_map.md

+115-21
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
Theia (https://github.com/sweeneychris/TheiaSfM) is a package for
44
global structure-from-motion (SfM). It may be faster and require less
5-
user effort than the method used in Astrobee which consists of
6-
creating submaps using incremental SfM on sequences of images that
7-
overlap with their immediate neighbors, followed by merging the
8-
submaps. Theia uses "cascade matching" to handle non-sequential image
9-
acquisitions.
5+
user effort than the method used in Astrobee (see \ref map_building)
6+
which consists of creating submaps using incremental SfM on sequences
7+
of images that overlap with their immediate neighbors, followed by
8+
merging the submaps. Theia uses "cascade matching" to handle
9+
non-sequential image acquisitions.
1010

1111
The Theia approach was tested on about 700 images acquired at
1212
different times and it did well. It is currently studied as an
1313
alternative to Astrobee's approach.
1414

1515
# Install Theia's prerequisites
1616

17+
It is suggested to use ``conda`` to install Theia's dependencies. The
18+
conda toolset does not require root access and creates a set of
19+
consistent libraries at a custom location in your home directory,
20+
which are largely independent of your particular Linux system.
21+
1722
Fetch and install ``conda`` from:
1823

1924
https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
@@ -34,7 +39,7 @@ Run the following command to install some packages and GCC 11:
3439
ceres-solver=1.14.0=h0948850_10
3540

3641
The Ceres package can be quite particular about the version of Eigen
37-
it uses, and some versions of Ceres are not built with suitesparse
42+
it uses, and some versions of Ceres are not built with ``suitesparse``,
3843
which is a sparse solver that is needed for best performance, so some
3944
care is needed with choosing the versions of the packages.
4045

@@ -53,42 +58,122 @@ view_reconstruction. That visualizer logic is not easy to compile
5358
and is not needed.
5459

5560
Run ``which cmake`` to ensure its version in the ``theia`` environemnt
56-
installed earlier is used. Otherwise run again ``conda activate
57-
theia``. Do:
61+
installed earlier is used. Otherwise run again:
62+
63+
conda activate theia
64+
65+
Do:
5866

5967
mkdir build
6068
cd build
6169
cmake ..
6270
make -j 20
6371

6472
This will create the executables ``build_reconstruction`` and
65-
``export_to_nvm_file`` in the ``bin`` subdirectory of ``build``. That
66-
directory needs to be added to the PATH.
73+
``export_to_nvm_file`` in the ``bin`` subdirectory of ``build``.
6774

68-
# Run the Astrobee wrapper around the Theia tools
75+
# Hide the conda environment
6976

7077
The conda environment set up earlier will confuse the lookup the
71-
dependencies for the Astrobee libraries. Hence the lines ``conda`` added
72-
to one's ``.bashrc`` should be removed, the bash shell restarted, and
73-
one should ensure that the ``env`` command has no mentions of conda.
78+
dependencies for the Astrobee libraries. Hence remove the block of
79+
lines starting and ending with ``conda initialize`` which conda added
80+
to your ~/.bashrc, then close and reopen your terminal. Ensure that
81+
the ``env`` command shows no mention of conda.
7482

75-
Set the environment. The following lines should be adjusted as needed,
76-
especially the robot name:
83+
# Set up the environment for Theia and Astrobee
7784

78-
export ASTROBEE_SOURCE_PATH=$HOME/projects/astrobee/src
79-
source $ASTROBEE_SOURCE_PATH/../devel/setup.bash
85+
Add the Theia tools to your path as:
86+
87+
export PATH=/path/to/TheiaSfM/build/bin:$PATH
88+
89+
Set up the environment for Astrobee, including the robot name. These
90+
should be adjusted as needed:
91+
92+
export ASTROBEE_BUILD_PATH=$HOME/astrobee
93+
export ASTROBEE_SOURCE_PATH=$ASTROBEE_BUILD_PATH/src
94+
source $ASTROBEE_BUILD_PATH/devel/setup.bash
8095
export ASTROBEE_RESOURCE_DIR=$ASTROBEE_SOURCE_PATH/astrobee/resources
8196
export ASTROBEE_CONFIG_DIR=$ASTROBEE_SOURCE_PATH/astrobee/config
8297
export ASTROBEE_WORLD=iss
8398
export ASTROBEE_ROBOT=bumble
8499

100+
Add some Astrobee tools to the path as well:
101+
102+
export PATH=$ASTROBEE_BUILD_PATH/devel/lib/sparse_mapping:$PATH
103+
104+
Please note that if the robot name, as specified in
105+
``ASTROBEE_ROBOT``, is incorrect, you will get poor results.
106+
107+
# Prepare the data
108+
109+
The data preparation is the same as used with the usual Astrobee
110+
map-building software documented in \ref map_building. To summarize,
111+
the steps are as follows.
112+
113+
Extract the data from the bag:
114+
115+
$ASTROBEE_BUILD_PATH/devel/lib/localization_node/extract_image_bag \
116+
bagfile.bag -use_timestamp_as_image_name \
117+
-image_topic /hw/cam_nav -output_directory image_dir
118+
119+
If the images were recorded with the image sampler, the nav_cam image
120+
topic needs to be changed to:
121+
122+
/mgt/img_sampler/nav_cam/image_record
123+
124+
The ``-use_timestamp_as_image_name`` option is not strictly necessary,
125+
but it is helpful if a lot of datasets needs to be processed
126+
jointly. With it, the image filename is the timestamp (in
127+
double-precision seconds since epoch), which provides for a rather
128+
unique name, as compared to using the image index in the bag without
129+
that option.
130+
131+
Select a subset of the images:
132+
133+
select_images -density_factor 1.4 image_dir/*.jpg
134+
135+
This will delete a lot of similar images from that directory. This is
136+
not a foolproof process, and sometimes too many images are deleted but
137+
most of the time too many are left. It is suggested to open the
138+
remaining images with ``eog`` as:
139+
140+
eog image_dir/*.jpg
141+
142+
and use the ``Delete`` key to remove redundant ones. The
143+
``nvm_visualize`` tool (see \ref sparsemapping) can be used exactly as
144+
``eog``, and it has the advantage that it echoes the current image
145+
name in the terminal, which can be useful in some occasions.
146+
147+
A good rule of thumb is for each image to have a 4/5 overlap with the
148+
next one. Too much or too little overlap will cause Theia to fail.
149+
150+
It is suggested to avoid images with pure camera rotation, or at least
151+
to have in the mix additional images of the same environemnt without
152+
such rotations.
153+
154+
Put the selected images in a list:
155+
156+
ls image_dir/*jpg > image_list.txt
157+
158+
# Run the Astrobee wrapper around the Theia tools
159+
85160
python $ASTROBEE_SOURCE_PATH/localization/sparse_mapping/tools/build_theia_map.py \
86161
--output_map theia.map --work_dir theia_work --image_list image_list.txt
87162

88163
This will take care of preparing everything Theia needs, will run it,
89-
and will export the resulting map to Astrobee's expected format. This
90-
map will need to be registered and visualized as described in other
91-
documentation. The work directory can be deleted later.
164+
and will export the resulting map to Astrobee's expected format.
165+
166+
It is suggested to first run this tool on a small subset of the data,
167+
perhaps made up of 10 images. A 700-image dataset may take perhaps 6
168+
hours on a machine with a couple of dozen cores and use up perhaps 20
169+
GB of RAM.
170+
171+
The obtained map can be examined with ``nvm_visualize``, as described
172+
in \ref sparsemapping.
173+
174+
The work directory can be deleted later.
175+
176+
# Command line options
92177

93178
This tool has the following command-line options:
94179

@@ -106,6 +191,15 @@ This tool has the following command-line options:
106191
imported from Theia. This is for testing purposes.
107192
--help: Show this help message and exit.
108193

194+
# Next steps
195+
196+
This map will need to be registered and visualized as described in
197+
\ref map_building.
198+
199+
That page also has information for how the map can be rebuilt to use
200+
BRISK features, and how it can be validated for localization by
201+
playing a bag against it.
202+
109203
# Auxiliary import_map tool
110204

111205
This tool is used to import a map from the NVM format, which Theia

0 commit comments

Comments
 (0)