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

Content

This example shows how to access images generated by sensor objects. Additionally to ReMe it uses OpenCV to display them for the sake of simplicity of this example.

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

#include <boost/test/unit_test.hpp>
#include <opencv2/opencv.hpp>
#include <stdio.h>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
BOOST_AUTO_TEST_CASE(image) {
// Create a new context that has default options applied
// Create a sensor using a saved data stream
reme_sensor_create(c, "openni;mskinect;file", true, &s);
// Create an image to hold the result
int width, height, nchans;
// Viewer for displaying up to 12 images in parallel
reme_viewer_create_image(c, "Images", &v);
int counter = 0;
while (REME_SUCCESS(reme_sensor_grab(c, s))) {
// Update internal state of images
// Receive the image into our image handle
if (counter % 30 == 0) {
// Derive the correct image format
reme_image_get_info(c, i, &width, &height, &nchans);
// Save image as PNG
char buffer[50];
sprintf(buffer, "image_%i.png", counter);
reme_image_save_to_file(c, i, buffer);
printf("Saved image (%ix%i - %i channels) to %s \n", width, height, nchans, buffer);
}
// Update the viewer
counter += 1;
}
// Print pending errors
// Make sure to release all memory acquired
}
BOOST_AUTO_TEST_CASE(image_external) {
// Create a new context that has default options applied
// Create a sensor using a saved data stream
reme_sensor_create(c, "openni;mskinect;file", true, &s);
// Create an image to hold the result
const void *data;
int width, height, length;
while (REME_SUCCESS(reme_sensor_grab(c, s))) {
// Update internal state of images
// Receive the image into our image handle
// Receive the pointer to the data
reme_image_get_bytes(c, i, &data, &length);
// Derive the correct image format
reme_image_get_info(c, i, &width, &height);
// In C++ we could now feed this to OpenCV for visualization
cv::Mat rgb(height, width, CV_8UC3, (char*)data);
cv::Mat bgr;
cv::cvtColor(rgb, bgr, CV_RGB2BGR);
cv::imshow("RGB", bgr);
cv::waitKey(10);
}
// Print pending errors
// Make sure to release all memory acquired
}
BOOST_AUTO_TEST_SUITE_END()