42 #include <visp3/core/vpConfig.h>
44 #if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_THREADS) \
45 && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) && defined(VISP_HAVE_PCL_VISUALIZATION)
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpImageConvert.h>
49 #include <visp3/core/vpTime.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayX.h>
52 #include <visp3/gui/vpDisplayPCL.h>
53 #include <visp3/sensor/vpRealSense2.h>
55 int main(
int argc,
char *argv[])
57 bool opt_pcl_color =
false;
58 bool opt_show_infrared2 =
false;
59 bool display_helper =
false;
61 for (
int i = 1; i < argc; i++) {
62 if (std::string(argv[i]) ==
"--pcl-color") {
65 else if (std::string(argv[i]) ==
"--show-infrared2") {
66 opt_show_infrared2 =
true;
68 else if ((std::string(argv[i]) ==
"--help") || (std::string(argv[i]) ==
"-h")) {
69 display_helper =
true;
72 display_helper =
true;
73 std::cout <<
"\nERROR" << std::endl;
74 std::cout <<
" Wrong command line option." << std::endl;
77 std::cout <<
"\nSYNOPSIS " << std::endl
80 <<
" [--show-infrared2]"
83 std::cout <<
"\nOPTIONS " << std::endl
84 <<
" --pcl-color" << std::endl
85 <<
" Enable textured point cloud visualization." << std::endl
87 <<
" --show-infrared2" << std::endl
88 <<
" Display also the infrared2 stream." << std::endl
90 <<
" --help, -h" << std::endl
91 <<
" Display this helper message." << std::endl
97 const int width = 640, height = 480, fps = 30;
100 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
101 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, fps);
102 config.enable_stream(RS2_STREAM_INFRARED, 1, width, height, RS2_FORMAT_Y8, fps);
103 config.enable_stream(RS2_STREAM_INFRARED, 2, width, height, RS2_FORMAT_Y8, fps);
106 vpImage<vpRGBa> color(
static_cast<unsigned int>(height),
static_cast<unsigned int>(width));
107 vpImage<vpRGBa> depth_color(
static_cast<unsigned int>(height),
static_cast<unsigned int>(width));
108 vpImage<uint16_t> depth_raw(
static_cast<unsigned int>(height),
static_cast<unsigned int>(width));
117 d1.
init(color, 0, 0,
"Color");
118 d2.
init(depth_color, color.getWidth() + 80, 0,
"Depth");
119 d3.
init(infrared1, 0, color.getHeight() + 70,
"Infrared left");
120 if (opt_show_infrared2) {
121 d4.
init(infrared2, color.getWidth(), color.getHeight() + 100,
"Infrared right");
125 pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud(
new pcl::PointCloud<pcl::PointXYZ>());
126 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_color(
new pcl::PointCloud<pcl::PointXYZRGB>());
127 vpDisplayPCL pcl_viewer(color.getWidth() + 80, color.getHeight() + 70,
"3D viewer " +
vpTime::getDateTime());
129 pcl_viewer.startThread(std::ref(mutex), pointcloud_color);
132 pcl_viewer.startThread(std::ref(mutex), pointcloud);
134 std::vector<double> time_vector;
139 std::lock_guard<std::mutex> lock(mutex);
142 rs.
acquire(
reinterpret_cast<unsigned char *
>(color.bitmap),
reinterpret_cast<unsigned char *
>(depth_raw.bitmap),
143 nullptr, pointcloud_color,
reinterpret_cast<unsigned char *
>(infrared1.bitmap),
144 opt_show_infrared2 ?
reinterpret_cast<unsigned char *
>(infrared2.bitmap) :
nullptr,
nullptr);
147 rs.
acquire(
reinterpret_cast<unsigned char *
>(color.bitmap),
reinterpret_cast<unsigned char *
>(depth_raw.bitmap),
148 nullptr, pointcloud,
reinterpret_cast<unsigned char *
>(infrared1.bitmap),
149 opt_show_infrared2 ?
reinterpret_cast<unsigned char *
>(infrared2.bitmap) :
nullptr,
nullptr);
178 std::cout <<
"Acquisition - Mean time: " <<
vpMath::getMean(time_vector)
179 <<
" ms ; Median time: " <<
vpMath::getMedian(time_vector) <<
" ms" << std::endl;
187 #if !defined(VISP_HAVE_REALSENSE2)
188 std::cout <<
"Install librealsense2 to make this test work." << std::endl;
190 #if !defined(VISP_HAVE_X11) && !defined(VISP_HAVE_GDI)
191 std::cout <<
"X11 or GDI are needed." << std::endl;
193 #if !defined(VISP_HAVE_PCL)
194 std::cout <<
"Install PCL to make this test work." << std::endl;
void start(bool reset=true)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
static double getMedian(const std::vector< double > &v)
static double getMean(const std::vector< double > &v)
void acquire(vpImage< unsigned char > &grey, double *ts=nullptr)
bool open(const rs2::config &cfg=rs2::config())
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")