Visual Servoing Platform  version 3.2.0 under development (2018-10-15)
tutorial-grabber-realsense.cpp
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/sensor/vpRealSense.h>
#include <visp3/sensor/vpRealSense2.h>
int main()
{
#if defined(VISP_HAVE_REALSENSE) || defined(VISP_HAVE_REALSENSE2)
try {
#ifdef VISP_HAVE_REALSENSE
unsigned int width = 640, height = 480;
g.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(width, height, rs::format::rgba8, 60));
g.open();
#else
rs2::config config;
config.disable_stream(RS2_STREAM_DEPTH);
config.disable_stream(RS2_STREAM_INFRARED);
config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_RGBA8, 30);
g.open(config);
#endif
g.acquire(I);
std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#elif defined(VISP_HAVE_GDI)
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
while (1) {
double t = vpTime::measureTimeMs();
g.acquire(I);
vpDisplay::displayText(I, 10, 10, "A click to quit", vpColor::red);
std::stringstream ss;
ss << "Acquisition time: " << vpTime::measureTimeMs() - t << " ms";
vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);
if (vpDisplay::getClick(I, false))
break;
}
} catch (const vpException &e) {
std::cout << "Catch an exception: " << e << std::endl;
}
#else
std::cout << "Install librealsense, configure and build ViSP again to use this example" << std::endl;
#endif
}