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

Content

Shows how to use to tilt moter of a Microsoft Kinect for Windows while scanning.

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)
void perform_tilt(reme_context_t c, reme_sensor_t s, reme_options_t o, int angle);
BOOST_AUTO_TEST_CASE(scan_tilt) {
puts("Key mapping");
puts("x: quit scanning");
puts("r: reset volume to empty state");
puts("f: tilt +10 degrees");
puts("b: tilt -10 degrees");
puts("All keys need to be pressed with the command line in the foreground");
// Create a new context
// Compile for OpenCL device using defaults
// Create a new volume
// Create a new sensor
reme_sensor_create(c, "mskinect", true, &s);
// Bind capture options
// Set tilt angle to zero
reme_options_set_int(c, o, "tilt_angle", 0);
// Bind tracking options
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, v, imgs[0]);
reme_viewer_add_image(c, v, imgs[1]);
bool continue_scanning = true;
// After each tilt we skip a couple of frames
int skip_frame_counter = 0;
while (continue_scanning && REME_SUCCESS(reme_sensor_grab(c, s))) {
// Keyboard handling
if (_kbhit()) {
char k = _getch();
switch (k) {
// Key 'r' resets the volume to empty state
case 'r': {
break;
}
// Key 'f' tilt +10 degrees
case 'f': {
perform_tilt(c, s, o, 10);
break;
}
// Key 'b' tilt -10 degrees
case 'b': {
perform_tilt(c, s, o, -10);
skip_frame_counter = 10;
break;
}
case 'x': {
continue_scanning = false;
break;
}
}
}
// Prepare image and depth data
if (skip_frame_counter == 0) {
}
} else {
skip_frame_counter -= 1;
}
// Update the viewer
reme_viewer_update(c, viewer);
}
// Print pending errors
// Make sure to release all memory acquired
}
// Perform the tilt and compensate for it.
// After tilting a couple of frames should be skipped to compensate for bad data.
void perform_tilt(reme_context_t c, reme_sensor_t s, reme_options_t o, int angle) {
// Read current angle
int prev_angle;
reme_options_get_int(c, o, "tilt_angle", &prev_angle);
// Apply tilt
reme_options_set_int(c, o, "tilt_angle", prev_angle + angle);
// Read tilt angle again to determine to determine actual movement
int new_angle;
reme_options_get_int(c, o, "tilt_angle", &new_angle);
// Compensate for tilt in sensor position
float pos[16];
reme_transform_compensate_tilt(c, pos, new_angle - prev_angle, pos);
}
BOOST_AUTO_TEST_SUITE_END()