This example shows how to retrieve data from a RealSense RGB-D sensor.
#include <iostream>
#include <visp3/sensor/vpRealSense.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpMutex.h>
#include <visp3/core/vpThread.h>
#if defined(VISP_HAVE_REALSENSE) && defined(VISP_HAVE_CPP11_COMPATIBILITY)
#if( ! defined(__APPLE__) && ! defined(__MACH__) ) // Not OSX
# if (defined(VISP_HAVE_PTHREAD) || defined(_WIN32)) // Threading available
# define USE_THREAD
# endif
#endif
#ifdef VISP_HAVE_PCL
# include <pcl/visualization/cloud_viewer.h>
# include <pcl/visualization/pcl_visualizer.h>
#endif
#ifdef VISP_HAVE_PCL
#ifdef USE_THREAD
typedef enum {
capture_waiting,
capture_started,
capture_stopped
} t_CaptureState;
t_CaptureState s_capture_state = capture_waiting;
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_ = *((pcl::PointCloud<pcl::PointXYZRGB>::Ptr *) args);
pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(pointcloud_);
viewer->setBackgroundColor (0, 0, 0);
viewer->addCoordinateSystem (1.0);
viewer->initCameraParameters ();
viewer->setPosition(640+80, 480+80);
viewer->setCameraPosition(0,0,-0.5, 0,-1,0);
viewer->setSize(640, 480);
t_CaptureState capture_state_;
do {
capture_state_ = s_capture_state;
if (capture_state_ == capture_started) {
static bool update = false;
if (! update) {
viewer->addPointCloud<pcl::PointXYZRGB> (pointcloud_, rgb, "sample cloud");
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
update = true;
}
else {
viewer->updatePointCloud<pcl::PointXYZRGB> (pointcloud_, rgb, "sample cloud");
}
viewer->spinOnce (10);
}
} while(capture_state_ != capture_stopped);
std::cout << "End of point cloud display thread" << std::endl;
return 0;
}
#endif
#endif
#endif
int main()
{
#if defined(VISP_HAVE_REALSENSE) && defined(VISP_HAVE_CPP11_COMPATIBILITY)
try {
std::cout <<
"Extrinsics cMd: \n" << rs.
getTransformation(rs::stream::color, rs::stream::depth) << std::endl;
std::cout <<
"Extrinsics dMc: \n" << rs.
getTransformation(rs::stream::depth, rs::stream::color) << std::endl;
std::cout <<
"Extrinsics cMi: \n" << rs.
getTransformation(rs::stream::color, rs::stream::infrared) << std::endl;
std::cout <<
"Extrinsics dMi: \n" << rs.
getTransformation(rs::stream::depth, rs::stream::infrared) << std::endl;
#ifdef VISP_HAVE_PCL
pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud(new pcl::PointCloud<pcl::PointXYZRGB>);
#ifdef USE_THREAD
#else
pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(pointcloud);
viewer->setBackgroundColor (0, 0, 0);
viewer->addCoordinateSystem (1.0);
viewer->initCameraParameters ();
viewer->setCameraPosition(0,0,-0.5, 0,-1,0);
#endif
#else
std::vector<vpColVector> pointcloud;
#endif
#if defined(VISP_HAVE_X11)
vpDisplayX dd(depth_display, 10, (
int) color.getHeight()+80,
"Depth image");
#elif defined(VISP_HAVE_GDI)
vpDisplayGDI dd(depth_display, 10, color.getHeight()+80,
"Depth image");
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
while(1) {
rs.
acquire(color, infrared, depth, pointcloud);
#ifdef VISP_HAVE_PCL
#ifdef USE_THREAD
{
s_capture_state = capture_started;
}
#else
static bool update = false;
if (! update) {
viewer->addPointCloud<pcl::PointXYZRGB> (pointcloud, rgb, "sample cloud");
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud");
viewer->setPosition(color.getWidth()+80, color.getHeight()+80);
update = true;
}
else {
viewer->updatePointCloud<pcl::PointXYZRGB> (pointcloud, rgb, "sample cloud");
}
viewer->spinOnce (10);
#endif
#endif
break;
}
}
std::cout << "RealSense sensor characteristics: \n" << rs << std::endl;
#ifdef VISP_HAVE_PCL
#ifdef USE_THREAD
{
s_capture_state = capture_stopped;
}
#endif
#endif
}
}
catch(const rs::error & e) {
std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "): " << e.what() << std::endl;
}
catch(const std::exception & e) {
std::cerr << e.what() << std::endl;
}
#elif !defined(VISP_HAVE_REALSENSE)
std::cout << "Install RealSense SDK to make this test working" << std::endl;
#elif !defined(VISP_HAVE_CPP11_COMPATIBILITY)
std::cout << "Build ViSP with c++11 compiler flag (cmake -DUSE_CPP11=ON) to make this test working" << std::endl;
#endif
return 0;
}