Shows how to use an existing sensor with ReconstructMe. This allows you to share a sensor resource between your application and ReconstructMe.I n this example we will connect to a sensor using OpenNI and use share its data with ReconstructMe. This example focuses on depth maps. Similar things can be done for auxilary (color) images.
Boost is only used to generate examples and is not necessary for working with this SDK.
#include <boost/test/unit_test.hpp>
#include <OpenNI.h>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
#define OPENNI_ASSERT(expr) \
if (!(expr) == openni::STATUS_OK) \
throw std::runtime_error(openni::OpenNI::getExtendedError());
BOOST_AUTO_TEST_CASE(sensor_external) {
openni::Device ni_dev;
openni::VideoStream ni_depth;
openni::VideoFrameRef ni_depth_frame;
OPENNI_ASSERT(openni::OpenNI::initialize());
OPENNI_ASSERT(ni_dev.open(openni::ANY_DEVICE));
OPENNI_ASSERT(ni_depth.create(ni_dev, openni::SENSOR_DEPTH));
OPENNI_ASSERT(ni_depth.start());
int image_width = ni_depth.getVideoMode().getResolutionX();
int image_height = ni_depth.getVideoMode().getResolutionY();
bool viewer_done = false;
while (!viewer_done)
{
int index;
openni::VideoStream* streams[] = {&ni_depth};
OPENNI_ASSERT(openni::OpenNI::waitForAnyStream(streams, 1, &index, 500));
OPENNI_ASSERT(ni_depth.readFrame(&ni_depth_frame));
const unsigned short *sensor_pixel = (const unsigned short *)ni_depth_frame.getData();
void *virtual_pixel;
int nbytes;
memcpy(virtual_pixel, sensor_pixel, image_width * image_height * sizeof(unsigned short));
}
}
}
BOOST_AUTO_TEST_SUITE_END()