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

Content

This example shows how to calibrate a sensor.

Boost is only used to generate examples and is not necessary for working with this SDK.

#include <boost/test/unit_test.hpp>
#include <stdio.h>
#include <conio.h>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
BOOST_AUTO_TEST_CASE(calibration) {
puts("Key mapping");
puts("s: capture image of calibration target");
puts("c: perform calibration and exit");
puts("All keys need to be pressed with the command line in the foreground");
// Create a new context
// Create a license object
reme_error_t e = reme_license_authenticate(c, l, "license.txt.sgn");
if (e == REME_ERROR_SUCCESS) {
puts("Now running in commercial mode");
} else {
puts("Failed to authenticate.");
}
// Create a new sensor with default intrinsics
reme_sensor_create(c, "openni", false, &s);
// Use the RGB stream as AUX image type
reme_options_create(c, &o_cfg);
// Switch IR stream on.
reme_options_set(c, o_cfg, "aux_stream.type", "STREAM_COLOR");
// Open sensor
// Create a calibrator using standard settings (A3 chessboard 10x7)
// We visualize two images, the auxilary image and the last detection result
reme_viewer_t viewer;
reme_viewer_create_image(c, "This is ReconstructMeSDK", &viewer);
reme_image_t imgs[2];
reme_image_create(c, &imgs[0]);
reme_image_create(c, &imgs[1]);
reme_viewer_add_image(c, viewer, imgs[0]);
reme_viewer_add_image(c, viewer, imgs[1]);
bool continue_grabbing = true;
while (continue_grabbing && REME_SUCCESS(reme_sensor_grab(c, s))) {
// Prepare image and update content
// Keyboard handling
if (_kbhit()) {
char k = _getch();
switch (k) {
// Key 's' tries to find the calibration target in the current image
case 's': {
reme_calibrator_add_image(c, calib, imgs[0]);
break;
}
// Key 'c' saves the volume content to disk
case 'c' : {
continue_grabbing = false;
break;
}
}
}
// Update the viewer
reme_viewer_update(c, viewer);
} // end of grabbing loop
// Actual calibration step
float accuracy;
if (REME_SUCCESS(reme_calibrator_calibrate(c, calib, &accuracy))) {
printf("Reprojection error: %f pixels \n", accuracy);
// Generate a new sensor config using the new intrinsic values
reme_options_t o, o_intr, o_intr_new;
reme_options_create(c, &o_intr);
reme_options_create(c, &o_intr_new);
// Get the current camera configuration
reme_options_bind_message(c, o, "aux_stream.intrinsics", o_intr);
// Get the result of the calibration
reme_calibrator_bind_intrinsics(c, calib, o_intr_new);
// Copy over
reme_options_copy(c, o_intr_new, o_intr);
// Save new config to file
reme_options_save_to_file(c, o, "calibrated_sensor.txt");
} else {
puts("Calibration failed");
}
// Print all errors
// Make sure to release all memory acquired
}
BOOST_AUTO_TEST_SUITE_END()