ReconstructMe SDK  1.1.739-75658
Real-time 3D reconstruction engine
 All Classes Files Functions Typedefs Enumerations Enumerator Groups Pages
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_license_authenticate(c, l, "license.txt.sgn");
// Create a new sensor with default intrinsics
reme_sensor_create(c, "mskinect", false, &s);
// We by either enabling IR stream or RGB (default) for REME_IMAGE_AUX we
// can choose the camera to calibrate.
reme_options_create(c, &o_cfg);
// Switch IR stream on.
reme_options_set(c, o_cfg, "enable_rgb", "false");
reme_options_set(c, o_cfg, "enable_ir", "true");
reme_options_set(c, o_cfg, "enable_ir_projector", "false");
// Increase contrast of the image. We've found that good values are
// - Kinect for Windows: around 40 with projector turned off
// - Kinect for XBox, Xtion: around 4 with projector covered
reme_options_set(c, o_cfg, "ir_alpha", "40");
// 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, "depth_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);
// Reset the flags we pulled in before
reme_options_set(c, o_cfg, "enable_rgb", "true");
reme_options_set(c, o_cfg, "enable_ir", "false");
reme_options_set(c, o_cfg, "enable_ir_projector", "true");
// Save new config to file
reme_options_save_to_file(c, o, "calibrated_sensor.txt");
} else{
puts("Calibration failed");
}
// Make sure to release all memory acquired
}
BOOST_AUTO_TEST_SUITE_END()