ReconstructMe SDK  2.6.43-0
Real-time 3D reconstruction engine
example_reconstructmesdk_color_tracking.cpp

Content

This example shows how to enable color tracking for robust camera motion estimation.

#include <boost/test/unit_test.hpp>
#include <stdio.h>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
BOOST_AUTO_TEST_CASE(color_tracking) {
// Create a new context
// Create a license object
reme_error_t e = reme_license_authenticate(c, l, "license.txt.sgn");
// Create options
// Create a new sensor.
reme_sensor_create(c, "openni;mskinect;file", true, &s);
// To perform color tracking color and depth streams need to be aligned geomtrically and in time.
reme_options_set_bool(c, o, "enable_align_viewpoints", true);
reme_options_set_bool(c, o, "enable_sync_viewpoints", true);
// A good idea: let the autoexposure ajdust the camera exposure for the first
// few frames. Then when we start scanning lock-in the exposure.
reme_options_set_real(c, ocap, "exposure_time", 75.f);
reme_options_set_bool(c, ocap, "auto_exposure", true);
// To enable color tracking we need to increase the color weight term to
// a value greater than zero. The higher the value to more importance is assigned to
// matching color terms.
reme_options_set_int(c, o, "camera_tracking.local_search.maximum_iterations", 30);
reme_options_set_int(c, o, "camera_tracking.local_search.pyramid_levels", 3);
reme_options_set_real(c, o, "camera_tracking.local_search.color_weight", 0.7f);
reme_options_set_bool(c, o, "camera_tracking.local_search.skip_finest_pyramid_level", true);
// Although not needed for color tracking, we enable integration of colors to
// get a colorized result.
reme_options_set_bool(c, o, "data_integration.use_colors", true);
// Create a new volume
// Position sensor outside of volume
reme_options_set(c, o, "shade_mode", "SHADE_COLORS");
reme_viewer_t viewer;
reme_viewer_create_image(c, "This is ReconstructMe SDK", &viewer);
reme_image_t volume, aux;
reme_image_create(c, &volume);
reme_viewer_add_image(c, viewer, aux);
reme_viewer_add_image(c, viewer, volume);
// Perform reconstruction until viewer is closed. The first 30 frames are
// skipped as cameras tend to vary the exposure of the color stream drastically
// on start-up.
int skip_images = 30;
bool is_closed = false;
while (!is_closed && REME_SUCCESS(reme_sensor_grab(c, s))) {
--skip_images;
if (skip_images == 0) {
reme_options_set_bool(c, ocap, "auto_exposure", false);
}
else if (skip_images < 0) {
}
}
reme_viewer_update(c, viewer);
reme_viewer_is_closed(c, viewer, &is_closed);
}
// View volume content
reme_viewer_t viewer2;
reme_viewer_create_volume(c, v, s, "This is ReconstructMe SDK", &viewer2);
reme_viewer_wait(c, viewer2);
// Shutdown
}
BOOST_AUTO_TEST_SUITE_END()