Visual Servoing Platform  version 3.4.0
testRealSense2_T265_images.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Images acquisition with RealSense T265 sensor and librealsense2.
33  *
34  *****************************************************************************/
35 
42 #include <iostream>
43 
44 #include <visp3/core/vpImageConvert.h>
45 #include <visp3/gui/vpDisplayGDI.h>
46 #include <visp3/gui/vpDisplayX.h>
47 #include <visp3/sensor/vpRealSense2.h>
48 
49 #if defined(VISP_HAVE_REALSENSE2) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && \
50  (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)) && \
51  (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
52 
53 int main()
54 {
55  try {
56  double ts;
57  unsigned int display_scale = 2;
58  vpRealSense2 rs;
59  std::string product_line = rs.getProductLine();
60  std::cout << "Product line: " << product_line << std::endl;
61 
62  if (product_line != "T200") {
63  std::cout << "This example doesn't support devices that are not part of T200 product line family !" << std::endl;
64  return EXIT_SUCCESS;
65  }
66  rs2::config config;
67  config.enable_stream(RS2_STREAM_FISHEYE, 1, RS2_FORMAT_Y8);
68  config.enable_stream(RS2_STREAM_FISHEYE, 2, RS2_FORMAT_Y8);
69 
70  rs.open(config);
71 
72  // Creating left and right vpImages
73  vpImage<unsigned char> I_left((unsigned int)rs.getIntrinsics(RS2_STREAM_FISHEYE).height,
74  (unsigned int)rs.getIntrinsics(RS2_STREAM_FISHEYE).width);
75 
76  vpImage<unsigned char> I_right((unsigned int)rs.getIntrinsics(RS2_STREAM_FISHEYE).height,
77  (unsigned int)rs.getIntrinsics(RS2_STREAM_FISHEYE).width);
78 
79 #if defined(VISP_HAVE_X11)
80  vpDisplayX display_left; // Left image
81  vpDisplayX display_right; // Right image
82 #elif defined(VISP_HAVE_GDI)
83  vpDisplayGDI display_left; // Left image
84  vpDisplayGDI display_right; // Right image
85 #endif
86 
87 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI)
88  display_left.setDownScalingFactor(display_scale);
89  display_right.setDownScalingFactor(display_scale);
90  display_left.init(I_left, 10, 10, "Left image");
91  display_right.init(I_right, static_cast<int>(I_left.getWidth()/display_scale) + 80, 10, "Right image"); // Right
92 #endif
93 
94  while (true) {
95  double t = vpTime::measureTimeMs();
96 
97  // Acquire both images with timestamp
98  rs.acquire(&I_left, &I_right, &ts);
99 
100  vpDisplay::display(I_left);
101  vpDisplay::display(I_right);
102 
103  vpDisplay::displayText(I_left, 15*display_scale, 15*display_scale, "Click to quit", vpColor::red);
104  vpDisplay::displayText(I_right, 15*display_scale, 15*display_scale, "Click to quit", vpColor::red);
105 
106  if (vpDisplay::getClick(I_left, false) || vpDisplay::getClick(I_right, false)) {
107  break;
108  }
109  vpDisplay::flush(I_left);
110  vpDisplay::flush(I_right);
111 
112  std::cout << "Loop time: " << vpTime::measureTimeMs() - t << std::endl;
113  }
114 
115  } catch (const vpException &e) {
116  std::cerr << "RealSense error " << e.what() << std::endl;
117  } catch (const std::exception &e) {
118  std::cerr << e.what() << std::endl;
119  }
120 
121  return EXIT_SUCCESS;
122 }
123 #else
124 int main()
125 {
126 #if !defined(VISP_HAVE_REALSENSE2)
127  std::cout << "You do not realsense2 SDK functionality enabled..." << std::endl;
128  std::cout << "Tip:" << std::endl;
129  std::cout << "- Install librealsense2, configure again ViSP using cmake and build again this example" << std::endl;
130  return EXIT_SUCCESS;
131 #elif (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
132  std::cout << "You do not build ViSP with c++11 or higher compiler flag" << std::endl;
133  std::cout << "Tip:" << std::endl;
134  std::cout << "- Configure ViSP again using cmake -DUSE_CXX_STANDARD=11, and build again this example" << std::endl;
135 #elif !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
136  std::cout << "You don't have X11 or GDI display capabilities" << std::endl;
137 #elif !(RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
138  std::cout << "Install librealsense version > 2.31.0" << std::endl;
139 #endif
140  return EXIT_SUCCESS;
141 }
142 #endif
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
std::string getProductLine()
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
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:150
error that can be emited by ViSP classes.
Definition: vpException.h:71
static void flush(const vpImage< unsigned char > &I)
bool open(const rs2::config &cfg=rs2::config())
VISP_EXPORT double measureTimeMs()
Definition: vpTime.cpp:126
static const vpColor red
Definition: vpColor.h:217
const char * what() const
static void display(const vpImage< unsigned char > &I)
void setDownScalingFactor(unsigned int scale)
rs2_intrinsics getIntrinsics(const rs2_stream &stream, int index=-1) const
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void acquire(vpImage< unsigned char > &grey, double *ts=NULL)