40#include <visp3/core/vpConfig.h>
42#if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_THREADS) \
43 && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON) && defined(VISP_HAVE_PCL_VISUALIZATION)
45#include <visp3/core/vpImage.h>
46#include <visp3/core/vpImageConvert.h>
47#include <visp3/core/vpTime.h>
48#include <visp3/gui/vpDisplayGDI.h>
49#include <visp3/gui/vpDisplayX.h>
50#include <visp3/gui/vpDisplayPCL.h>
51#include <visp3/sensor/vpRealSense2.h>
53int main(
int argc,
char *argv[])
55#ifdef ENABLE_VISP_NAMESPACE
58 bool opt_pcl_color =
false;
59 bool opt_show_infrared2 =
false;
60 bool display_helper =
false;
62 for (
int i = 1;
i < argc;
i++) {
63 if (std::string(argv[i]) ==
"--pcl-color") {
66 else if (std::string(argv[i]) ==
"--show-infrared2") {
67 opt_show_infrared2 =
true;
69 else if ((std::string(argv[i]) ==
"--help") || (std::string(argv[i]) ==
"-h")) {
70 display_helper =
true;
73 display_helper =
true;
74 std::cout <<
"\nERROR" << std::endl;
75 std::cout <<
" Wrong command line option." << std::endl;
78 std::cout <<
"\nSYNOPSIS " << std::endl
81 <<
" [--show-infrared2]"
84 std::cout <<
"\nOPTIONS " << std::endl
85 <<
" --pcl-color" << std::endl
86 <<
" Enable textured point cloud visualization." << std::endl
88 <<
" --show-infrared2" << std::endl
89 <<
" Display also the infrared2 stream." << std::endl
91 <<
" --help, -h" << std::endl
92 <<
" Display this helper message." << std::endl
101 config.enable_stream(RS2_STREAM_COLOR, width, height, RS2_FORMAT_RGBA8, fps);
102 config.enable_stream(RS2_STREAM_DEPTH, width, height, RS2_FORMAT_Z16, fps);
103 config.enable_stream(RS2_STREAM_INFRARED, 1, width, height, RS2_FORMAT_Y8, fps);
104 config.enable_stream(RS2_STREAM_INFRARED, 2, width, height, RS2_FORMAT_Y8, fps);
108 vpImage<vpRGBa> depth_color(
static_cast<unsigned int>(height),
static_cast<unsigned int>(width));
109 vpImage<uint16_t> depth_raw(
static_cast<unsigned int>(height),
static_cast<unsigned int>(width));
118 d1.
init(color, 0, 0,
"Color");
119 d2.
init(depth_color,
color.getWidth() + 80, 0,
"Depth");
120 d3.
init(infrared1, 0,
color.getHeight() + 70,
"Infrared left");
121 if (opt_show_infrared2) {
122 d4.
init(infrared2,
color.getWidth(),
color.getHeight() + 100,
"Infrared right");
126 pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud(
new pcl::PointCloud<pcl::PointXYZ>());
127 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_color(
new pcl::PointCloud<pcl::PointXYZRGB>());
130 pcl_viewer.startThread(std::ref(mutex), pointcloud_color);
133 pcl_viewer.startThread(std::ref(mutex), pointcloud);
135 std::vector<double> time_vector;
140 std::lock_guard<std::mutex> lock(mutex);
143 rs.
acquire(
reinterpret_cast<unsigned char *
>(
color.bitmap),
reinterpret_cast<unsigned char *
>(depth_raw.bitmap),
144 nullptr, pointcloud_color,
reinterpret_cast<unsigned char *
>(infrared1.bitmap),
145 opt_show_infrared2 ?
reinterpret_cast<unsigned char *
>(infrared2.bitmap) :
nullptr,
nullptr);
148 rs.
acquire(
reinterpret_cast<unsigned char *
>(
color.bitmap),
reinterpret_cast<unsigned char *
>(depth_raw.bitmap),
149 nullptr, pointcloud,
reinterpret_cast<unsigned char *
>(infrared1.bitmap),
150 opt_show_infrared2 ?
reinterpret_cast<unsigned char *
>(infrared2.bitmap) :
nullptr,
nullptr);
179 std::cout <<
"Acquisition - Mean time: " <<
vpMath::getMean(time_vector)
180 <<
" ms ; Median time: " <<
vpMath::getMedian(time_vector) <<
" ms" << std::endl;
188#if !defined(VISP_HAVE_REALSENSE2)
189 std::cout <<
"Install librealsense2 to make this test work." << std::endl;
191#if !defined(VISP_HAVE_X11) && !defined(VISP_HAVE_GDI)
192 std::cout <<
"X11 or GDI are needed." << std::endl;
194#if !defined(VISP_HAVE_PCL)
195 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)
Definition of the vpImage class member functions.
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")