Visual Servoing Platform  version 3.1.0
tutorial-grabber-realsense.cpp
1 
2 #include <visp3/core/vpImage.h>
3 #include <visp3/gui/vpDisplayGDI.h>
4 #include <visp3/gui/vpDisplayX.h>
5 #include <visp3/sensor/vpRealSense.h>
6 
10 int main()
11 {
12 #ifdef VISP_HAVE_REALSENSE
13  try {
15 
16  vpRealSense g;
17  unsigned int width = 640, height = 480;
18  g.setStreamSettings(rs::stream::color, vpRealSense::vpRsStreamParams(width, height, rs::format::rgba8, 60));
19  g.open();
20  g.acquire(I);
21 
22  std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
23 
24 #ifdef VISP_HAVE_X11
25  vpDisplayX d(I);
26 #elif defined(VISP_HAVE_GDI)
27  vpDisplayGDI d(I);
28 #else
29  std::cout << "No image viewer is available..." << std::endl;
30 #endif
31 
32  while (1) {
33  double t = vpTime::measureTimeMs();
34  g.acquire(I);
36  vpDisplay::displayText(I, 10, 10, "A click to quit", vpColor::red);
37  std::stringstream ss;
38  ss << "Acquisition time: " << vpTime::measureTimeMs() - t << " ms";
39  vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);
40 
42  if (vpDisplay::getClick(I, false))
43  break;
44  }
45  } catch (vpException &e) {
46  std::cout << "Catch an exception: " << e << std::endl;
47  }
48 #endif
49 }
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:129
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
error that can be emited by ViSP classes.
Definition: vpException.h:71
void acquire(std::vector< vpColVector > &pointcloud)
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:88
static const vpColor red
Definition: vpColor.h:180
static void display(const vpImage< unsigned char > &I)
void setStreamSettings(const rs::stream &stream, const rs::preset &preset)
unsigned int getHeight() const
Definition: vpImage.h:178
unsigned int getWidth() const
Definition: vpImage.h:229