SDK Usage Examples
The SDK ships with example code that shows how the API is used. The examples are small command line applications, one for each part of the API, in C++ and in Python. They run on example data that is distributed separately from the SDK, and have options for trying out the settings of the API on that data. The C++ and Python versions take the same options and print the same kind of results.
Where the examples are
<sdk>/
├── examples/
│ ├── example_config.json SDK configuration for the config_from_json example
│ ├── viewer/ The page that the --visualize option writes
│ ├── cpp/ C++ examples. cpp/README.md describes how to build and run them
│ │ └── common/ Code shared by the C++ examples
│ └── python/ Python examples. python/README.md describes how to run them
│ └── common/ Code shared by the Python examples
└── data/
└── example/ Example data, after unpacking raptor-example-data-<version>.tar.gz
The SDK calls are in the example files themselves. The code in common/ reads the example data,
reads and writes image files, adds errors to poses, writes the visualization and handles the
command line options that the examples have in common.
What the examples show
| Example | Shows | Described in |
|---|---|---|
sdk_info | SDK version, machine fingerprint and license validation | License Management Guide |
config_from_json | Reading raptor::Config from a JSON file | Loading Configuration from JSON |
render_map | renderMap() and renderMapCoverage() | Map Inspection and Queries |
query_map_intersection | queryMapIntersection() for a position, a ray and image pixels, with geodetic and ECEF types | Map intersection queries |
pose_estimator | raptor::guide::PoseEstimator, with a prior covariance from search ranges | PoseEstimator Integration Guide, Prior Pose Covariance |
attitude_tracker | raptor::sync::AttitudeTracker | AttitudeTracker Integration Guide |
The C++ applications are named after the part of the SDK they use, for example
raptor.guide.examples.pose_estimator. The Python scripts are named after the examples, for
example pose_estimator.py.
Example data
All examples use the same example data: a 3D map of Grant Park in Chicago, and a synthetic image sequence of a UAV flying over the park, with the exact pose and field of view of every image. The images are rendered from a 3D model through a perfect pinhole camera, from exact poses and with perfect timestamps. The sequence is not a recording from a real UAV, and is only meant for trying out the functionality of the SDK.
An exact pose leaves nothing to correct, so the examples add an error of their own to the poses before passing them to the SDK, and report how far the results are from the exact poses.
The data is distributed as raptor-example-data-<version>.tar.gz, which unpacks to
data/example. Unpacked in the SDK directory, it ends up next to the geo resources in
data/resources. Pass the directory to the examples with --data. The README.md in the
directory describes the data and the contents of its poses.csv in detail.
Building and running
The C++ examples are built with CMake against the installed SDK, as described in
examples/cpp/README.md. The Python examples need the raptor wheel and Pillow, as described in
examples/python/README.md. Every example takes the example data directory and a license file,
and lists its options with --help:
raptor.guide.examples.pose_estimator --data <sdk>/data/example --license <license file>
python pose_estimator.py --data <sdk>/data/example --license <license file>
Options
These options are shared by most of the examples:
| Option | Meaning |
|---|---|
--data | The example data directory |
--license | The Raptor license file |
--geo-resources | The geo resource directory, if the SDK does not find it on its own |
--first-frame, --frame-count, --frame-step | The images to process |
--crs | Pass poses to the SDK as geodetic or ecef |
--height-system | Pass the altitudes of geodetic poses above the ellipsoid, egm2008 or egm96 |
--image-type | Pass images to the SDK as gray8, rgb8 or rgba8 |
--axes | The axes of the pose errors and the search ranges. ned, the default, is north (x), east (y) and down (z) at the camera position. camera is forward (x), right (y) and down (z) in the image |
--error-x, --error-y, --error-z | Position error added to the poses, in meters along the axes chosen with --axes |
--error-yaw, --error-pitch, --error-roll | Attitude error added to the poses, in degrees. With ned, it is added to the yaw, pitch and roll of the camera relative to north, east and down. With camera, it turns the camera about its down, right and forward axes |
--visualize | Write a page that shows the camera images on the map to a directory, see Visualization |
--log-level, --detail-stage1, --max-cpus, ... | Settings of raptor::Config |
The attitude_tracker example only takes attitude errors, since the tracker needs an accurate
position. The examples print the errors of the poses together with their components along the
axes chosen with --axes, and end with the mean time per image that the SDK took and the frame
rate it allows. The pose_tracker example prints the time of the initialization on its own, and
the mean over the frames passed to update().
The pose_estimator and pose_tracker examples search for the pose within ranges around the
prior pose, along the axes chosen with --axes:
| Option | Meaning |
|---|---|
--search-position | How far from the prior position to search, in meters. One range for all three axes, or one for each axis as x,y,z |
--search-attitude | How far from the prior attitude to search, in degrees. One range for all three axes, or one for each as yaw,pitch,roll |
--search-position 10,10,0 searches 10 meters to the north, south, east and west of the prior
position, and not at all vertically. The uncertainty of a navigation system is usually known
along north, east and down, which is why that is the default. The example converts the ranges
to a prior covariance as described in Prior Pose Covariance.
Visualization
With --visualize <directory>, the pose_estimator, attitude_tracker and pose_tracker
examples write a page to the directory that shows how well the camera images fit the map. Open
index.html in the directory with a web browser. For every image, the page shows the map seen
from 80 meters behind the true camera, with the camera image laid onto the map as seen from a
pose: the prior pose, or the pose that the SDK returned. The closer a pose is to the true pose,
the better the image lines up with the map. Buttons, or the number keys, switch between the poses
and the map alone, and the arrow keys step between the images. The page can be opened while the
example runs, and shows the images written so far when it is reloaded.
Things to try
... stands for the --data and --license options.
# A pose error too large to correct without searching, and the search that corrects it
pose_estimator ... --error-y 30 --error-yaw 4
pose_estimator ... --error-y 30 --error-yaw 4 --search-position 40 --search-attitude 6
# The map seen from the same inaccurate pose, to compare with the camera image
render_map ... --error-y 30 --error-yaw 4 --output <directory>
# The same search with less of it where the error is small: 40 m horizontally and 5 m
# vertically, 6 degrees in heading and 3 degrees in pitch and roll. Compare the time it takes
pose_estimator ... --error-y 30 --error-yaw 4 --search-position 40,40,5 --search-attitude 6,3,3
# Errors and search ranges along the camera axes instead: an error to the right in the image
# and in yaw, and a search that is mostly to the sides and in yaw
pose_estimator ... --axes camera --error-y 30 --error-yaw 4 --search-position 5,40,5 --search-attitude 6,1,1
# A position error in the horizontal plane, and a search in that plane only
pose_estimator ... --error-x 20 --error-y 20 --error-yaw 0 --search-position 40,40,0
# The prior and the refined poses on the map, in a page in the directory
pose_estimator ... --error-y 30 --error-yaw 4 --search-position 40 --search-attitude 6 --visualize <directory>
# The same poses with altitudes above the EGM2008 and the EGM96 geoid. Here the geoids are
# about 34 m below the ellipsoid and 4 cm apart, as the altitudes of the refined poses show
pose_estimator ... --height-system egm2008
pose_estimator ... --height-system egm96
# ECEF poses and color images instead of geodetic poses and grayscale images
pose_estimator ... --crs ecef --image-type rgb8
# An attitude tracker that also has to correct the focal length
attitude_tracker ... --error-yaw 3 --error-focal-length 2
# Altitudes in feet above the EGM2008 geoid
query_map_intersection ... --height-system egm2008 --height-unit foot